Create a directory named as the current date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create a directory named as the current date
# 1  
Old 09-25-2010
Create a directory named as the current date

I am preparing a shell script to backup a few config files on a daily basis, with a retention of 30 days. Need some help with syntax/examples:

The shell script (running as cron) would require the following:

1. create a sub-directory within a specified (backup) directory, in the format MMDDYYYY
2. copy the config files (can be various paths) to this newly created directory
3. delete directory which is more than 30 days old.

Thanks,
Neil
# 2  
Old 09-25-2010
Could you show us what you tried so far and where you are stuck?
Tip: Pay attention to scripts run from cron !
# 3  
Old 09-25-2010
I have the basic syntax which will work. I just need help with the 3 steps.
# 4  
Old 09-25-2010
bash code:
  1. #!/bin/bash
  2. # 1. create a sub-directory within a specified (backup) directory, in the format MMDDYYYY
  3. DIR=$(date +%m%d%y)
  4. # 2. copy the config files (can be various paths) to this newly created directory
  5. for F in $FILES # here you need to specify which files...
  6. do
  7.   cp $F $DIR
  8. done
  9. # 3. delete directory which is more than 30 days old.
  10. # if you have GNU date
  11. rm -r $(date -d "30 days ago" +%m%d%y)
  12. # else you'll have to do some specific date calculation
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching for a files based on current date directory

Hi All, I've been trying to do some recursive searching but not been very successful. Can someone please help. Scenario: I have directory structure /dir1/dir2/dir3/ 2019/ 11/ 17 18 19 20 so what I want to do is run a script and as its 2019/11/18/ today it would go and only search... (3 Replies)
Discussion started by: israr75
3 Replies

2. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

3. Shell Programming and Scripting

I need to back up a bunch of files on a directory and save that file as the current date....

this is what i have to find the files modified within the past 24 hours find . -mtime -1 -type f -print0 | xargs -0 tar rvf "$archive.tar" however i need to save/name this archive as the current date (MM-DD,YYYY.tar.gz) how do i doo this (1 Reply)
Discussion started by: bugenhagen_
1 Replies

4. Homework & Coursework Questions

C Program to search and read all named pipes in current directory

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a C program to search the current directory for all pipes. 1. It will print the pipe... (2 Replies)
Discussion started by: natwickley
2 Replies

5. UNIX for Dummies Questions & Answers

Create a directory using current date

Hi, I have a question, is there any way I can, when i create a directory, put the current date on it so that the directory name will be "name-current date"? just curious (3 Replies)
Discussion started by: aric87
3 Replies

6. Shell Programming and Scripting

How to find the create time of a file if current date is in next month

Hi All, I want to find the time diffrence between currnt time and "abc.txt" file create time. I have solve that but if the abc.txt file created last month then is there any process to find the difftent? Exp: Create time of abc.txt is "Apr 14 06:48" and currect date is "May 17 23:47".... (1 Reply)
Discussion started by: priyankak
1 Replies

7. Shell Programming and Scripting

Use awk to create new folder in current directory

Alright, I am sure this is a laughable question, but I don't know so I am going to ask anyway. I have a little script I am writing to take information from one source, recode it in a certain way, and print to files for each subject I have data for. This all works perfectly. I just want to put... (6 Replies)
Discussion started by: ccox85
6 Replies

8. Solaris

check the current date file in directory

Hi, I am making a script which check the directory and if there is today date file, it is showing message file is there for today date . 1) filename is accessline.win.$timestamp example ;-accessline.win.200712211004 2) On monday i have recieved two file in this directory with current... (2 Replies)
Discussion started by: pallvi
2 Replies

9. UNIX for Dummies Questions & Answers

Directory create date

Hi, How do you find the create date of a directory? I can see the modification date using ls -l but I'm looking for the create date. Many thanks Helen (2 Replies)
Discussion started by: Bab00shka
2 Replies

10. UNIX for Dummies Questions & Answers

create directory named current date

Since this site solved my problems before, I am back for more (solutions) I down load via a script every day a file that has the same name as the file of the day before. I want to move that file to its own directory like: /archive/jul30 How do I capture the systems date in a script an... (2 Replies)
Discussion started by: flowrats
2 Replies
Login or Register to Ask a Question