Results 1 to 2 of 2
I am new to scripting. I would like to join the output of daily files to a single file at the end of each month. The daily files are saved ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-14-2004 #1
- Join Date
- Sep 2004
Getting a filename to used for automation
The daily files are saved in the following format "logddmmyy.log" where dd is day, mm is month & yy is year.
Any idea how i can do it via scripts?
- 09-14-2004 #2
- Join Date
- Jul 2004
I think you should write a cron job that will be run at beginning of each month, and just cat the files from the previuos month together. To do it the script you invoke from cron might look like this:
#! /bin/bash # XXX: this uses base#value notation because month numbers smaller than 10 will # be padded with 0s, that would otherwise be interpreted as being in octal system. # Get number of the previous month and year. mon=$((10#`date +%m`)) year=`date +%y` # check if the month was january if [[ $mon -eq "0" ]] then year=$((10#$year-1)) mon=12 fi # Compact files into a single file. cat log[0-9][0-9]`printf '%02d%02d' $mon $year`.log > "log`printf '%02d' $mon`.log"
One disclaimer here: I'm not a bash guru and I've treated your question as a kind of challenge. Therefore I can't be sure whether it's the simplest or even correct solution."I don't know what I'm running from
And I don't know where I'm running to
There's something deep and strange inside of me I see"