troubleshooting Question

Adding date to bash script for cronjob.. Pls help

Avatar of bemara57
bemara57 asked on
Linux OS DevLinux Distributions
4 Comments2 Solutions5010 ViewsLast Modified:
I'm trying to write a bash script that I can add to the cron. What I want to do is copy a folder and attach a date (any format is ok) to the end of it and put it in a backup folder. The only part I'm stuck on is creating the date as a variable and attach it to the folder name. This is what I'm trying to do on the Red Hat.

#!/bin/sh
cp dir_test /backup/dir_test_YYYY_MM_DD

After getting the date straight, I would just add this to /etc/crontab for update everyday at 6am right?
0 6 * * * /home/myscript.sh

I'm not sure if I even need a script file, can't I just put the command on the crontab itself? Thanks in advance for the. I just want to make sure I've got the right syntax and all.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros