LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Force CRON to run a job once again, despite the crontab settings (https://www.linuxquestions.org/questions/linux-newbie-8/force-cron-to-run-a-job-once-again-despite-the-crontab-settings-4175501649/)

ddsglq 04-14-2014 07:50 AM

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.

jpollard 04-14-2014 08:32 AM

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).

ddsglq 04-15-2014 09:11 AM

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?

jpollard 04-15-2014 10:08 AM

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.

ddsglq 12-06-2017 10:20 PM

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.


All times are GMT -5. The time now is 02:49 AM.