Bash + Expect脚本在cron RHEL 7中不起作用

问题描述 投票:0回答:1

我有以下脚本,该脚本在终端中运行,但在crontab中不起作用。为什么它不在cron中运行

注意:/opt/app/bin/app.exe具有CLI

#!/bin/bash
PATH=/opt/app/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/myuser/.local/bin:/home/myuser/bin:/home/myuser/scripts

ip=10.12.13.4
file=filename

function filestats(){
        /usr/bin/expect - $1 $2 << 'EOF' | awk  '/^second line/ { print $5 }'
set ip [lindex $argv 0]
set file [lindex $argv 1]

set timeout 60

spawn /opt/app/bin/app.exe 127.0.0.1 $ip 1112

expect {
        "CLI# > " { send "addip $file\r" }
}

sleep 3
expect {
        "CLI# > " { send "quit\r" }
}
EOF
}
filestats ${ip} ${file}
bash cron expect rhel7
1个回答
0
投票

EOF并没有真正退出循环。我将其固定在EOF上方的expect eof,从而解决了该问题。我仅在RHEL 7中注意到了此问题,而在RHEL 6中则没有注意到]

© www.soinside.com 2019 - 2024. All rights reserved.