LinuxQuestions.org
Help answer threads with 0 replies.
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 01-02-2005, 10:22 PM   #1
aunquarra
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware 10.1
Posts: 28

Rep: Reputation: 15
cron job only runs halfway


I've got a cron.daily script that's supposed to pull a remote text file, force it all to lowercase, remove stupid windows formatting junk, and save it with the date in the filename. The job runs, but the final document is empty. When you run the script manually from the command line, it works gloriously...

Code:
# get the date, for the title
dater=`date +%b-%d-%Y`;

# pull the remote file
wget --tries=0 --retry-connrefused --output-document=/var/log/foo/temp --url of txt file--

# remove the stupid windows formatting things like ^M, etc. for ease of viewing
tr -d '\15\32' < /var/log/foo/temp > /var/log/foo/temp2;

# force it to lowercase
cat /var/log/foo/temp2 | tr -t '[:upper:]' '[:lower:]' > /var/log/foo/foo$dater;

# clean up the temp files
rm /var/log/foo/temp;
rm /var/log/foo/temp2;
I've checked the permissions to make sure the directory was writeable, which it was. And, as stated before, it works perfectly if you execute it manually. Just, for some reason, when it runs as a cron job, the resulting file (/var/log/foo/fooJan-02-2005) is empty as can be.


I'm running on a slack 10.0 box, with bash as the shell of choice. If you need any other information, let me know. Any help would be extremely appreciated. I've been mulling over this for about three weeks so far, and I'm getting worse about forgetting to run this thing manually each morning. :P
 
Old 01-02-2005, 10:50 PM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Quote:
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null. We'll do this here since these jobs should run
# properly on a newly installed system, but if they don't the average newbie
# might get quite perplexed about getting strange mail every 5 minutes. :^)
If you look at root's crontab, you'll find that output is directed to /dev/null.

EDIT: ** Please ignore. I didn't read your post carefully. **

Last edited by Berhanie; 01-02-2005 at 11:04 PM.
 
Old 01-02-2005, 11:08 PM   #3
aunquarra
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware 10.1
Posts: 28

Original Poster
Rep: Reputation: 15
Ah... that's right.


I knew it would end up being something stupid I'd overlooked. I'll fix that and we'll see if it fixes it. Thanks!
 
Old 01-02-2005, 11:30 PM   #4
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
No, I don't believe that this solves your problem. At best the redirection to /dev/null hides an error message that would have been mailed to you about the problem. I think it's a permissions problem or a PATH problem. Please check.
 
Old 01-03-2005, 08:05 AM   #5
aunquarra
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware 10.1
Posts: 28

Original Poster
Rep: Reputation: 15
Permissions are right. I can say that much for certain. I've re-checked that countless times.

As far as the path being wrong, I don't see how that could be a problem if it runs properly when executed manually.

I thought you might have a point with your post about the /dev/null bit. I thought the > in...
Code:
tr -d '\15\32' < /var/log/foo/temp > /var/log/foo/temp2;
... might qualify as output. Is that not the case?

At any rate, my initial tinkering didn't work because I missed a stupid little something, so the script didn't even run last night. I fixed that, and I'll see in the morning if it works this time.
 
Old 01-03-2005, 02:25 PM   #6
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
You might want to leave the temp files around to see what they contain...
I noticed you have this:
# clean up the temp files
rm /var/log/foo/temp;
rm /var/log/foo/temp2;
Comment them out and then check to make sure that /var/log/foo/temp contains what you expect it to after the script runs.

Other questions...
Why do you run one this way:
tr -d '\15\32' < /var/log/foo/temp > /var/log/foo/temp2;
and then turn around and do this?
cat /var/log/foo/temp2 | tr -t '[:upper:]' '[:lower:]' > /var/log/foo/foo$dater;

couldn't you do this:
cat /var/log/foo/temp | tr -d '\15\32' | tr -t '[:upper:]' '[:lower:]' > /var/log/foo/foo$dater;
 
Old 01-06-2005, 09:55 AM   #7
aunquarra
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware 10.1
Posts: 28

Original Poster
Rep: Reputation: 15
Sorry about the delayed response. I've been too busy to even look into this for a couple days.

The main reason for separating them was for troubleshooting purposes, so I could look at the temp files as mentioned above, though I'll probably combine the commands as you suggested once it's... well, working.

I'm going to comment out the rm's and see how that goes in the morning.

Thank again for the help guys.
 
Old 01-10-2005, 10:29 AM   #8
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
Find anything?
 
Old 01-27-2005, 08:08 AM   #9
aunquarra
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware 10.1
Posts: 28

Original Poster
Rep: Reputation: 15
Actually no.

No matter what I do, there aren't any temp files created.

At least that establishes WHERE the problem lies. Just no idea why.
 
Old 01-27-2005, 08:39 AM   #10
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
Just an idea...
Change /var/log/foo/whatever to /tmp/whatever
Not all users can write to the /var/log directory.
 
Old 01-27-2005, 02:11 PM   #11
aunquarra
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware 10.1
Posts: 28

Original Poster
Rep: Reputation: 15
Hmmm...

But if it didn't have permission to write the temp files, how is it still writing the dater'ed files?
 
Old 01-27-2005, 03:25 PM   #12
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
Got this working through a cron job:
Code:
# get the date, for the title
dater=`date +%b-%d-%Y`;

wget --tries=0 --retry-connrefused --output-document=/tmp/foo_$dater http://192.168.84.9/index.html

# remove the stupid windows formatting things like ^M, etc. for ease of viewing
tr -d '\15\32' < /tmp/foo_$dater > /tmp/temp2_$dater;

# force it to lowercase
cat /tmp/temp2_$dater | tr -t '[:upper:]' '[:lower:]' > /tmp/foo_$dater;

# clean up the temp files
rm /tmp/temp2_$dater;
 
Old 01-29-2005, 11:22 AM   #13
aunquarra
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware 10.1
Posts: 28

Original Poster
Rep: Reputation: 15
Just as an idea, I'm going to try to have the wget write to /tmp and have the cat commands pull from there...


Code:
# get the date, for the log title
dater=`date +%b-%d-%Y`;

# pull the remote file
wget --tries=0 --retry-connrefused --output-document=/tmp/tempfile http://www.fakedomain.com/test.txt;

# clean it up
cat /tmp/tempfile | tr -d '\15\32' | tr -t '[:upper:]' '[:lower:]' > /var/log/foo/foo$dater;
I don't see how it could have any affect, but it's worth a shot. I can't believe it's taken me this long to actually get this working...
 
Old 01-30-2005, 02:52 PM   #14
aunquarra
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware 10.1
Posts: 28

Original Poster
Rep: Reputation: 15
Gah. No dice. Still creates the empty dated file.

I'm gonna tinker with this some more, but in the meantime, I'll have the log reading script execute the cron script if the dated file is empty.
 
Old 01-30-2005, 10:18 PM   #15
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
So does the /tmp/tempfile have anything in it?
 
  


Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with cron job parthcorp1 Linux - General 2 02-01-2005 11:37 AM
Why Does One Cron Job Runs Twice? cpope67 Programming 4 11-16-2004 06:09 AM
cron job ? johnyy Linux - Software 3 12-10-2003 06:00 PM
cron job thesnaggle Linux - Newbie 1 09-19-2003 10:47 AM
Cron job T-Rex Linux - Newbie 1 09-26-2001 11:28 AM


All times are GMT -5. The time now is 01:40 AM.

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