LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-19-2012, 01:30 PM   #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-19-2012, 01:47 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Quote:
crontab looks like this
5,10,15,20,25,30,35,40,45,50,55,59 * * * * /home/user/test.tcl > /home/user/hstfiltest
This is neither a problem with crontab, nor with your script, but I think you've made a wrong entry in crontab. You've mentioned:
/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:
5,10,15,20,25,30,35,40,45,50,55,59 * * * * /home/user/test.tcl >> /home/user/hstfiltest

Last edited by shivaa; 10-19-2012 at 01:49 PM.
 
Old 10-19-2012, 01:50 PM   #3
mmheera
Member
 
Registered: Oct 2012
Location: Germany
Distribution: Ubuntu, Debian, Fedora,Windows 7
Posts: 107

Rep: Reputation: 11
Here are some troubleshooting tips:

http://askubuntu.com/questions/16422...-not-executing

Thanks!
 
Old 10-19-2012, 02:04 PM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
I'd like to add one more thing, instead of doing:
Quote:
5,10,15,20,25,30,35,40,45,50,55,59 * * * * /home/user/test.tcl >> /home/user/hstfiltest
You should add output file i.e. >> /home/user/hstfiltest in script itself, not in crontab! Just add ">> /home/user/hstfiltest" after the line where your command generates output in your script.
Let's say, your script will look like this:
Code:
for i in $file
do
<command> >> /home/user/hstfiltest
done
 
Old 10-19-2012, 02:34 PM   #5
vsandilya
Member
 
Registered: Jan 2008
Posts: 31

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by meninvenus View Post
This is neither a problem with crontab, nor with your script, but I think you've made a wrong entry in crontab. You've mentioned:
/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.
Hello. Thanks for replying. I did try the >> option in crontab but that did not help. It still puts nothing out to the file. But I do see the file updates every 5 minutes but nothing is in the file. But, when I run it as a command, the file gets populated.
[user@user ~]$ /home/user/test.tcl >> /home/user/hstfiltest
 
Old 10-19-2012, 04:07 PM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
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
do
<command> >> /home/user/hstfiltest
done
I tested the same with a test script and it's working, so make a try with this.
Further, it would be better if you mention what's your script is, or any illustration please...
 
Old 10-19-2012, 05:12 PM   #7
vsandilya
Member
 
Registered: Jan 2008
Posts: 31

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by meninvenus View Post
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
do
<command> >> /home/user/hstfiltest
done
I tested the same with a test script and it's working, so make a try with this.
Further, it would be better if you mention what's your script is, or any illustration please...
Here is my TCL script. Its a simple script to interact with a modem and find out the state and depending on it do something.

#!/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]}
}
 
Old 10-22-2012, 01:02 PM   #8
vsandilya
Member
 
Registered: Jan 2008
Posts: 31

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by meninvenus View Post
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
do
<command> >> /home/user/hstfiltest
done
I tested the same with a test script and it's working, so make a try with this.
Further, it would be better if you mention what's your script is, or any illustration please...
I took care of printing to the file in my script and got rid of the >> /home/user/testfile in the crontab but still doesn't work.

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...
 
Old 10-22-2012, 07:08 PM   #9
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
cron has a minimal env setting; best to explicitly (ie absolute path) call cmds, files etc.
 
  


Reply

Tags
crontab, linux


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
TCL script runs fine manually but not as a cron job vsandilya Programming 2 10-22-2012 11:13 AM
Script runs Manually but not in Cron, yet other parts of the script run mccartjd Linux - Newbie 5 01-08-2012 07:54 PM
Script runs manually but not from cron redvelo Linux - Newbie 6 09-29-2010 02:37 PM
Script not running properly in cron though runs well if run manually. linuxlover.chaitanya Linux - Newbie 4 01-15-2009 04:31 AM
Cron Job only runs when it is manually started sinister1 Linux - General 4 02-25-2008 09:35 AM


All times are GMT -5. The time now is 08:55 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration