bash – Using the system date / time in a Cron Script – Unix & Linux Stack Exchange

bash – Using the system date / time in a Cron Script – Unix & Linux Stack Exchange

You could try something like this:

15 11 * * * touch “/tmp/$(date +%d-%m-%Y).sql”

To see if your particular cron will run the command out of crontab as a script in and of itself, or if you need to write a script that figures out the date as a string, and then runs your mysqldump command.

“cron” on Redhat Enterprise Linux 5.0 (I think) did not like the “$()” construct, and kept giving me errors about not finding a matching ‘)’.

NOTE: As glenn jackmann notes below, you have to escape all ‘%’ characters.

15 11 * * * touch “/tmp/$(date +\%d-\%m-\%Y).sql”

via bash – Using the system date / time in a Cron Script – Unix & Linux Stack Exchange.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s