1

我有以下脚本工作。我希望将send -- "/system identity print\r"执行命令的结果保存到文件中,但它可能写得不好。目前,我只能将路径写入文件 tmp.

#!/bin/bash
HOSTNAME="xx.xx.xx.xx"
PORT="22422"
USER="admin"
PASS="pass"
TMP=$(mktemp)
PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin"

# Create Expect script
cat > $TMP << EOF
#exp_internal 1 # Uncomment for debug
set timeout -1
spawn ssh -p$PORT $USER@$HOSTNAME
match_max 100000
expect -exact "password:"
send -- "$PASS\r"
expect " > "
$nazwa send -- "/system identity print\r"
expect " > "
send -- "quit\r"
expect eof
EOF

# Run Expect script
#cat $TMP # Uncomment for debug
expect -f $TMP
echo $TMP >> log.log
# remove expect script
rm $TMP
4

1 回答 1

-1

由于您实际上是在开发您的脚本,请取消注释exp_internal 1以获取 Expect 来帮助您。

于 2013-01-23T14:26:41.523 回答