LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-18-2009, 12:27 AM   #1
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Rep: Reputation: 0
Thumbs up Doubt with crontab.


Hi All,

I am into this trouble. I have a simple script, say:
/root# cat test1.sh
x= `tail -100 abc.sh| cut -d '|' 2`
echo x = $x >> testlog1
/root#

When I manually run this script, it gives correct output with value of x in testlog1.

/root# cat testlog1
x = 1234
/root#

But when I run this by making entry in crontab, it doesn't give the value :

/root# cat testlog1
x =
/root#

All settings are correct according to me but then why this anamoly, I cannot understand. Somebody please help.

Thanks in advance.
Sumit Dev Bharadwaj

Last edited by sumitdevbharadwaj; 04-18-2009 at 01:15 AM.
 
Old 04-18-2009, 12:57 AM   #2
dchmelik
Senior Member
 
Registered: Nov 2008
Location: USA
Distribution: Slackware, FreeBSD, Illumos, NetBSD, DragonflyBSD, Plan9, Inferno, OpenBSD, FreeDOS, HURD
Posts: 1,063

Rep: Reputation: 146Reputation: 146
I like shells and scripting, but I am unsure I can give you an exact answer. A guess is you have to output from your script in a different way. Actually I made a timekeeping/alarm script that I had problems with output. I solved it by redirecting its output in the crontab differently. Look up the 'system file numbers' that you direct script output to. I suppose you want to direct it to 'standard output' or 'standard error.' If you do that the rest of your output may just show up. I have forgotten the way to redirect some output, but you use some punctuation such as '>' or '&' and then the number (representing system files such as 'standard error') is probably at the end.

Another thing I suspect is maybe cron does not work well with some of the syntax in your script. That is unlikely though. I think it is a combination of the shell and cron (since programs in your script are maybe running in the background) that has a problem doing all the output. If I did not at least indicate a few things to try, hopefully someone with much more scripting and cron experience can enlighten us.

Last edited by dchmelik; 04-18-2009 at 12:59 AM.
 
Old 04-18-2009, 02:59 AM   #3
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Try to give the whole path to the commands and files
ie
Code:
/usr/bin/tail
/usr/bin/cut
....
 
Old 04-28-2009, 07:30 AM   #4
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Greetings!!!

Hey repo, your suggestion was great and even I thought it should work, but when I tried, it didn't wok too :-( .
dchmelik is correct I think. Crontab is not able to recognise some of the commands in any script.
But then I have some other scripts scheduled in crontab, which contain such commands and work well.
I'll be running in a big problem if this doesn't get solved.
Can anybody please help me? Thank you.


Sumit Dev Bharadwaj

Last edited by sumitdevbharadwaj; 04-28-2009 at 07:32 AM.
 
Old 04-28-2009, 07:41 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
x=`tail -100 abc.sh| cut -d '|' 2`
echo x = $x >> testlog1
the script as written in your post above does not work, because of a syntax error. If you want to extract the second field using cut, you have to put the -f option:
Code:
x=$(tail -100 abc.sh | cut -d'|' -f2)
The script has correctly redirected the standard output to teslog1, but the standard error coming from the first line of code should have been sent to the mail of the crontab's owner. Check it using the mail command and you will find the error message.
 
Old 04-28-2009, 09:07 AM   #6
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Pardon me guys, that was my typo here. In actual script it is with -f option, as it gives correct outpout when run manually.
My problem is with crontab. There is some anomaly I am not getting to. Please post your answers as well.
 
Old 04-28-2009, 10:53 AM   #7
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
what are he error message cron gives you ?
 
Old 04-28-2009, 03:25 PM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Have you checked the mail as suggested above? Any mail with standard error from the cron job?
 
Old 04-29-2009, 03:05 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
With cron you have to ensure that you use the complete path for all cmds/files. This includes full path to abc.sh....
Also, ensure there is no space either side of the '=' in the assignment
x=`tail -100 abc.sh| cut -d '|' -f2`
Your version appears to have one after the '='.

Last edited by chrism01; 04-29-2009 at 03:06 AM.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
replaced crontab, now should get crontab back to what it was raminn Linux - Newbie 2 10-20-2008 07:15 PM
man crontab(5) vs crontab(1) Canis Polaris Linux - Newbie 2 06-04-2008 04:03 PM
Crontab entry doubt paventhan Solaris / OpenSolaris 1 11-03-2007 05:33 AM
Doubt in C++ zeropash Programming 1 07-05-2005 12:33 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:42 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