LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 04-14-2014, 07:50 AM   #1
ddsglq
LQ Newbie
 
Registered: Apr 2014
Posts: 19

Rep: Reputation: Disabled
Force CRON to run a job once again, despite the crontab settings


I run a script once a day. When the cron daemon runs the script I get a neat email from CRON containing the output of the script which I cant get if I run it manually.
Now sometimes I want to run this script right away but it takes an hour to run so I want to go away after initiating it and still get that email.
How do I force the cron daemon to run the script once again today right away instead of running the script directly or fiddling with the daily run time settings? Is it possible?
Or in other words how do I run a nohup script in background mode and send the output to my mail with subject containing the word CRON ?
Sorry I am new to linux.
 
Old 04-14-2014, 08:32 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Check the "batch" and "at" command man pages.

"batch" will do the same thing as "at now". Both are entries in the cron queue, but are only run once.

One thing the script might need to check on is whether the script is already active or not. This is sometimes a problem with colliding output file names or file data being updated (a second run while the first is running may wipe out the results of the first, or may cause data corruption).

Last edited by jpollard; 04-14-2014 at 08:36 AM.
 
Old 04-15-2014, 09:11 AM   #3
ddsglq
LQ Newbie
 
Registered: Apr 2014
Posts: 19

Original Poster
Rep: Reputation: Disabled
at now -f script.sh worked
but now I have another problem. the script ran ie I was able to see ps aux while it was running. But I didn't get any email. This is because my email filter auto deletes any mail that doesn't have CRON or Software in the subject line. Does 'at' send the email with a different subject? What word should be added to the filter to allow mail from at? I hope it is not a generic word like 'at'. That word would let in too many spam mails.
Is there a way to manually direct the output of a script to the mail specifying my own subject line in the command?
 
Old 04-15-2014, 10:08 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
My cron doesn't use CRON in the subject - is this a configuration you set in the crontab file?

The only way I have found is:
Code:
/path_to_script/script 2>&1 | mailx -s "Subject" userid@hostname
The scripts (or the crontab entry) I use have this for the command to run. Since there is no output from the command (both stdout and stderr are sent to mailx) no explicit mail is generated - leaving only that provided by the mailx command.

You can do this with:
Code:
$ at now
script.sh 2>&1 | mailx -s "CRON: whatever" user@server
^D
$
Or just have it embedded in a very short script.

Last edited by jpollard; 04-15-2014 at 10:16 AM.
 
Old 12-06-2017, 10:20 PM   #5
ddsglq
LQ Newbie
 
Registered: Apr 2014
Posts: 19

Original Poster
Rep: Reputation: Disabled
I know it has been many years. But I wanted to share how I solved this.
I will run date and then I will do crontab -e
and then change the time to 43 * * * *
if 43 was the next minute.
After the next minute after verifying the job has started I will do crontab -e and restore the original settings.
Now after the job finishes CRON will send out the mail as usual.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian daily cron job won't run, but does run in cron.hourly. sandersch Linux - General 7 05-24-2012 01:50 AM
cron job fails, but command in crontab succeeds when directly entered rmunsch Linux - Server 2 02-16-2009 05:27 PM
the crontab job is not run ust Linux - Software 1 03-24-2008 07:03 PM
Run crontab job sunhui Linux - Software 2 05-16-2007 08:35 PM
how to run crontab job every 30 seconds houssamfarag Slackware 5 06-23-2006 02:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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