SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Thursday, February 10, 2011

Shell script to run a particular job not on holidays

Currently i had a requirement in my opensource project to run the jobs not on holidays.In the previous post, i have tried with grouping the datas into arrays and then comparing with current date.

Now in this post i tried with the grep method and then on fetching the exit status or $? we can able do the logic or run other scripts.

How my script look likes

#!/usr/bash

#By default i have used date, if u want to change the format.You can try like date +%Y-%m-%d or you can have a better understanding from this post

grep -i date holiday.txt

#date is the default current date of the system & holiday.txt is the file having the collection of holidays

Now on checking the $? the status of the above command we can achieve our target
$? status will be 0, when the current date matches with date from the text.

if[ $? -ne 0] then;
#script to run the jobs
exit
fi

Finally the code will be much more simpler than the code in my previous post

#!/bin/bash
grep -i date holiday.txt
if[ $? -ne 0] then;
#script to run the jobs
exit
fi