To run the script only if the date is not between 5 th and 10th of january ?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users To run the script only if the date is not between 5 th and 10th of january ?
# 1  
Old 05-06-2009
Question To run the script only if the date is not between 5 th and 10th of january ?

Hi

I am new to unix.

I have to set up a cron for the program , which should run every Monday at 3 a.m, however , if the date is between the 5 th and the 15th of January,APril or December, the program should not run


I know i cant do this in cron , Help with writing the if contion is appreciated.

Thank You
# 2  
Old 05-06-2009
Hammer & Screwdriver

I am not convinced that this can not be done in cron. However, I would set my cron to run a script for every Monday at 3am.
Then, at the beginning of the script, have IT check the date to see if conditions are met to continue or exit. Start with something like:
Code:
> day=`date '+%d'`
> echo $day
06
> month=`date '+%m'`
> echo $month
05

then if statements to validate the day of month and month number.
# 3  
Old 05-06-2009
if the condition meets , i should run another script ..how to do that

Quote:
Originally Posted by joeyg
I am not convinced that this can not be done in cron. However, I would set my cron to run a script for every Monday at 3am.
Then, at the beginning of the script, have IT check the date to see if conditions are met to continue or exit. Start with something like:
Code:
> day=`date '+%d'`
> echo $day
06
> month=`date '+%m'`
> echo $month
05

then if statements to validate the day of month and month number.

Thank you for ur reply :-
can u pls tell me is this correct :-

vi crontest.sh

#!/bin/bash
Date='date +%d'
Month='date +%m'
Day='date +%a'
if[["$Date" -ge "05" && "$Date" -le "15"] && ["$Month" -eq "01" -o "$Month" -eq "04" -o "$Month" -eq "12"] && ["&Day" = "Mon"]]; then
exit()
else
RunTheShell.sh
fi


once i create this shell script which runs the shell RunTheShell.sh , only when the Monday doesnot fall between 05 and 15 th of the month jan , april and dec .

Where and how should i set the crontest.sh to run on every monday at 3am .


pls help me how to do this..
Thank You
# 4  
Old 05-06-2009
Hammer & Screwdriver

If you set your cron as
0 3 * * 1 crontest.sh

Then you won't have to deal with the DAY variable.
I think the following is 'better', but I might still be missing something.

Code:
#!/bin/bash
Date='date +%d'
Month='date +%m'

if [["$Date" -ge 05 && "$Date" -le 15] && ["$Month" -eq 01 -o "$Month" -eq 04 -o "$Month" -eq 12]]
  then
  exit 99   # habit, exit with return code on error
fi

RunTheShell.sh
# or simply the command you want to do

# 5  
Old 05-06-2009
Bug How to create crontab

Quote:
Originally Posted by joeyg
If you set your cron as
0 3 * * 1 crontest.sh

Then you won't have to deal with the DAY variable.
I think the following is 'better', but I might still be missing something.

Code:
#!/bin/bash
Date='date +%d'
Month='date +%m'
 
if [["$Date" -ge 05 && "$Date" -le 15] && ["$Month" -eq 01 -o "$Month" -eq 04 -o "$Month" -eq 12]]
  then
  exit 99   # habit, exit with return code on error
fi
 
RunTheShell.sh
# or simply the command you want to do


Thank You So much .

I want to know how to setup crontab

at the unix prompt i gave
$crontab -e

the reply i got is 108

how to create it pls
# 6  
Old 05-06-2009
crontab -e returned an error - you need to get your sysadmin to help. You may not have access to crontab.
# 7  
Old 05-07-2009
Check if you have access to edit the cron tab,

cat /etc/cron.allow ----> if your user account is not present in this file, then you have to contact your administrator to give you the access
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Run shell script based on date file

Hi Team, I have a to run a script based on a date present in a different file which updates everyday. Kindly help with the solution. My current execution : ksh scriptname.sh 10152019. But here i want to enter this date from a file which gets updated daily. My appraoch : date file location:... (3 Replies)
Discussion started by: midhun3108
3 Replies

2. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

3. UNIX for Dummies Questions & Answers

How to write a shell script to Run it the from Date A to Date B?

Hi , How would i write a shell script to run the code from one date to another date EXample 2014-01-01 to 2014-02-28, can i any provide some clue on this (4 Replies)
Discussion started by: vikatakavi
4 Replies

4. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

5. Shell Programming and Scripting

run script in time and date range

i need to run one script inside of other, and there is some terms - main script in scheduled in cron for everyday runing every 5min - i need to run /tmp/script2.sh after first 3 days in month - i need to run /tmp/script2.sh from 7-9AM, main script is runining all day all recommendations are... (1 Reply)
Discussion started by: waso
1 Replies

6. Shell Programming and Scripting

how to run an already made script run against a list of ip addresses solaris 8 question

how to run an already developed script run against a list of ip addresses solaris 8 question. the script goes away and check traffic information, for example check_GE-VLANStats-P3 1.1.1.1 and returns the results ok. how do I run this against an ip list? i.e a list of 30 ip addresses (26 Replies)
Discussion started by: llcooljatt
26 Replies

7. Shell Programming and Scripting

shell script that will run for a specific date

Hi, I have these changes needed to modify a shell script that will run on a specific date of a month, below pseudocode, appreciate any answers..thanks.. if date of the month is 26th then ..event 1 fi if date of the month is 26th and month are MAR,JUN,SEP,DEC then ..event2 ... (7 Replies)
Discussion started by: sonja
7 Replies

8. AIX

My script didn't run every run every minute at cronjob

In my cronjob, I would like to schedule my script.sh to run every minutes. I crontab -e and have in line below but it didn't seems to run at all. * * * * * script.sh When I run it manually, I can run it. Is that anything wrong with the above line? If I change it to something like below,... (4 Replies)
Discussion started by: ngaisteve1
4 Replies

9. Shell Programming and Scripting

Run script from another script if system date was reached

I what to find a system date in a shell script and search for it in a file in specific record. If the record (ENDC) has the same date I what to execute another shell script. Here is example of the file: Can someone please help me with this ? (3 Replies)
Discussion started by: Lenora2009
3 Replies
Login or Register to Ask a Question