shell之except
发布时间:2020-12-15 16:51:16 所属栏目:安全 来源:网络整理
导读:在使用shell脚本时候,总会遇到交互性的命令,会提示输入密码,用户名之类的。这时候就需要使用except了。 例如: #!/usr/bin/expect -f set username [lindex $argv 0 ] set hostname [lindex $argv 1 ] set upload_name [lindex $argv 2 ] set dst_dir [li
在使用shell脚本时候,总会遇到交互性的命令,会提示输入密码,用户名之类的。这时候就需要使用except了。 例如: #!/usr/bin/expect -f
set username [lindex $argv 0]
set hostname [lindex $argv 1]
set upload_name [lindex $argv 2]
set dst_dir [lindex $argv 3]
set password [lindex $argv 4]
spawn scp -r $upload_name $username@$hostname:$dst_dir
set timeout 3
expect { "yes/no"
{send "yesr";exp_continue}
}
expect "$username@$hostname's password:"
set timeout 3
send "$passwordr"
set timeout 300
send "exitr"
expect eof
这里通过 set password [lindex $argv num]
从脚本外部传入参数,这里需要与传统的shell脚本做一个区别。 然后通过spawn、expect、send完成对交互式命令scp的操作。其他的ftp、tftp等等也可以仿照这个来写。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |