Expect script not executing via cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect script not executing via cron
# 1  
Old 07-19-2016
Expect script not executing via cron

Hello All,

I'm having an issue getting an expect script to run as a cron job. The script executes fin if I run it from the command line but I get nothing when trying to run it as a cron job. I've researched other forums and threads and there have been references to the environment, or lack thereof through cron, but I still haven't been able to resolve. The script is as follows:


------------------------------------------------------------------------
Script:
Code:
#!/usr/bin/expect -f
 #export PATH=/usr/bin:TH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
spawn "/home/scripts/myscript.sh"
 expect "Select Operation" { send "1\r" }
 expect "Select TMS6 Snapshot Type" { send "1\r" }
 set timeout 600
expect eof
exit

-----------------------------------------------------------------------
cron job:
Code:
41 13 * * * root /home/user/expect.sh

---------------------------------------------------------------------
output from cron log:
Code:
Jul 19 13:40:06 localhost crond[4862]: (CRON) STARTUP (V5.0)
Jul 19 13:41:01 localhost crond[4997]: (root) CMD (/home/user/expect.sh)

----------------------------------------------------------------------

The expect script will pass 2 arguments into myscript.sh, which then creates an output file. When I run this on the command line, no problems, but through cron.....no results. Thanks for the help in advance!




Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!


---------- Post updated at 03:28 PM ---------- Previous update was at 03:11 PM ----------

my apologies.....I'm a newb to forum posting.

Last edited by RudiC; 07-19-2016 at 05:15 PM.. Reason: Addd code tags.
# 2  
Old 07-19-2016
You need to remove the # from in front of the export to actually change your PATH. As is, cron will be running it with a very minimal path.
# 3  
Old 07-20-2016
Thanks for the reply Corona688. I must've pasted an older version of the script. Either way, I removed the # but the script continues to give no output or result. Just the same cron log entry showing the job getting kicked off and nothing else. Here's an updated version of what the script looks like:

Code:
#!/usr/bin/expect -f
export PATH=/usr/bin:TH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 spawn "/home/scripts/myscript.sh"
 expect "Select Operation" { send "1\r" }
 expect "Select TMS6 Snapshot Type" { send "1\r" }
 set timeout 600
expect eof
exit

# 4  
Old 07-20-2016
Ah, I think I see. 'export' is a shell command, not an expect one.

I think for expect/TCL it's something like

setenv PATH "/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin"

The TH= does not belong in PATH and I'm not sure what it was intended to do. Neither should PATH entries be repeated like that.
# 5  
Old 07-20-2016
I picked up that line with the TH in the path from another thread in a futile attempt to resolve this. With your suggested changes the script still doesn't run via cron and now it no longer runs on the command line and produces the following output:
Code:
 invalid command name "env"
    while executing
"env PATH "/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin""
    (file "./expect.sh" line 2)

I've looked at a few other forums and tried using a variant of env PATH "/usr/bin......." but end up with the same result of nothing. Damn you cron and your lack of environment
# 6  
Old 07-20-2016
I don't think its a PATH or environment problem, as no command is run or called inside the expect script, and expect is run with full path.

I'm a bit baffled. The form of your crontab entry indicates it is from the system crontab file, the only one that requires a user to be run as. Please confirm that it comes from there (most probably /etc/crontab) and is not used as a user crontab. Although the syslog line shows it is really starting...

Can you try to write a verbose log file and post that here?
# 7  
Old 07-20-2016
Rudi, I tested your theory and I believe you are correct with the path/environment. I ran the following:

command line:
Code:
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/sbin:

via cron:
Code:
PATH=/usr/bin:/bin

output from which expect:
Code:
/usr/bin/expect

Based on this I'd say that it's not a path or environment issue, which led me to your 2nd problem area....the cron entry file. I've tried running it from both the /etc/crontab, crontab -e (as local user and root) but it seems the job never runs despite the log posting it starts.

I'm not quite sure on how to produce a verbose log file...I'll be searching for that process now.

