Creating directory daily basis...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating directory daily basis...
# 1  
Old 03-04-2011
Creating directory daily basis...

Need help on this script.
the month is not changing to February...

Code:
#!/bin/bash

for X in `seq 1 100`
do

DATE=`date +%Y-%m-%d "--date=${X} day ago"`
Y=`date +%Y`
M=`date +%m`
D=`date +%d "--date=${X} day ago"`
DIR=/home/LogBackup

for i in `seq 1 `
do
        if [ -d  ${DIR}/${Y}/${M}/${D}/Login/Login0${i} ];then

#               echo "OK ${Y}${M}${D}"
                echo "OK ${DATE}"

        else

        #       mkdir -p ${DIR}/${Y}/${M}/${D}/Login/Login0${i}
                   echo  ${DIR}/${Y}/${M}/${D}/Login/Login0${i}

        fi


done

             echo Login01::R/home/seal/Login/EnterUser_log/LS_${DATE}.log /home/LogBackup/${Y}/${M}/${D}/Login/Login01/
#       rsync -avz Login01::R/home/seal/Login/EnterUser_log/LS_${DATE}.log /home/LogBackup/${Y}/${M}/${D}/Login/Login01/

#             echo Login02::R/home/seal/Login/EnterUser_log/LS_${DATE}.log /home/LogBackup/${Y}/${M}/${D}/Login/Login02/
#       rsync -avz Login02::R/home/seal/Login/EnterUser_log/LS_${DATE}.log /home/LogBackup/${Y}/${M}/${D}/Login/Login02/

done


Last edited by pludi; 03-05-2011 at 04:17 PM..
# 2  
Old 03-05-2011
Quote:
Originally Posted by alelee
Need help on this script.
the month is not changing to February...
It definitely does for me.

Code:
for X in `seq 1 100`
do
        DATE=`date +%Y-%m-%d "--date=${X} day ago"`
        echo $DATE
done

prints
Code:
2011-03-03
2011-03-02
2011-03-01
2011-02-28
2011-02-27
2011-02-26
2011-02-25
2011-02-24
...

on my system.

Are the Y, M, and D variables also supposed to be in the past? Because you just call date without the X day ago there.

You can extract those from the DATE var easily enough with
Code:
IFS="-" read Y M D <<< "${DATE}"

BTW, 'seq 1 100' isn't a good way to do a loop like that. for ((X=1; X<=100; X++)) ; do stuff ; done is much less likely to challenge the maximum size of a shell variable.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to count files on daily basis

Hi all I need to count files on a daily basis and send the output via email, what I am currently doing its simply running the following:ls -lrt *.cdr | awk '{if(($6 == "Jul") && ($7 == "13")) print $0}' | wc -l, which in this case it will count all files with extension "cdr" from the month of... (13 Replies)
Discussion started by: fretagi
13 Replies

2. Shell Programming and Scripting

Check daily files arrival in a directory

Hi All, I wanted to write a script to check if set of files exist in a directory or not for a particular day. each file has a date stamp. Now i want to implement this - -i can check files of a particular date in a particular folder -generate log and send it to through email. Big THANKS !!... (5 Replies)
Discussion started by: flagboy2014
5 Replies

3. Shell Programming and Scripting

Script to move file on a daily basis

Hi! Please I need help on the a script that would pick one file in a directory, change its name, them change its permissions, them move to a different directory, but has to be done on a daily basis, and the file that is being moved to its final destination has to have the following format:... (7 Replies)
Discussion started by: fretagi
7 Replies

4. UNIX for Dummies Questions & Answers

Tracking the script(.sh) files triggered on daily or monthly basis from source

Hi Gurus, Is there any solution for tracking the script(.sh) files triggered on daily or monthly basis from source - Datastage (Routines) Needs to find out if this scripts are running on daily just want to know that is there anything to track Thanks in Advance (2 Replies)
Discussion started by: SeenuGuddu
2 Replies

5. UNIX for Dummies Questions & Answers

Create alias to daily dated directory

Hello, I wanted to see if there's a way to shortcut to a dated logs directory that changes daily...what I'm working with is something like this: > > > . . where the log directory is named yyyymmdd I've created a shortcut to get me to the /log directory but was... (2 Replies)
Discussion started by: mojowtm6
2 Replies

6. UNIX for Dummies Questions & Answers

Help Creating Daily Cron Job

I need to create a cron job that will run daily to change permissions to a particular folder to 666 every 24hrs. I have no experience with crontab or cron jobs at all so if someone can guide me through this it would be a great help. The folder's example is 'www/test/htdocs' Also if you... (3 Replies)
Discussion started by: Xechno
3 Replies

7. Shell Programming and Scripting

Creating date directory and moving files into that directory

I have list of files named file_username_051208_025233.log. Here 051208 is the date and 025233 is the time.I have to run thousands of files daily.I want to put all the files depending on the date of running into a date directory.Suppose if we run files today they should put into 05:Dec:08... (3 Replies)
Discussion started by: ravi030
3 Replies

8. Shell Programming and Scripting

Zip all the files within a directory on a daily basis

I need to zip all the files within a directory on a daily basis and store them as a zip file within that directory with the date in its naming convention I have file extentions .log .lst and .out's within that directory How do i do this task zip -mqj mydir/allzip$YYMMDDDD.zip mydir/*.* ... (5 Replies)
Discussion started by: ramky79
5 Replies

9. HP-UX

HPUX printers & plotters disable on a daily basis

HI all, I've been having issues with printers and plotters disabling with no reason at all...It could happen to the same workstation once a day or once a week..There is nothing consistant..I stop and restart the spooler, only then can I re-enable the disabled printer.... If anyone is... (0 Replies)
Discussion started by: Shutdown
0 Replies
Login or Register to Ask a Question