我有以下脚本:if语句,不工作
#!/bin/bash
pw=$1
pw2=$2
file=$3
user="admin"
if [ $# -eq 0 ]
then
echo "bitte PW und IP-file als Parameter angeben"
fi
for ip in `cat $file`;
do
ping -c1 $ip >/dev/null 2>&1
if [ $? -eq 0 ];
then
echo $ip
/usr/bin/expect <<EOD
spawn /usr/bin/telnet $ip
if { expect "Please Enter Password:" } {
send $pw\r }
} elseif{ expect "Please Enter Login Name:" } {
send $user\r
send $pw\r }
expect [email protected]*
send ena\r
expect "Password:"
send $pw2\r
expect "[email protected]*"
send skip-page-display\r
expect [email protected]*
send "show running-config\r"
log_file "$ip.conf"
expect "[email protected]*"
send "exit\r"
expect "[email protected]*"
send "exit\rn"
EOD
else
echo "$i nicht erreicht"
fi
done
,但它没有工作,我得到了以下错误:
spawn /usr/bin/telnet IP
invalid bareword "expect"
in expression " expect "Please Enter Passwor...";
should be "$expect" or "{expect}" or "expect(...)" or ...
(parsing expression " expect "Please Enter ...")
invoked from within
"if { expect "Please Enter Password:" } {
send top_SECRET\r }"
任何想法如何,我得到这个上班? 某些交换机需要用户名,其他一些交换机不需要,所以我需要一个If-Statement来检查预期的结果。 在此先感谢您的帮助!
感谢这个信息,但我怎样才能解决呢? – colttt