Problem : we need a command that will give previous day date and previous day should be mon-fri only.
Example :if we are running a command on Monday , it will give Friday �s date not Sunday�s .
Few more restrictions :
Command should be working in NM n/w.
Hard coding of date should be avoided.
Command will be running on NM and market holidays also .
Avoid the use of sysin or other static file .
I created a .sh script. The code is given below.
#!/bin/bsh
if [ date '+%w' ==1 ]; then
date -v -3d + '%Y/%m/%d'
else
date -v - 1d + '%Y/%m/%d'
fi
When I execute this script I get the following error
Welcome to forum, please use code tags for commands/inputs/codes which you use in your posts as per forum rules. Following may help you in same.
cat check_day.ksh
if [[ `date -d "1 day ago" +%A` == "Sunday" ]]
then
PRE_VAL=`date -d "3 day ago"`
elif [[ `date -d "1 day ago" +%A` == "Saturday" ]]
then
PRE_VAL=`date -d "2 day ago"`
else
PRE_VAL=`date -d "1 day ago"`
fi
echo $PRE_VAL " is the previous day."
Here name of the script is check_day.ksh .
When I execute it on my system following is the output.
./check_day.ksh
Fri Sep 4 07:58:17 EDT 2015 is the previous day.
Could you please check your date's command version by doing date --version as suggestion I gave will be for GNU dates. Also please mention your os details too(you can hide your box name but can provide version details and os name etc).
I tried = instead of ==. Even that did not work. My script name is Priorworkday.ksh. When I execute it I get the error interpreter "/bin/bash: not found file link resolves to "/usr/bin/bash"