www.unix.com
Open in
urlscan Pro
209.126.104.117
Public Scan
URL:
https://www.unix.com/shell-programming-and-scripting/142129-rerun-cronjob-if-doesnt-work-first.html
Submission: On April 03 via manual from US — Scanned from DE
Submission: On April 03 via manual from US — Scanned from DE
Form analysis
3 forms found in the DOMPOST https://www.unix.com/search.php?do=process
<form action="https://www.unix.com/search.php?do=process" method="post">
<input type="hidden" name="do" value="process">
<input type="hidden" name="quicksearch" value="1">
<input type="hidden" name="childforums" value="1">
<input type="hidden" name="exactname" value="1">
<input type="hidden" name="s" value="83a0594eb5838dfa78abaaffc5de198b">
<input type="hidden" name="securitytoken" value="guest">
<input type="hidden" name="showposts" value="0" id="rb_nb_sp0_neo" tabindex="1002">
<div id="bs-search-bar" class="nav-top-margin" style="margin-bottom:20px;">
<div class="input-group">
<span class="input-group-addon"><button class="btn btn-light" style="background-color: #f0f0f7;border:1px solid silver;color:gray;"><i class="fas fa-search neo-toolbit" data-original-title="" title=""></i></button></span>
<input type="search" class="form-control" style="background-color: lightyellow" name="query" tabindex="1001" placeholder="Search The UNIX and Linux Forums (Quick Search)">
</div>
</div>
</form>
POST https://www.unix.com/search.php?do=process
<form action="https://www.unix.com/search.php?do=process" method="post">
<input type="hidden" name="do" value="process">
<input type="hidden" name="quicksearch" value="1">
<input type="hidden" name="childforums" value="1">
<input type="hidden" name="exactname" value="1">
<input type="hidden" name="s" value="83a0594eb5838dfa78abaaffc5de198b">
<input type="hidden" name="securitytoken" value="guest">
<div>
<input type="text" class="bginput form-control" name="query" size="25" tabindex="1001">
</div>
<div style="margin:10px 0px 10px 0px;text-align:center;">
<input type="submit" class="button btn btn-primary btn-block" value="Search" tabindex="1004">
</div>
<div style="margin-top:6px">
<label for="rb_nb_sp0"><input type="radio" name="showposts" value="0" id="rb_nb_sp0" tabindex="1002" checked="checked" style="margin: 0px 5px 0px 0px;">Show Threads . </label> <label for="rb_nb_sp1"><input type="radio" name="showposts"
value="1" id="rb_nb_sp1" tabindex="1003" style="margin: 0px 5px 0px 0px;">Show Posts</label>
</div>
</form>
GET https://www.unix.com
<form action="https://www.unix.com" method="get">
<div style="padding:0px; margin:0px; border:0;width:100%;text-align:center;">
</div>
<div style="background-color:white;">
<br>
<div style="text-align:center; width:100%;background-color:white;">
<div class="smallfont" style="width:100%;background-color:white;padding-left:20px;padding-right:20px;">
<strong>
<span class="neo-footer-contactus"><a href="https://www.unix.com/sendmessage.php?s=83a0594eb5838dfa78abaaffc5de198b" style="text-decoration:none;" rel="nofollow" accesskey="9">Contact Us</a></span>
<span class="neo-footer"> - <a href="https://www.unix.com/" style="text-decoration:none;">The UNIX and Linux Forums - unix commands, linux commands, linux server, linux ubuntu, shell script, linux distros.</a> -</span>
<span class="neo-footer"><a style="text-decoration:none;" href="https://buysellads.com/buy/detail/215189" rel="nofollow" accesskey="9">Advertising</a> - </span>
<a style="text-decoration:none;" href="https://www.unix.com/shell-programming-and-scripting/142129-rerun-cronjob-if-doesnt-work-first.html#top" onclick="self.scrollTo(0, 0); return false;"><span class="neo-footer">Top</span></a>
</strong>
</div>
</div>
</div>
</form>
Text Content
The UNIX and Linux Forums Forum Home Linux and Unix Man Pages Search Forums Search Community Posts Today's Posts Quick Links Man Pages RedHat Commands OpenSolaris Commands Linux Commands SunOS Commands FreeBSD Commands All UNIX Man Pages All Linux Man Pages Full Man Repository Login or Register to Ask a Question and Join Our Community Search Forums Show Threads . Show Posts Tag Search Advanced Search Quick Links Contact Us Forum Rules Today's Posts FAQ Pictures & Albums All Albums Miscellaneous What is My IP Whois Mark Forums Read SHELL PROGRAMMING AND SCRIPTING RERUN A CRONJOB IF IT DOESN'T WORK AT FIRST. Tags rerun cronjob, shell scripts Login to Discuss or Reply to this Discussion in Our Community Thread Tools Search this Thread Top Forums Shell Programming and Scripting Rerun a cronjob if it doesn't work at first. # 1 08-11-2010 libertyforall Registered User 21, 0 Join Date: Feb 2010 Last Activity: 18 July 2011, 3:13 PM EDT Location: Hawaii Posts: 21 Thanks Given: 0 Thanked 0 Times in 0 Posts Rerun a cronjob if it doesn't work at first. -------------------------------------------------------------------------------- I want to add a line to the script that searches for a file. If the file does not exist, I need to kill the cronjob and run it again in one hour. I am running the program and 2 am and 2pm. I would want the job to run again at 3am and 3pm respectively. How could I do this and still keep the cronjob running twice daily if I killed it once? The cronjob simply runs one file. example Code: sh filebatch.sh . Then filebatch.sh runs several other files, example Code: $sh filebatch2.sh $sh filebatch3.sh $sh filebatch4.sh . Filebatch2.sh is a script that uses wget to pull files that I need to run the program. If the files are not ready, I want it to kill the entire job and run it again in 1 hour. I would like to put the line of code right after the command Code: wget file1 . How would I do this. I think I am using a linux machine with a c shell. See below. Code: [rhuff@huina working]$ echo $SHELL /bin/csh ---------- Post updated at 01:18 PM ---------- Previous update was at 12:09 PM ---------- Looks like I also have bash installed on the box. It looks like when I use an sh command it runs bash libertyforall View Public Profile for libertyforall Find all posts by libertyforall # 2 08-12-2010 agama Registered User 1,466, 512 Join Date: Jul 2010 Last Activity: 7 April 2014, 3:02 PM EDT Location: earth>US>UTC-5 Posts: 1,466 Thanks Given: 110 Thanked 512 Times in 491 Posts Cron is a very basic scheduler without any real conveniences such as retries, so you'll need to get creative. My first thought is to schedule the script at both times (2pm and 3pm for instance) and have the first script delete, or move, the input file. The second execution will fail because the first execution processed the file, and if the file wasn't there for the first execution, the second should find it. If the script is already deleting/moving the file, then no changes will be needed. If you need to keep the file, another simple solution would be to have the script sleep for an hour and retry if it doesn't find the file initially. Depending on the complexity of your script this will require the least amount of change to your script. The only other way that I can think of is a bit of a kludge, and will require a few modifications to your script, but it will work. First, modify your script to create a 'rerun' file in /tmp or some other known location when it is not able to find the file that it needs. It then exits. A second modification, to accept a check option from the command line is also necessary. If the check option is present, then the script should initially test for the 'rerun' file. If the rerun file isn't present, then the script should immediately exit. The fact that there is no rerun file indicates that the earlier execution was successful. Once those changes are made, add two more lines to your crontab that invoke the script at 3pm and 3am with the check option. A small (untested) example of this (ksh/bash Im not a Csh person at all): Code: #!/usr/bin/env ksh create_rerun=1 # default to creating rerun on failure if [[ $1 == -c ]] then if [[ ! -f /tmp/my.rerun ]] then echo "did not find rerun file; exiting OK" exit 0 fi create_rerun=0 # don't create a rerun on failure fi rm -f /tmp/my.rerun # ensure that the rerun file is gone if [[ ! -f needed_file_name ]] then echo "unable to find needed file" if (( $create_rerun > 0 )) then touch /tmp/my.rerun exit 0 # stop now, an ok return code fi exit 1 # stop now -- error fi # what ever code you have to manipulate the file If the script cannot be modified, then create a small 'wrapper' that is basically the code above and invoke the wrapper from cron. The wrapper then invokes the real script, but only if the file exists. The crontab entries would be something like this for the check method: Code: 0 2 * * * /usr/home/me/bin/myscript 0 3 * * * /usr/home/me/bin/myscript -c agama View Public Profile for agama Find all posts by agama Login or Register to Ask a Question Previous Thread | Next Thread 9 MORE DISCUSSIONS YOU MIGHT FIND INTERESTING 1. SHELL PROGRAMMING AND SCRIPTING -NE 0 DOESN'T WORK -LE DOES Hi, I am using korn shell. until ] do echo "\$# = " $# echo "$1" shift done To the above script, I passed 2 parameters and the program control doesn't enter inside "until" loop. If I change it to until ] then it does work. Why numeric comparison is not working with -ne and works... (3 Replies) DISCUSSION STARTED BY: AB_2010 3 Replies 2. UNIX FOR DUMMIES QUESTIONS & ANSWERS WHY DOESN'T THIS WORK? find . -name "05_scripts" -type d -exec mv -f {}/'*.aep\ Logs' {}/.LogFiles \; Returns this failure: mv: rename ./019_0120_WS_WH_gate_insideTEST/05_scripts/*.aep\ Logs to ./019_0120_WS_WH_gate_insideTEST/05_scripts/.LogFiles/*.aep\ Logs: No such file or directory I don't know why it's trying... (4 Replies) DISCUSSION STARTED BY: SCRIBLING 4 Replies 3. SHELL PROGRAMMING AND SCRIPTING DOESN'T RUN AS A CRONJOB... Hi! I have a svn backup script that works perfectly if I execute it from the command line but if I set it as a cronjob to run at night, only part of the code works. So, basically the scripts starts by deleting the folder yesterday and then moves the folder today to the folder yesterday. When... (4 Replies) DISCUSSION STARTED BY: RUBEN.RODRIGUES 4 Replies 4. UNIX FOR DUMMIES QUESTIONS & ANSWERS FTP DOESN'T WORK Hi! I have 2 servers. The firts has vsftpd server with this configuration: # Example config file /etc/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp daemon more usable. # Please see vsftpd.conf.5 for all... (2 Replies) DISCUSSION STARTED BY: TORQUEMADA 2 Replies 5. UNIX FOR DUMMIES QUESTIONS & ANSWERS HOW CAN I KNOW THAT CRONJOB WORK STATUS how can i know that cronjob work status(like completed or throws any error) (2 Replies) DISCUSSION STARTED BY: SS4U 2 Replies 6. UNIX FOR DUMMIES QUESTIONS & ANSWERS SCRIPT DOESN'T WORK, BUT COMMANDS INSIDE WORK Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies) DISCUSSION STARTED BY: CHEONGWW 2 Replies 7. SHELL PROGRAMMING AND SCRIPTING WHY DOESN'T THIS WORK? cat .servers | while read LINE; do ssh jason@$LINE $1 done exit 1 ./command.ksh "ls -l ~jason" Why does this ONLY iterate on the first server in the list? It's not doing the command on all the servers in the list, what am I missing? Thanks! JP (2 Replies) DISCUSSION STARTED BY: JPEERY 2 Replies 8. UNIX FOR DUMMIES QUESTIONS & ANSWERS REPQUOTA DOESN'T WORK AS CRONJOB?!? Hello: I'm trying to run repquota -ag > /home/usersdir/repquota.txt as a daily cronjob at midnight, but the file always ends up blank. I even tried writing a quick Perl script to e-mail me what running that command outputs, and it's nothing. Can root run repquota as a cronjob? Do I have... (1 Reply) DISCUSSION STARTED BY: B416 1 Replies 9. 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 Login or Register to Ask a Question MEMBER BADGES AND INFORMATION MODAL × Close FEATURED TECH VIDEOS Powered By 10 Elemental (Latin America Market Trailer 1 Subtitled) Share Next Stay All times are GMT -4. The time now is 02:18 PM. Contact Us - The UNIX and Linux Forums - unix commands, linux commands, linux server, linux ubuntu, shell script, linux distros. - Advertising - Top Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved. Privacy Policy