LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   TCL script runs fine manually but not as a cron job (https://www.linuxquestions.org/questions/programming-9/tcl-script-runs-fine-manually-but-not-as-a-cron-job-4175433080/)

vsandilya 10-19-2012 11:29 AM

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

druuna 10-20-2012 04:12 AM

I don't have any experience with TCL but most of the problems when running a script from cron have to do with environment settings.

When running a script from the command line it has access to a fully set environment and parts of the script might make use of those settings. When running that script from cron, the environment that is set is minimal and thus the script might not work.

Make sure that all that is needed is set/present in the script.

If you are unsure, post the TCL script. I'm sure there are some people on this board that can help you with specifics.

vsandilya 10-22-2012 10:13 AM

Quote:

Originally Posted by druuna (Post 4810551)
I don't have any experience with TCL but most of the problems when running a script from cron have to do with environment settings.

When running a script from the command line it has access to a fully set environment and parts of the script might make use of those settings. When running that script from cron, the environment that is set is minimal and thus the script might not work.

Make sure that all that is needed is set/present in the script.

If you are unsure, post the TCL script. I'm sure there are some people on this board that can help you with specifics.

The TCL code is real simple. Here it is.

1 #!/usr/bin/tclsh
2 package require Expect
3 set modem "192.168.13.31"
4 set timeout 30
5 log_user 0
6 proc state {arg} {
7 if {$arg == 1} {
8 puts "Modem will reboot"
9 set systemTime [clock seconds]
10 puts [clock format $systemTime -format {%Y,%m,%d %H:%M:%S}]
11 send "atz\r"
12 expect "\nOK"
13 exit
14 #send "^]\r"
15 #expect "\ntelnet>"
16 #send "q\r"
17 }
18 if {$arg == 0} {
19 puts "Modem is ready"
20 exit
21 }
22 }
23 spawn telnet $modem 2332
24 expect "\nPassword: "
25 send "12345\r"
26 expect "\nOK"
27 send "at*netstate?\r"
28 interact {
29 -o -re
30 "\n.*Ready.*" {[state 1]}
31 "\n.*Dormant.*" {[state 0]}
32 }
It spawns a telnet to a modem and uses expect to find out the state and depending on the state, reboots the modem. Why would this not work with a crontab but works when run from the command prompt? really frustrating..


All times are GMT -5. The time now is 12:56 AM.