#!/usr/bin/expect -f# Password change shell script, tested on Linux and FreeBSD# ----------------------------------# It need expect tool. If you are using Linux use following command# to install expect# apt-get install expect# FreeBSD user can use ports or following command:# pkg_add -r -v expect# ----------------------------------# If you are using linux change first line# From:#!/usr/local/bin/expect -f# To:#!/usr/bin/expect -f# -------------------------------------------------------------------------# display usage# script must be run by root userset whoami [exec id -u]if {$whoami!=0} {send_user "You must be a root user to run this script\n"exit}#set timeout -1match_max 100000# stopre passwordset password [lindex $argv 1]# usernameset user [lindex $argv 0]# opem shellspawn $env(SHELL)# send passwd commandsend -- "passwd root\r"expect "assword:"send "rahasia\r" ------> Misal : "rahasia" adalah password baru andaexpect "assword:"send "rahasia\r" ------> Untuk pengulangan input karakter/ retype passwordsend "\r"expect eof
Yakz...pada initinya kita ingin merubah password root dengan program. Program ini berguna bila di suatu sistem ada banyak admin yang ingin merubah password root sesuai kehendaknya, tapi ketika dijalankan script ini, password root akan berubah kembali ke asal.
NB : Bila program expect belum ada, install dahulu. Kalau menggunakan Yum bisa ketikkan #yum install expect.
Lumayan, ilmu baru....
0 comments:
Post a Comment