• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1753
  • Last Modified:

Shell script to print out YESTERDAY's date: MMDDYYYY

Hello all,

I have a cron job that will be renaming some mysql tables daily to back them up..

I wanted to do this from a shell script but I'm not sure how to gate 'date' to show YESTERDAYS date (since the script is run at midnight)


YESTERDAY=$(date +%m%d%Y)   - todays date just fine heh


0
mcainc
Asked:
mcainc
1 Solution
 
TintinCommented:
If you have GNU date (standard on all Linux systems), you can simply do

YESTERDAY=$(date --date yesterday +%m%d%Y)
0
 
aherpsCommented:
Same as above but:
YESTERDAY=$(date --date='1 day ago' +%m%d%Y)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now