简体   繁体   English

Bash Expect 脚本,发送命令

[英]Bash Expect script, send command

I have the following script working.我有以下脚本工作。 I would like the result of command send -- "/system identity print\\r" executed saved to a file, but it is probably badly written.我希望将命令send -- "/system identity print\\r"的结果send -- "/system identity print\\r"执行保存到文件中,但它可能写得不好。 At the moment, I can only write the path to the file tmp.目前,我只能写入文件 tmp.conf 的路径。

#!/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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM