scp.sh
#!/usr/bin/expect -f set port 1234 set user "me" set host "192.168.1.2" set password "whatismypassword" set timeout - 1 set file [ lindex $argv 0] set hostFilePath "/home/me/" spawn scp -P$port $file $user@$host:$hostFilePath expect "*assword:*" send "$password " expect eof
每次敲scp命令,蛋疼的用户名,蛋疼的超复杂的密码,蛋疼的长长的路径。写成这样,自动执行,超爽
./scp.sh text.txt
就把test.txt传到远程的机器
expect,传参的话,用[lindex $argv 0],这里的0表示text.txt。刚开始还以为是1,所以一直取不到
spawn是expect的内建命令,需要chmod 755 scp.sh