Run script on particular day


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run script on particular day
# 8  
Old 10-24-2018
I don't understand. You want script_1 to run on the 25th. But if it fails you want it to run on the 26th?

You want script_2 to run every day. But if it succeeds on the 25th you don't want it to run on the 26th?

What if script_1 keeps failing?

Andrew
# 9  
Old 10-24-2018
Let me explain you clearly. The expectation of script_1 - every month 25th it would run. Script_2 - every day and script_3 every quarterly month end. For eg. if script_1 fails due to any reason on 25th and if i re-run the main_script on 26th. In this scenario script_1 will not run on 26th but i would like to run on 26th because it failed on 25th but i tried re-running on next day or any other day on same month, if i re-run the main_Script for that month then it should script_1 should run. In this scenario if i take script_2 which runs every day shouldn't run for again because it was already successful on 25th daily run
# 10  
Old 10-24-2018
Comments:
break breaks a current for-loop or while-loop. exit exits the script.
&& runs the following command after a good exit status. || runs the command after a bad exit status.
If the exit status of the previous run matters, you need to save this somehow in a file, to be discovered in the next run.
date +%e puts a leading space if day is less than 10. date +%d returns the plain decimal number.
Why check the current time? Why not simply schedule for 10:00 (daily at 10:00) in crontab?
# 11  
Old 10-24-2018
Expanding a little on what MadeInGermany has already said...

Do you realize that there are 4 quarters in a year; not 3? Do you also realize that month numbers 4 and 8 are not the last month in any calendar quarter?

Are you aware that break has undefined behavior if it is invoked when you are not inside a for, while, or until loop? Although it is treated as a no-op by the Korn shell, it will give you a syntax error in bash.

What operating system (including version) are you using?

What shell (including version) are you using?

What exit code does script1.sh return when it succeeds. What exit codes does script1.sh return when it fails?

What exit code does script2.sh return when it succeeds. What exit codes does script2.sh return when it fails?

What exit code does script3.sh return when it succeeds. What exit codes does script3.sh return when it fails?

Even if you use cron to start your script, do you realize that there is no guarantee that any job will be started within one minute of its scheduled start time?
# 12  
Old 10-25-2018
Hi Don,

Its bash and Linux flavour,

for success scenario it will not return any exit because there will be scenario where daily and 25th will come in same time.

If the script_1.sh fails then it should exit post script_2.sh completes
# 13  
Old 10-25-2018
Quote:
Originally Posted by rohit_shinez
Hi Don,

Its bash and Linux flavour,

for success scenario it will not return any exit because there will be scenario where daily and 25th will come in same time.

If the script_1.sh fails then it should exit post script_2.sh completes
Your answers above demonstrate a complete lack of understanding of how running commands in your main script works, how all three of the scripts invoked by your main script work, and how shell programming works.

All of the actions taken in your main script are run synchronously, so there is absolutely no chance that if script_1.sh fails (or if it succeeds) it will not exit before script_2.sh starts. But, of course, if the command in your main script:
Code:
current_time=$(date +"%H:%M")

is invoked at any time other than the first minute of 10 o'clock in the morning, none of your numbered scripts will ever be run anyway. I see no reason why this test should be included in your script nor anything in the description of your problem that would make such a test desirable. Every command that is run synchronously returns an exit code before the next command in your script starts. Always. Unconditionally.

If you can't figure out whether or not any of the shell scripts you are invoking in your main script succeeded, there is absolutely no way that you can record whether or not they succeeded so you can re-run them the next day if they failed.
# 14  
Old 10-25-2018
You can save the exit status in a variable
Code:
./script1
x1=$?
./script2
if [ $x1 -ne 0 ]
then
  echo "script1 failed with status $x1"
  exit $x1
fi
./script3

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to run on 2 4 and 7 day of the month

I am looking for a unix script which could run a job on 2, 4 and 7 working day of the month. if the days are falling on the saturday/sunday. it should run on the next day. Thank you.. (9 Replies)
Discussion started by: tradingspecial
9 Replies

2. UNIX for Advanced & Expert Users

Run A Job in Cron On A Specific Day Excluding Holidays

Hi, I want to run a job in cron on a specific date(say 25th of every month) excluding holidays. Can anyone provide some hints to do this? Thanks for any inputs. (1 Reply)
Discussion started by: sktkpl
1 Replies

3. Shell Programming and Scripting

Writing a script to run weekly/monthly - check for weekday or day-of-the-month

Hi all, I currently have a UNIX file maintenance script that runs daily as a cron job. Now I want to change the script and create functions/sub inside it that runs on a weekly or monthly basis. To run all the scripts' daily maintenance, I want to schedule it in cron as simply maint.sh... (1 Reply)
Discussion started by: newbie_01
1 Replies

4. Shell Programming and Scripting

run the script for last day of the month

Hello Experts, I have a script which i want to run the on last day of every month. let say I have backup.sh script which i want to run it every month last day. Can anyone please help :confused: thanks (4 Replies)
Discussion started by: aks_1902
4 Replies

5. Shell Programming and Scripting

Script to check if last modified day is previous day

Hi, I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it. For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Discussion started by: hegdepras
1 Replies

6. AIX

kill process that run more then 1 day

hi all i need a script which will find all the processes witht the name of xxx and kill all those processes that runs for more than 1 day. Regards (3 Replies)
Discussion started by: Elii
3 Replies

7. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

8. Shell Programming and Scripting

crontab entry to run every last day of the month

i've created a script which should run every last day of the month. what would be the exact crontab entry for this? thanks! (9 Replies)
Discussion started by: tads98
9 Replies

9. UNIX for Dummies Questions & Answers

cron script -run every 2nd day of month except Monday

I know I can't schedule this in cron and would have to write a wrapper around my script and schedule it in cron ....but not sure how do to this? How do I exclude Monday if the 2nd day of the month falls on a Monday? Thanks. I tried this: 0 0 2 * 0,2-6 command And I know this doesnt... (2 Replies)
Discussion started by: newtou
2 Replies

10. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies
Login or Register to Ask a Question