Last edited by KingT617; 07-20-2016 at 04:35 PM.. Reason: add text
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Script is not executing as expected when I schedule it in cron

Hi, I have a shell script which fetches the MRP status and the LAG status. When I execute it manually like, sh <script_name>, it fetches the output as expected, but when I schedule through crontab, it's not working as expected. Any help would be really appreciated. Here is the code... (3 Replies)
Discussion started by: Nagaraj R
3 Replies

2. Shell Programming and Scripting

Expect Script not running from cron. Full Paths used

My cron file. Copied $PATH # Minute Hour Day of Month Month Day of Week Command SHELL=/bin/ksh PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/perl/lib:/perl/lib/lib/perl5:/perl/scripts:.:/perl/lib/local:/home/popeye:/temp 0... (3 Replies)
Discussion started by: popeye
3 Replies

3. Shell Programming and Scripting

Script not executing using cron

Hi, I created a script which connects to database and update a table. This script is running fine when i run it manually but when i am trying to execute it scheduling in crontab.script is executing but Data is not getting updated. below is my script sqlplus test/##### >> test_feed.log <<!... (6 Replies)
Discussion started by: sv0081493
6 Replies

4. UNIX for Dummies Questions & Answers

Cron shell script not executing diskutil command

I'm trying to learn how to use cron for repetative tasks. I have an external disk that needs to be unmounted and remounted every hour due to some problems that a backup utility (specifically, TimeMachine) is having repeatedly accessing the device. I've created a shell script that will find the... (3 Replies)
Discussion started by: illuminate
3 Replies

5. Shell Programming and Scripting

Executing a script from CRON behaves differently than terminal

Hi have a script which transferers from Microsoft server to Linux box. The scripts(ksh) is on Linux box. If I run script from terminal, it transfers files to directory. Where as If I run script from CRON. It does not. Here is the log of both: Terminal execution log:... (2 Replies)
Discussion started by: dipeshvshah
2 Replies

6. Shell Programming and Scripting

Problem with executing a shell script through the cron

Hi, I have a shell script as below: ORACLE_HOME=/usr/local/opt/oracle/product/dev export ORACLE_HOME PATH=$PATH:$ORACLE_HOME/bin:/usr/bin export PATH OUTFILE=/export/home/`basename $0`.out export OUTFILE export IDEN df -k . | tail -1 | read a b c d e f echo $a >> $OUTFILE echo $b... (4 Replies)
Discussion started by: Abhinav Pandey
4 Replies

7. Shell Programming and Scripting

Executing expect script giving message as bad interpreter: Permission denied

Hi Gurus, I am new to scripting and needs your help in expect script used for telnet. I wrote a simple script as #!/usr/bin/expect-5.43 -f spawn telnet localhost 2233 expect "password:" send "secret\r" send "i data.cnbc.com\r" send "exit\r" expect eof When I am trying to execute... (2 Replies)
Discussion started by: niks_yv
2 Replies

8. Shell Programming and Scripting

Using expect script with AIX's SMIT in cron

My searches turned up nothing relevant, so I apologize if this has already been looked at. I am trying to run an expect script from a Solaris machine, that ssh's into an AIX machine, and interacts with a SMIT created menu system that runs a few backups for me. The expect script runs fine when... (0 Replies)
Discussion started by: Mariognarly
0 Replies

9. HP-UX

executing shell script from the cron

This isn't the usual problem that a shell script runs from the command line and not the cron. It's a little different. Among other things, the shell scrip executes my .profile to set a bunch of variables. It then does an env to ensure that it ran OK. There are echos in the shell script and... (2 Replies)
Discussion started by: abNORMal
2 Replies

10. Shell Programming and Scripting

expect script in cron

I wrote a script using 'expect' tool to change the password of my login id, every fortnight. And I had put it as a cron job. The cron job is throwing an error ld.so.1: /usr/local/bin/expect: fatal: libtcl8.3.so: open failed: No such file or directory The environment variables are set... (4 Replies)
Discussion started by: Deepa
4 Replies
Login or Register to Ask a Question