- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how do I add a date to the name of copied file...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2001 12:53 PM
тАО02-19-2001 12:53 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2001 01:10 PM
тАО02-19-2001 01:10 PM
SolutionI created a file called file.02192001 with the command:
touch file.`date +%m%d%Y`
You can use the `date +%m%d%Y` syntax in a script as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2001 01:14 PM
тАО02-19-2001 01:14 PM
Re: how do I add a date to the name of copied files
You can do something like this:
cp /var/adm/syslog/syslog.log /var/adm/syslog/syslog.log_`date +%Y%m%d_%H%M%S`
This will copy the syslog.log appending the current date and time, as for example:
...syslog_20010219_161148
that is, CCYYMMDD_HHMMSS.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2001 02:51 PM
тАО02-19-2001 02:51 PM
Re: how do I add a date to the name of copied files
set `date +'%d %b %Y'`
DAY=$1
MONTH=$2
YEAR=$3
DATE=$DAY$MONTH$YEAR
Then copy the file to the new location with the $DATE appended to the end.
cp FILE /tmp/FILE.$DATE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2001 04:54 PM
тАО02-19-2001 04:54 PM
Re: how do I add a date to the name of copied files
If you are copying a considerable number of log files, then an alternate way of organisation would be to create subdirectories for each timestate. For example, if you have the cron job running everyday at 2300 hrs, then your cron job can be:
============================================
#!/sbin/sh
DATE=`date +%Y%m%d`.`date +%H%M`
for log in /var/adm/syslog.log /var/adm/cron/log /var/adm/shutdownlog # modify your list accordingly
do
mkdir -p /archive/logs/$DATE
cp $log /archive/logs/$DATE
done
============================================
Hope this helps. Regards.
Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2001 05:02 PM
тАО02-19-2001 05:02 PM
Re: how do I add a date to the name of copied files
============================================
#!/sbin/sh
DATE=`date +%Y%m%d`.`date +%H%M`
mkdir -p /archive/logs/$DATE
for log in /var/adm/syslog.log /var/adm/cron/log /var/adm/shutdownlog # modify your list accordingly
do
cp $log /archive/logs/$DATE/
done
============================================
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2001 09:37 PM
тАО02-19-2001 09:37 PM
Re: how do I add a date to the name of copied files
If you are going to copy syslog.log to syslog.date then you will also have to either stop and start the system logger, or send it a kill -HUP so that it restarts it's logs.
Interestingly enough if you rename syslog.log, it will keep growing as the name is not used by syslogd.
This is true of more services than syslog, so read a bit before you just rename as you may not always get the results you expect.
Now, heres my idea for your task. Myself, I have done what you are attempting. First rule is to keep the date where you will understand it, and can manipulate it.
#!/bin/sh
DATE=`date +%m-%d-%y`
gives the format 02-20-01 which is much easier for ME than
#!/bin/sh
DATE=`date +%m.%d.%y`
Next, if you have many files, write your script to do them all at once. It is not a bad idea to keep your list of files in a separate file to keep maintanance easy. NOTE: I customize /etc/syslog.log, so have more than the default logs.
I.E.
>cat /usr/local/etc/rotate.txt
/var/adm/syslog/syslog.log
/var/adm/syslog/mail.log
/var/adm/syslog/daemon.log
/var/adm/syslog/critical.log
Next, a simple script
#!/bin/sh
INFILE='/usr/local/etc/rotate.txt'
DATE=`/usr/bin/date +%m-%d-%y`
for LOG in [/bin/cat $INFILE ] ; do
/bin/cp -p $LOG $LOG.$DATE
done
/sbin/init.d/sendmail stop
/sbin/init.d/sendmail start
/usr/bin/kill -HUP `cat /var/run/syslog.pid`
HP needs to build in "restart" in the script cases for init scripts....
Hope it helps!
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2001 05:51 AM
тАО02-20-2001 05:51 AM