In a unix shell, how to get yesterday’s date into a variable?
You can use GNU date command as shown belowGetting Date In the Past
To get yesterday and earlier day in the past use string day ago:date –date=’yesterday’
date –date=’1 day ago’
date –date=’10 day ago’
date –date=’10 week ago’
date –date=’10 month ago’
date –date=’10 year ago’Getting Date In the Future
To get tomorrow and day after tomorrow (tomorrow+N) use day word to get date in the future as follows:date –date=’tomorrow’
date –date=’1 day’
date –date=’10 day’
date –date=’10 week’
date –date=’10 month’
date –date=’10 year’
Source: datetime – In a unix shell, how to get yesterday’s date into a variable? – Stack Overflow
I basically google everything when making a shell script for linux. Blame projects with component that require windows stuff which has helped me forget what I used to know about shell scripting
Here is a way of using GNU date which is fortunately present in the linux installed in the oracle servers where our weblogic application servers are installed.
This was used in a CRON job that had to look at a file that is stored in a directory which is formatted with yesterday’s date <YYYYMMDD>.
another useful stackoverflow link regarding the date command.
Here is the link that help me format the command in a CRON job
The secret is that % have to be escaped with \