0

I have the below script which is working in the terminal but not in crontab.Why it is not running in cron

Note:/opt/app/bin/app.exe is having a 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}
Raju John
  • 23
  • 3
  • Show the crontab entry. – glenn jackman May 21 '20 at 16:56
  • Are there any environment variables that the app requires, that you have set in your environment, that need to be added to this script? – glenn jackman May 21 '20 at 16:58
  • */3 * * * * /home/myuser/scripts/script.sh 2> /tmp/crontab_script_log 2>&1 – Raju John May 22 '20 at 06:10
  • I have also tried to give crontab as shown below as well, but issue was not solved */3 * * * * /bin/bash /home/myuser/scripts/script.sh 2> /tmp/crontab_script_log 2>&1 – Raju John May 22 '20 at 06:13
  • I don't see anything obviously wrong. Have a careful read of [the cron tag info page](https://stackoverflow.com/tags/cron/info) which has a lot of troubleshooting advice. – glenn jackman May 22 '20 at 11:47

1 Answers1

0

EOF was not really exiting the loop. I made it to expect eof just above the EOF which fixed the issue. I have noticed this issue only in RHEL 7, not in RHEL 6

Raju John
  • 23
  • 3