Visit The New, Modern Unix Linux Community


How to stop cronjob automatically after cron process get completed?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to stop cronjob automatically after cron process get completed?
# 1  
Blade How to stop cronjob automatically after cron process get completed?

Hi ,
I have scheduled the script using cron between 25-31 of the month.

My script will trigger the ETL job once file is available in Windows path between these days(every 2 hours between 26 - 30 of every month ).

So my question : "if the ETL job completes cron should stop the running the script. (i.e., if the ETL job completed on 26th after that cron should stop running the script for 2 hours of rest of the days)"

Is the any way can do ?

Please help
# 2  
Put a line in the job right at the end to write out a timestamp file somewhere. The existence of this file indicates that the required processing has already been done. Put in a line at the beginning of the job to check for the existence of a timestamp file and, if it exists, end the job without doing anything.

Schedule another cron job to run, say, the 4th of the month to delete the timestamp file so that things will run later in that month.
This User Gave Thanks to hicksd8 For This Post:
# 3  
How have you written the cron entry? It is possible that you will have it run every day from 25th to 31st inclusive.

Please paste the cron record in CODE tags.



Robin
# 4  
Code:
00 14 25-31 * * /path/script/shell.sh

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-29-2017 at 01:40 PM.. Reason: Added CODE tags.
# 5  
That will NOT run every 2 hours, but at 2pm for 7 days.
# 6  
Following the suggestion from hicksd8
Code:
00 */2 25-31 * * /path/script/shell.sh && >/tmp/shell.sh.lockfile

and have another cron job
Code:
00 14 24 * * rm -f /tmp/shell.sh.lockfile

The && does the lockfile only if the shell.sh exited happily (zero exit status).

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #290
Difficulty: Easy
Free and open-source software (FOSS) is software that anyone is freely licensed to use, copy, study, and change the software in any way, and but the source code must be maintained secretly.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To stop execution in cron

hi guys i have a question my cron should start executing minute but it sould stop execute only i have tried tis 10 * * * * /home/sample.sh >> /data/band/cron_$(date+|%Y|m|d).log (2 Replies)
Discussion started by: azherkn3
2 Replies

2. Shell Programming and Scripting

Process only files which have completed in transaction

Hi , I have a situation where I have to Process files ( move , edit or rename ) in a folder ..... This folder is a FTP folder and Files keep coming in when they are available ... So I should perform my actions on those which which completed transaction .. . Is there a way to identify a... (3 Replies)
Discussion started by: chillblue
3 Replies

3. Solaris

How to stop a cron job?

Hi Guys. can someone please tell me how to stop a running cron job without editing the cron file? I know you have to find the process ID of the command, but I have no idea of how to do that. I will really appreciate it . Thanks (3 Replies)
Discussion started by: cjashu
3 Replies

4. UNIX for Dummies Questions & Answers

Finding return code for completed process ??

I have Process Id for one background process and currently it is running state. I want to see the return code after the above running process is done. for the forground process normally I use "echo $?". But how to get the return code for my background process on UNIX/Linux?? Thanks in... (5 Replies)
Discussion started by: sriraman2
5 Replies

5. Shell Programming and Scripting

Command to stop all the cron jobs

Hi All, Please provide the command to stop all the cron jobs. Thanks in Advance Regards, Sindu (2 Replies)
Discussion started by: indira_s
2 Replies

6. Shell Programming and Scripting

Script - How to automatically start another process when the previous process ends?

Hi all, I'm doing automation task for my team and I just started to learn unix scripting so please shed some light on how to do this: 1) I have 2 sets of datafiles - datafile A and B. These datafiles must be loaded subsequently and cannot be loaded concurrently. 2) So I loaded datafile A... (10 Replies)
Discussion started by: luna_soleil
10 Replies

7. Shell Programming and Scripting

Cronjob Crontab Cron Restarter Help

Hello. I'd like to know how to make a simple restarter using cron. I made something like this: "* * * * * root home/..(full path)/file" But it doesn't work. How can I do that or how to make restarter of the application in other way? (1 Reply)
Discussion started by: ArtuDitu
1 Replies

8. Shell Programming and Scripting

How to create cron job automatically?

How do I write a perl script to get the cron jobs? I could do a perl -e ' system "crontab -l > jobs.txt " '; Is there a better way? Then I can use perl to make changes to jobs.txt. How can I submit the changes. I suppose I could use system "crontab jobs.txt", is there a better way? ... (0 Replies)
Discussion started by: siegfried
0 Replies

9. UNIX for Dummies Questions & Answers

temporarily stop cron services

hi can i know what is the command and in which directory to temporarily stop the cron service of my server? here is my server information thanks SunOS statsfs07 5.8 Generic_117000-03 sun4u sparc SUNW,Ultra-4 (1 Reply)
Discussion started by: legato
1 Replies

10. UNIX for Dummies Questions & Answers

cronjob process not work

Hi all, I having a very unknown problem. I set my process to cronjob but it does not work at all!!!!!!No error detected, just nothing.... Cron: 15 * * * * /process/directory/path/$processname.sh Script($processname.sh): nohup $process & Please help. I have no idea at all.... (3 Replies)
Discussion started by: clemeot
3 Replies

Featured Tech Videos