linux 中的expect问题,在expect中放入ssh ip "[[ -d /home/bin ]] || mkdir /home/bin",报错:-d有问题 10
具体的脚本如下:#!/usr/bin/expectsettimeout10sethost[lindex$argv0]setpassword[lindex$argv1]sp...
具体的脚本如下:
#!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set password [lindex $argv 1]
spawn ssh $host "[[ -d /home/bin ]] || mkdir /home/bin"
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect eof
想实现的功能为,判断远程的服务器上是否有指定的目录,因为用到了ssh,所以需要输入密码,由于服务器数量过多,所以想expect自动去输入密码。但是执行这个脚本的时候有问题。
如果有其他解决方法的也请告诉一下,谢谢了…… 展开
#!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set password [lindex $argv 1]
spawn ssh $host "[[ -d /home/bin ]] || mkdir /home/bin"
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect eof
想实现的功能为,判断远程的服务器上是否有指定的目录,因为用到了ssh,所以需要输入密码,由于服务器数量过多,所以想expect自动去输入密码。但是执行这个脚本的时候有问题。
如果有其他解决方法的也请告诉一下,谢谢了…… 展开
1个回答
展开全部
shell的语法在expect下不好使的,把[[ -d /home/bin ]] 改成test -d /home/bin
#!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set password [lindex $argv 1]
spawn ssh $host "test -d /home/bin || mkdir /home/bin"
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect eof
#!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set password [lindex $argv 1]
spawn ssh $host "test -d /home/bin || mkdir /home/bin"
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect eof
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询