Expect Script not getting called in the Cron Job
Hi All,
I have written a script that telnets 100 servers and gets a command output. I have written an "Expect" Script that does the telent functioning. Shell script calls the expect script to telnet each server The script runs with No issues when executed manually. But, when I run the script via Cron, the expect script is not getting called. Like this I am calling the Script /opt/sfw/bin/expect telExpect.exp $server $Username $Password While googling I found someone saying mention the SHELL variable so that the expect script should determine the shell where it should run. So I changed the script like this SHELL=/opt/sfw/bin/expect telExpect.exp $server $Username $Password But, the expect script is still not getting called while running from the CRON. Please please help me on this. Regards, Athreya |
Is that the entire script in cron?
Where are $server, $Username, $Password getting set? In any case, the default env in cron is minimal, so ALWAYS specify the complete (absolute) path to ALL cmds and files. Something like /opt/sfw/bin/expect /path/to/script/telExpect.exp $server $Username $Password |
Hi Chrism01 ,
Thanks for the quick reply. The variables are in the Shell Script I call them in the expect Script like this #!/usr/bin/expect -f set timeout -1 spawn $env(SHELL) match_max 100000 expect "#" send -- "telnet [lrange $argv 0 0]\r" expect "login:" send -- "[lrange $argv 1 1]\r" expect "*:" send -- "[lrange $argv 2 2]\r" expect "*]$ " send -- "history\r" expect "*]$ " send -- "exit" And the shell script has complete path of everything, #!/bin/bash # Setiing the Date Varibale DATE=`date +%d-%m-%Y` #Make the Result File Null > /export/home/admin/result.txt rm /export/home/admin/op* > /export/home/admin/up > /export/home/admin/down # Reading every line in the servers.conf file cat /home/servers.conf | while read line do server=`echo $line | cut -d ':' -f1` # Server name variable echo "The Server Name" >> result.txt echo $server >> /export/home/admin/result.txt # Echo the server name to the result filer echo "-------------------------" >> result.txt Username=`echo $line | cut -d ':' -f2` # User name Password=`echo $line | cut -d ':' -f3` # Password for the user ping -c 1 $server &> /dev/null # Ping the server to check the availability if [ "$?" -eq 1 ];then # Check the availability of the Server echo "$server was not pinging!!Please check" >> /export/home/admin/PingFail.txt if [ "$?" -eq 2 ]; then echo " " >> /export/home/admin/WrongIPFormat.txt else /opt/sfw/bin/expect /home/admin/telExpect.exp $server $Username $Password # Expect Script Called fi fi done >> /export/home/admin/result.txt #This section We are filering the servers which have Down links awk '/The server Name/ {n++} {print > f n}' f=/export/home/admin/op /export/home/admin/result.txt; for i in `ls -lrt /export/home/admin/ | awk '{print $9}' | grep op`; do grep down $i if [ $? -eq 0 ] then echo $i >> /export/home/admin/down else echo $i >> /export/home/admin/up fi done; cat /export/home/admin/down | while read line do cat $line >> /export/home/admin/result$DATE.txt done rm /export/home/admin/op* Regards, Athreya |
Hi Chrism01 ,
I solved the issue. It took me lot of googling around. Only 2 things I should have mentioned in the Shell Script. The user id from which I am running the script his shell was set to csh. I set the same in the script export SHELL=/bin/csh export TERM=vt100 This did the trick for me. Please consider this Case as CLOSED. Thanks for the help. |
All times are GMT -5. The time now is 07:30 AM. |