sch遠程拷貝自動輸入密碼expect小腳本

#!/usr/bin/expect

#Author Aladin

#date 20140504

#auto input passwd

#Version 1.0

spawn scp -P22  /root/shell_test/123.txt [email protected]:/tmp/

set timeout 100

expect "[email protected]'s password:"

set timeout 10

send "123456\r"

#expect eof

interact


#注意:服務器需要安裝expect

一、源碼包安裝要安裝expect,linux expect的安裝

1.安裝相應的包

   yum install -y tcl tclx tcl-devel

2.下載expect-5.43.tar.gz包(我這裏用的這個包,大家也可以用別的)

根據參數,運行./configure
./configure --with-tcl=/usr/lib --with-tclinclude=/usr/include/tcl-private/generic
3.make && make install  安裝完畢


二、yum 安裝

yum install -y expect


問題處理:

./auto_scpfile.sh: line 2: spawn: command not found

couldn't read file "password:": no such file or directory

./auto_scpfile.sh: line 8: send: command not found

./auto_scpfile.sh: line 10: interact: command not found

這樣的話,腳本要指定expect:  #!/usr/bin/expect

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章