Log date
Nils Kassube
kassube at gmx.net
Thu Mar 27 20:01:54 UTC 2008
Mario Frechette wrote:
> but what I would like is to create a log file with a date in the name
> of the file that would look like ( backup.log.`date +%d%m%y`) format
> or anything near that
> I succeded to create a file named backup.log in the /home DIR
>
> but how to do that in a bash script ?
A bash script is more or less only a sequence of the commands you can run
on the command line. Therefore your filename would be made like you wrote
above. Then you have to redirect the output of your commands inside the
script to that file. That would be something like this:
#!/bin/bash
log=$(date "+backup.log.%d%m%y")
echo "Starting backup $(date)"
somecommand >>$log 2>&1
anothercommand >>$log 2>&1
echo "Backup finished $(date)" >>$log
Both the output and error output of the commands are sent to the same log
file.
Nils
More information about the ubuntu-users
mailing list