Run script on particular day


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run script on particular day
# 1  
Old 10-23-2018
Run script on particular day without crontab

Hi Guys,

I am having a driving script which calls internally multiple scripts

Code:
sh main_script.sh > main_script.log

inside main_script.sh

sh -x script_1.sh

sh -x script_2.sh

sh -x script_3.sh

I Have to run the internal scripts in partcular dates

script_1.sh - 25th of every month
script_2.sh - daily
script_3.sh - Every quaterly month end

Code:


Last edited by rohit_shinez; 10-24-2018 at 12:40 AM..
# 2  
Old 10-24-2018
Use cron/crontab!
Man pages:
Code:
man crontab

Month end cannot be specified in crontab. How about the 1st of each month?
# 3  
Old 10-24-2018
I know its possible in crontab but can it be handled in script itslef like before trigerring each of the sub scripts
# 4  
Old 10-24-2018
Quote:
Originally Posted by rohit_shinez
I know its possible in crontab but can it be handled in script itslef like before trigerring each of the sub scripts
Yes, of course: there is the date command, which will tell you the current time and date. Use a format specifier to get the part of the date you want to base your condition on and use if... to conditionally run the script.

Example: run the script myscript only on 25th of the month (have a look at man date to understand what %d means):

Code:
if [ $(date '+%d') -eq 25 ] ; then
     myscript
fi

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 5  
Old 10-24-2018
what if script_1.sh fails then if i rerun the main_script.sh it should run only script_1.sh . For eg script_1.sh fails on 25th and re-running on 26th in that case script_1.sh will not run and other script_2.sh will also run which would have completed being daily job
# 6  
Old 10-24-2018
Quote:
Originally Posted by rohit_shinez
what if script_1.sh fails then if i rerun the main_script.sh it should run only script_1.sh . For eg script_1.sh fails on 25th and re-running on 26th in that case script_1.sh will not run and other script_2.sh will also run which would have completed being daily job
I suggest reading up on the test- command (this is effectively what [..] is). You have many possibilities to formulate various conditions on when and when not to run a script, you just need to implement them. It is far easier and in the long run less time-consuming for you to learn that (takes about 10 minutes) than to ask over and over again like you are doing now.

But first you should define what "script fails" means: does it exit with a non-zero return code? Does it write a log with an error message? Does it (not) produce a file? The secret of writing good scripts is to first make up your mind what exactly you want to do and under which conditions, then to define exactly what it is you want to do: "i need a file today" is less exact than "i need a file every second friday of the month" and this in turn is less exact than "i need a file every second friday only if this other file is up to date execpt for ....". Nobody here knows what you need as well as you do, so do your work first and we will gladly help with the rest.

I hope this helps.

bakunin

Last edited by bakunin; 10-24-2018 at 07:23 AM..
# 7  
Old 10-24-2018
Here is what i am trying

Code:
current_day=$(date +%e)
current_time=$(date +"%H:%M")
current_month=$(date +"%m")

if [ $current_day == 25 ] && [ $current_time == '10:00' ]
      sh -x script_1.sh && break  
 fi

if [ $current_time == '10:00' ]
then
   sh -x script_2.sh
fi

if [ $current_month == 4 ] || [ $current_month == 8 ] || [ $current_month == 12 ]
then 
  if [ $current_day == 30 ] && [ $current_time == '10:00' ]
    then
      sh -x script_3.sh
  fi
fi

For instance if my script_1 fails on 25th and trying to re-run the main_script.sh on next day, then it should run only script_1.sh instead of script_2.sh because script_2.sh was already successful on 25th
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