I've still got a lot of learning about cron to do, including the use of the crontab command ( for user-specific jobs ) and the /etc/crontab file, and it's associated pals: -
/etc/cron.hourly
/etc/cron.daily
/etc/cron.weekly
/etc/cron.monthly
However, as part of my uber cool bash script, I wanted to be able to automatically backup and then copy out a log file. Here we go: -
#! /bin/sh
cd /opt/IBM/TDI/V7.0/tdisol/TDI
mv logs/ibmdi.log logs/ibmdi.log-$(date +%F-%T)
/opt/IBM/TDI/V7.0/ibmdisrv -c /opt/IBM/TDI/V7.0/tdisol/TDI/PwdExpire.xml -r pwdExpiry
cp logs/ibmdi.log /tmp/ibmdi_execution-$(date +%F-%T)
cd /opt/IBM/TDI/V7.0/tdisol/TDI
mv logs/ibmdi.log logs/ibmdi.log-$(date +%F-%T)
/opt/IBM/TDI/V7.0/ibmdisrv -c /opt/IBM/TDI/V7.0/tdisol/TDI/PwdExpire.xml -r pwdExpiry
cp logs/ibmdi.log /tmp/ibmdi_execution-$(date +%F-%T)
The use of the -$(date +%F-%T) element of the filename appends the date and time, which is just what I wanted.
Sweet, cool and neat
No comments:
Post a Comment