script to rename files with current date and copy it.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers script to rename files with current date and copy it.
# 1  
Old 04-26-2007
script to rename files with current date and copy it.

I have few webservers logs like access.log. which would be growing everyday.
what i do everyday is, take the backup of access.log as access.log_(currentdate) and nullify the access.log.

So thought of writing a script... but stuck up in middle.

My requirement: to take the backup and nullify the log after it reaches 500 mb

1) i am able to find the logs which are more than 500mb using this command

find . -size +1000000 -exec ls -l {} \; > /tmp/logs

2) How do i pickup the files mentioned in /tmp/logs and take the backup with currentdate ? i need a command to backup (copy) with current date in same directory .

Thanks
logic0
# 2  
Old 04-26-2007
Code:
dt=$( date +%Y%M%d )
cd /tmp
while read file
do
    cp ${file} "${file}_${dt}"
    : > ${file}
done < log

# 3  
Old 04-26-2007
lamme question

output of /tmp/log is like
./access.log
./logs/access.log

in command i see using

while read file

file is the /tmp/log ?
# 4  
Old 04-26-2007
Quote:
Originally Posted by logic0
output of /tmp/log is like
./access.log
./logs/access.log

in command i see using

while read file

file is the /tmp/log ?
Replace dot by actual path
Code:
find <path_to_directory> -size +1000000 -exec ls -l {} \; > /tmp/logs

Code:
dt=$( date +%Y%M%d )
while read file
do
    cp ${file} "${file}_${dt}"
    : > ${file}
done < /tmp/logs

# 5  
Old 04-27-2007
thanks anbu

thanks anbu.. it worked kool !!! cheers
# 6  
Old 04-30-2007
question

dt=$( date +%Y%M%d )
while read file
do
cp ${file} "${file}_${dt}"
: > ${file} --I did not undestsand this line, what does this line
done < /tmp/logs

Can u explain, what does that line.
# 7  
Old 05-01-2007
Quote:
Originally Posted by Birasing
dt=$( date +%Y%M%d )
while read file
do
cp ${file} "${file}_${dt}"
: > ${file} --I did not undestsand this line, what does this line
done < /tmp/logs

Can u explain, what does that line.
Code:
: > ${file}

This line clears the text in ${file}
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

2. Shell Programming and Scripting

Oop to copy and rename files through SQL Statement in shell Script

#!/bin/sh sqlplus -s "/ as sysdba" << EOF SET HEADING OFF SET FEEDBACK OFF Select pt.user_concurrent_program_name , OUTFILE_NAME FROm apps.fnd_concurrent_programs_tl pt, apps.fnd_concurrent_requests f where pt.concurrent_program_id = f.concurrent_program_id and pt.application_id =... (1 Reply)
Discussion started by: usman_oracle
1 Replies

3. Shell Programming and Scripting

Linux Script to copy and rename files through SQL statement

Hi, I require help to complete below requirement through Linux Script. I have a SQL query which shows two columns as output. One is Report Name and other is report path. Query return multiple rows. below is the output. Report Name Cotton Stock Report (Net Weight)- Customized Output... (3 Replies)
Discussion started by: usman_oracle
3 Replies

4. Shell Programming and Scripting

how to copy current date files to another dir

i have directory /abcd and i want to copy all today date files in /xyz directory. i am able to see the files by using below command but not able to understand copy. find . -mtime -1 -type f -exec ls -l {} \; (2 Replies)
Discussion started by: learnbash
2 Replies

5. UNIX for Dummies Questions & Answers

Script to copy files from a certain date

I need to copy files from a directory that has a lot of files in it. However I only want to copy them from a certain date. My thoughts so far are to use ls -l and to pipe this into awk and print out tokens 6 (month)and 7 (day). $ ls -l -rw-r--r-- 1 prodqual tst 681883 Jun 12... (2 Replies)
Discussion started by: millsy5
2 Replies

6. Shell Programming and Scripting

Help with script to copy/rename files, then delete by date

Hi All, I am new to scripting and am looking for some assistance setting up a script. Basically I need the script to scan a folder for the newest files and make a copy of those files, adding a month to the date stamp. I also need this script to delete the previously copied files to save space.... (4 Replies)
Discussion started by: Lucid13
4 Replies

7. Shell Programming and Scripting

Shell Script to compare files, check current date and count

Hello - I have written the following basic shell script to count files, compare files and look for a particular strings in a file. Problem 1: How do I define more than 1 file location? #!/bin/bash #this is a test script FILES=$(ls /home/student/bin/dir1, home/student/bin/dir2)... (0 Replies)
Discussion started by: DallasT
0 Replies

8. Shell Programming and Scripting

Script to copy log files with today's date

I am a newbie to scripting. I need a korn shell script to copy log files of current day to archive folder and rename with current days date stamp. I would really appreciate your help. File structure is as follows. Everyday files get overwritten, so I need copy to a archive directory and... (3 Replies)
Discussion started by: mdncan
3 Replies

9. Shell Programming and Scripting

copy/rename file as date() unix/shell

File.jpg I want to copy and rename this as 2008-12-02.jpg I tried this copy File.jpg date '%y-%m-%d-%H:%M:%S'.jpg This doesnt work.... what do i do? (1 Reply)
Discussion started by: hdogg
1 Replies
Login or Register to Ask a Question