Home > database >  Is there a way to run shell command only once a year?
Is there a way to run shell command only once a year?

Time:11-23

I have a shell script inside Jenkins job where I need that only one command inside the script will run only once a year every year. Something like:

if [today is 1st of Nov in any Year]; then
 do this command....
fi

Is it possible?

CodePudding user response:

The date utility in conjunction with a string test should do the trick:

case $(date  %m%d) in
  (1101) run this command
esac

For the formats that date(1) accepts, see the strftime(3) manual page.

CodePudding user response:

Since you are using Jenkins and this is a job that runs once a year, you can move the script into a Jenkins job and remove the if conditions. Then, under the "build triggers" section you can choose the option to build periodically. Cron expressions are supported here, or you could simply use @yearly. Doing this will show something like:

Would last have run at Sunday, September 11, 2022 10:21:52 PM CEST; would next run at Monday, September 11, 2023 10:21:52 PM CEST.

Which should hopefully be what you're looking for.

  • Related