troubleshooting Question

Adding date to bash script for cronjob.. Pls help

Avatar of bemara57
bemara57 asked on
Linux DistributionsLinux OS Dev
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.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 4 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004