Quote:
Originally Posted by smilemukul
Can any one tell me what the below expression means while creating a script as,
[`date +%a` = Sun ]
|
This tests if the output of the command
date +%a is equal to
Sun. Backticks are the syntax for command substitution, as well as the new syntax for bash/ksh
$(command). Pay attention to spaces: there must be a space after the opening bracket and a space before the closing one, e.g.
Code:
[ $(date +%a) = Sun ]
and yes.. this is a way to test if the current day is Sunday.
Quote:
Originally Posted by smilemukul
Also need to confirm whether below command is correct for running a cron job for 3rd Sunday as,
0 0 15-21 * * [`date +%a` = Sun ] && /path/to/command
Thanks
|
It should work (provided the syntax is slightly corrected, as explained above). This crontab runs at 00:00 of every day between 15th and 21st of every month. It checks if it's Sunday and execute /path/to/command accordingly.