TCL script runs fine manually but not as a cron job
Hello
I have a simple TCL script that runs fine manually from the command line but if I schedule it as a cron job it produces only half the output of the script. I can't seem to get why. The script is in my home directory /home/user/test.tcl crontab looks like this 5,10,15,20,25,30,35,40,45,50,55,59 * * * * /home/user/test.tcl > /home/user/hstfiltest I see the hstfiltest file that updates every 5 mins but not with the complete output The script starts like this #!/usr/bin/tclsh package require expect { whole bunch of tcl code} Any help is appreciated. Thanks |
Quote:
/home/user/test.tcl > /home/user/hstfiltest, which is wrong. Your test.tcl script will update the /home/user/hstfiltest all the time and finally it will show you only last executed part of script in the /home/user/hstfiltest. Solution: Use a >> (double >) between /home/user/test.tcl and /home/user/hstfiltest, so if your script is generating some data, it will keep appending that data in /home/user/hstfiltest until it succesfully gets finish. Quote:
|
|
I'd like to add one more thing, instead of doing:
Quote:
Let's say, your script will look like this: Code:
for i in $file |
Quote:
[user@user ~]$ /home/user/test.tcl >> /home/user/hstfiltest |
As I said in my last reply, add the line ">> /home/user/hstfiltest" in script itself, not in cron, somewhat like this:
Code:
for i in $file Further, it would be better if you mention what's your script is, or any illustration please... |
Quote:
#!/usr/bin/tclsh package require Expect set modem "192.168.13.31" set timeout 30 log_user 0 proc state {arg} { if {$arg == 1} { puts "Modem will reboot" set systemTime [clock seconds] puts [clock format $systemTime -format {%Y,%m,%d %H:%M:%S}] send "atz\r" expect "\nOK" exit #send "^]\r" #expect "\ntelnet>" #send "q\r" } if {$arg == 0} { puts "Modem is ready" exit } } spawn telnet $modem 2332 expect "\nPassword: " send "12345\r" expect "\nOK" send "at*netstate?\r" interact { -o -re "\n.*Ready.*" {[state 1]} "\n.*Dormant.*" {[state 0]} } |
Quote:
I don't understand.. Is crontab not recognizing the expect package? If I write a simple TCL script that prints a message to a file, that works but not this... |
cron has a minimal env setting; best to explicitly (ie absolute path) call cmds, files etc.
|
All times are GMT -5. The time now is 04:32 AM. |