Script to add date×tamp on the filename. (135 Views)
Reply
Regular Advisor
Narendra Uttekar
Posts: 234
Registered: ‎12-30-2007
Message 1 of 3 (135 Views)
Accepted Solution

Script to add date×tamp on the filename.

Hi,
I want to know whether it is possible to have date&timestamp on the filename. The question over here is i can put the date&timestamp on the filename. But i want the date&timestamp on the filename as of India time. As we have servers in US in pacific timezone i.e. PDT. The script will run on this US server but when it will put the date&timestamp on the filename it should be of India time. Please can someone help me how to write the date conversion i.e. PDT to IST conversion logic in the script as below,
#!/bin/ksh
cd /SID/TEST/IN/Out
Datestamp=$(date +%Y%m%d%H%M)
file=$(ls *)
for x in $file
do
mv $x /backup/$x.$Datestamp
done

Thanks,
Narendra
Acclaimed Contributor
Dennis Handly
Posts: 25,067
Registered: ‎03-06-2006
Message 2 of 3 (135 Views)

Re: Script to add date×tamp on the filename.

>help me how to write the date conversion i.e. PDT to IST conversion

You let the computer do it:
Datestamp=$(TZ=IST-5:30 date +%Y%m%d%H%M)

You can also combine these lines to:
for x in *; do
mv $x /backup/$x.$Datestamp
done
Regular Advisor
Narendra Uttekar
Posts: 234
Registered: ‎12-30-2007
Message 3 of 3 (135 Views)

Re: Script to add date×tamp on the filename.

Thanks Dennis it works great...
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.