Results 1 to 2 of 2
Hello,
I wrote two bash scripts :
bash1.sh (will call bash2.sh and write logs to a daily file)
Code:
#!/bin/bash
./bash2.sh >> log`date +%d_%m_%y` 2>&1
bash2.sh (will loop indefinetly and ...
- 10-31-2009 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 1
Rotate Logs!
Hello,
I wrote two bash scripts :
bash1.sh (will call bash2.sh and write logs to a daily file)
bash2.sh (will loop indefinetly and write the current time)Code:#!/bin/bash ./bash2.sh >> log`date +%d_%m_%y` 2>&1
I'm expecting the logs to be written in a seperate file each day. But if you launch bash1.sh you will see that even if you change the system time, logs will be writte n in the same file :/Code:#!/bin/bash while [ 1 -eq 1 ] do date '+%H:%M:%S' sleep 1 done
Any idea ? any hints are welcome.
Regards,
cLaSic
- 11-03-2009 #2Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
You don't need two scripts to accomplish what you want, here's how
cat log.sh
I use MINUTE_NOW in the code so you can see how the code works without waiting till next day to see the result. Simply replace MINUTE_NOW line withCode:#!/bin/bash while true; do MINUTE_NOW=`date +%y_%m_%d_%H_%M` date '+%H:%M:%S' >> $MINUTE_NOW done
Today=`date +%y_%m_%d
and the following line to
date '+%H:%M:%S' >> $Today
to get what you want to achieve.
What >> basically does is it'll append stuff to an existing file OR create a new file then start appending if the file does not exist.


Reply With Quote