- 论坛徽章:
- 1
|
本帖最后由 registcn 于 2013-11-27 00:06 编辑
#!/bin/bash
myexp="/home/work/usr/bin/expect"
myssh="ssh -o StrictHostKeyChecking=no -o ConnectionAttempts=2 -o ConnectTimeout=2 -nq -lroot"
$myexp<<eof22
spawn $myssh yourdomain "cd /etc/ && awk '\$1~/127.0.0.1/ {print \$1,\$2,$mac}' hosts >hosts.bak && cp hosts.bak hosts
hostname $mac"
expect {
"(yes/no)?" {send "yes\r";exp_continue;}
".*assword:" {send "yourrootpassword\r";exp_continue;}
"Permission denied" {exit 1}
"No such file or directory" {exit 2}
"Name or service not known" {exit 3}
}
eof22
注释:
yourdoamin和yourpassword请根据自己情况填写
问题貌似出在awk那里(可能特殊符号处理不对?如果去掉awk,脚本的整体框架没问题),怎么处理特殊符号呢?
下面是报错:
can't read "1": no such variable
while executing
"spawn ssh -o StrictHostKeyChecking=no -o ConnectionAttempts=2 -o ConnectTimeout=2 -nq -lroot yourdomain "cd /etc/ && awk \'$1~/127.0.0.1/ {pr..." |
|