ºìÁªLinuxÃÅ»§
Linux°ïÖú

ExpectµÄÓ¦ÓÃ---ÐÞ¸ÄLinuxÓû§¿ÚÁî

·¢²¼Ê±¼ä:2008-10-11 10:40:24À´Ô´:ºìÁª×÷Õß:mxjqcg
ExpectÒ»¸ö¿ØÖƽ»»¥Ê½³ÌÐòµÄ¹¤¾ß£¬±»Éè¼Æ³ÉרÃÅÕëºÍ½»»¥Ê½³ÌÐòµÄ½»»¥¡£ÄÜÃÖ²¹linuxÖÐsh,cshºÍ±ðµÄһЩshellÌṩµÄÓû§½Ó¿ÚµÄ¾ÖÏÞÐÔ¡£

Expect³ÌÐòÔ±¿ÉÒÔд½Å±¾À´ÃèÊö³ÌÐòºÍÓû§µÄ¶Ô»°£¬½Ó×ÅExpect³ÌÐò¿ÉÒԷǽ»»¥µÄÔËÐС°½»»¥Ê½¡±µÄ³ÌÐò¡£Expect»¹¿ÉÒÔÓÃÓÚ¶Ô¶Ô»°µÄÒ»²¿·Ö½øÐÐ×Ô¶¯»¯£¬ÒòΪ³ÌÐòµÄ¿ØÖÆ¿ÉÒÔÔÚ¼üÅ̺ͽű¾Ö®¼ä½øÐÐÇл»¡£[code]#!/usr/bin/expect

if { $argc<1 } {
send_user "usage: $argv0 U_Name PassWD\n"
exit 1
}
set UN [lindex $argv 0]
set PW [lindex $argv 1]

spawn -noecho /usr/bin/passwd $UN
expect {
"password" {send "$PW\n"}
}
expect {
"password" {send "$PW\n"}
}
expect {
"password" {send "$PW\n"}
}
expect eof
exit 0[/code]Telnet£¬crypt£¬su£¬rlogin£¬ºÍÉÏÀýÖеÄpasswd³ÌÐò½ÔÎÞ·¨ÔÚshell½Å±¾ÀïÃæ×Ô¶¯Ö´ÐУ¬³ý´ËÒÔÍâºÜ¶à³ÌÐòÉè¼ÆÒ²ÊÇÒªÇóÓû§ÊäÈë¡£

ËùÒÔLinuxѧϰÖÐEpectµÄ±Ø½«µÃµ½¹ã·ºÓ¦Óã¡
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