LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2012, 11:29 AM   #1
vsandilya
Member
 
Registered: Jan 2008
Posts: 31

Rep: Reputation: 1
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
 
Old 10-20-2012, 04:12 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 10-22-2012, 10:13 AM   #3
vsandilya
Member
 
Registered: Jan 2008
Posts: 31

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by druuna View Post
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..
 
  


Reply

Tags
crontab, linux, tcl



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script runs Manually but not in Cron, yet other parts of the script run mccartjd Linux - Newbie 5 01-08-2012 06:54 PM
Script runs manually but not from cron redvelo Linux - Newbie 6 09-29-2010 01:37 PM
Script not running properly in cron though runs well if run manually. linuxlover.chaitanya Linux - Newbie 4 01-15-2009 03:31 AM
Cron Job only runs when it is manually started sinister1 Linux - General 4 02-25-2008 08:35 AM
Script works when run manually but not in cron job Harlin Linux - Software 7 10-16-2007 06:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration