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
 
fi

If i understand correctly for the rest of months on 26th day event1 will be executed and for the specified months 26th day event 2 will be executed right?

How do you get date? Is it "now" or a parameter (and in what format then)?

 
TodayDate=$(date +%d)
MonthNum=$(date +%b)
if [ "$TodayDate" -eq "26" ]
then
 case $MonthNum in
  Mar,Jun,Sep,Dec)
   echo "Event 2";;
        *)  echo "Event 1";;
 esac
fi
1 Like

yes, prarat that was the scenario..

and yazu,, at the start of the script i see this, is this what you're looking for?

CLMI=`date +"%m%d%y%H%M%S"`
echo 'Currency Load Monitoring #'$CLMI
STARTTIME=`date +"%b %d %H:%M:%S %Y"`
echo 'Time Started: '$STARTTIME
#getPass(){
#        grep ^${1}:${2} $PS_HOME/autosys/pass/global.pass  | awk '{print $2}'
RATES_ALERT="0"
DAY=`date +"%a"`
D_MSG=""
M_MSG=""
Q_MSG=""

Could you please try this

a=27
date=` date +%d`
month=` date +%m`
if [ $date -eq $a ]
then
if [ $month -eq 03 -o $month -eq 06 -o $month -eq 09 -o $month -eq 12 ]
then
echo 'Execute event 1'
else
echo 'Execute event2'
exit 1
fi
fi

Thanks,
Pragyan

---------- Post updated at 02:22 AM ---------- Previous update was at 02:21 AM ----------

small correction a=26

1 Like

Hi, I think you can try this as cronjob as below:

Case will suffice with a bit regex
You can, of course put in the exact hour and minute, and just run the script all the time every 3 min from cron.
Please check man date on your unix/linux box.

RUNTM=$(date "+%d%m%k%M")
case $RUNTM in
26122100) printf "action for Dec 26th \n"
;;
260[369]2200) printf "action for  Mar Jun Sep 26th \n"
;;
esac