35:xmgEXfinder.sh:语法错误:文件结束意外(期待“完成”)
这是我目前的代码:
#!/bin/bash
IP=$(sudo arp-scan --localnet --numeric --ignoredups --quiet | grep -i ac:3f:a4 | awk '{print$1}')
Dumpdir='/home/location/logs/'
for x in $IP
do
/usr/bin/expect<<EOF
spawn ssh -i /home/location/id_rsa root@172.17.26.$x
expect "Enter passphrase for key 'id_rsa':"
send "password\n"
sleep 3
log_file XMGcheck.log
expect "~"
send "cat /reg/nv/system/serial|sed \x22s/\x24/,/g\x22 ; tail -n 50 /usr/log/ams.log|grep -i xmg|wc -l \n"
expect eof
EOF
done
答案 0 :(得分:0)
使用here here(<<EOF
)时,匹配的字符串必须从一行的开头开始。你有:
for x in $IP
do
/usr/bin/expect<<EOF
spawn ssh -i /home/location/id_rsa root@172.17.26.$x
expect "Enter passphrase for key 'id_rsa':"
send "password\n"
sleep 3
log_file XMGcheck.log
expect "~"
send "cat /reg/nv/system/serial|sed \x22s/\x24/,/g\x22 ; tail -n 50 /usr/log/ams.log|grep -i xmg|wc -l \n"
expect eof
EOF
完成
你需要:
for x in $IP
do
/usr/bin/expect<<EOF
spawn ssh -i /home/location/id_rsa root@172.17.26.$x
expect "Enter passphrase for key 'id_rsa':"
send "password\n"
sleep 3
log_file XMGcheck.log
expect "~"
send "cat /reg/nv/system/serial|sed \x22s/\x24/,/g\x22 ; tail -n 50 /usr/log/ams.log|grep -i xmg|wc -l \n"
expect eof
EOF
done
或者您需要使用<<-EOF
格式,然后使用制表符代替空格进行识别。
您可以在bash
man page的Here Documents
部分阅读更多内容。