expect scripts and cron
I have an expect script that executes fine in my (roots) home directory, but not from anywhere else. I would like to create a cron job to execute the script but I don't know how to include the enviroment variable and path statements necessary for the script to run in a cron job. Anyone have any ideas?
TIA. |
Make a wrapper script that contains those PATH and other environment variable definitions and then calls the expect. Then call this wrapper from your crontab.
|
great can you give me an example of the wrapper script?
|
Something like
Code:
#!/bin/bash |
k, appreciate the help, howerver it still doesn't work. I looked at my .bash_profile and got the infor for the path and bash_env.
Here is my wrapper script: #!/bin/bash export PATH=/usr/local/sbin:/usr/local/bin: etc... export BASH_ENV=/root/.bashrc cd /root expect blah-blah When cron runs ps will show /bin/bash process followed by another for the expect script. What am I doing wrong. I will pay to have this work properly! |
The process you should see is the bash process with the child process for the expect, so that part presumably works as expected.
If i understand you correctly, the problem is, that the command run in the cron won't get executed as it should. While you speak in general terms without concrete example of what you are trying to do and what in that fails, I can only give a few ideas of what might have gone wrong.
About the environment variables and other initialization in the startup scripts:
|
Forgot to mention that also /etc/profile and/or /etc/bash.bashrc are executed when run as an interactive user but not when run from cron.
|
That could be a large part of the problem couldn't it. The wrapper shell never gets to execute the expect script when it run under cron. I know this because all the expect script does it ftp files to a web server, and the files aren't copied when cron is used to execute the wrapper script.
|
Hi,
Im also facing the same problem of Expect script not running in crontab............... My script looks like #! /usr/bin/expect -f set d [timestamp -format %H%d%m] log_file -a sysusage_$d.txt set prompt "APPL> " global argc if { $argc !=0 } { send_user "Invalid number of args" send_user "Usage: $argv0" exit -1 } set server_ip x.x.x.x set app_name xyz set timeout 5 proc do_attempt { app_name server_ip } { global prompt set timeout 5 log_user 0 spawn application -i $server_ip expect "login: " { send "login\r" } expect "password: " { send "password\r" } expect "APPL> " { send "$app_name:;\r" } expect { -re "More..." { send "\r"; exp_continue; } expect "APPL> " { send "exit\r" } } } do_attempt $app_name $server_ip; exit I think within the script since im changing the prompt to "APPL>" from "$" , I need to change the environmental variable. However, plz help me how can i do this using EXPECT . Thanks, Ruchita |
All times are GMT -5. The time now is 06:56 AM. |