File renames with timestamp urgent

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File renames with timestamp urgent
# 1  
Old 01-10-2008
File renames with timestamp urgent

Hi Gurus,

I am novice in unix.
I had a requirement where i should get the file when it is loaded in a folder & append time stamp to it & relace that file with timestamp.

i.e., Suppose i have a file in home/input folder as abc.xml

I want to get that file & rename it as abc.xml_11/01/08_12:33:56 & put it in home/input folder.

This script should run continously so that whenever a new file is loaded into the input folder we should rename it with timestamp.

Please provide me any sample script for this requirement

# 2  
Old 01-10-2008
I'd suggest you not use '/' in the filename as it's the unix character to delimit directories.
A popular timestamp is this:
That way round means that it will be sorted by file first, then in date order.

The date command will output the info you want, call it as follows to get the format you specified below:
date +%d\/%m\/%y_%H\:%M\:%S

To get the format I've suggested:
date +%Y%m%d.%H%M%S

# 3  
Old 01-10-2008

Thanks for ur reply
But i required a script how a file will be renamed with timestamp dynamically
The script should run continously & whenever there is a new file in the folder it should rename that file with timestamp(Any format)

# 4  
Old 01-10-2008
To make something run continuously, use a while loop with a sleep to prevent it using all your cpu:
while true
   sleep 300 # five minutes

To look for new files, I would propose that you specify to the script an expression that will math the new files but not the ones with the timestamp. That way it won't need to keep a running history.
It look like anything ending in '.xml' would do?

If so, the fragment to decide what files need to have a timestamp appended would look like this:
ls -1 *.xml 2> /dev/null | while read filename
  mv $filename ${filename}_${timestamp}

put it all together and you have a solution
# 5  
Old 01-11-2008
Thanks for ur reply

But i can't get the point what ur saying.
can u give me a sample script with the example i had said
i dont know the file name which should be append the timestamp
I want to make it as .XML with timestamp
I can't use *.xml because all ends with *.xml

secondly if we use sleep after 5 min i will get files for every one min
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

3. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

4. Shell Programming and Scripting

Lftp sftp get - script renames the local file with suffix tilde

Hi, Below script used for sftp get, #/bin/bash USER=xxx PASS=xxx HOST=xxx REMOTE_FILE=$1 LOCAL_FILE_LOC=$2 cd $LOCAL_FILE_LOC lftp sftp://$USER:$PASS@$HOST:10022 -e "get $REMOTE_FILE; bye" If file does not exist in sftp server, and file (same as remote file name) exists in local dir,... (4 Replies)
Discussion started by: vhegde1011
4 Replies

5. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

6. Shell Programming and Scripting

Urgent ...pls Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting. Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (1 Reply)
Discussion started by: robertbrown624
1 Replies

7. Shell Programming and Scripting

Identifying files with a timestamp greater than a given timestamp

I need to be able to identify files with file timestamps greater than a given timestamp. I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies

8. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

9. Shell Programming and Scripting

I need a korn shell script that renames and copies

I have 68 servers whose /etc/ntp.conf file have the wrong NTP server name and they need to be updated with a different or correct NTP server name. I am doing this on AIX Here is what I would like. and I would need a script that would rename the old /etc/ntp.conf and add a date stamp to it ... (1 Reply)
Discussion started by: jesifra
1 Replies

10. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies
Login or Register to Ask a Question