Re: Log date



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

--
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users



Relevant Pages

  • Re: Cmd returns ctrl to bash b4 completion, how to get PID
    ... I would like to issue commands from a bash script. ... I would like to capture the PID of such a launched command so ... launched Xwin, which did not put it in the background. ...
    (comp.unix.shell)
  • Re: Log date
    ... Nils Kassube a écrit: ... of the file that would look like format ... A bash script is more or less only a sequence of the commands you can run ...
    (Ubuntu)
  • Re: OT: Scripting humour
    ... So a bash script written for Linux will work on OSX? ... It has bash - but not Gnome, which is required for the zenity command. ... Most of the basic gnu commands are there with the bash shell, ...
    (Ubuntu)
  • Re: Days to Month file
    ... > Then the following should help but not all commands may work in your shell. ... bash script introduction documentation ...
    (comp.unix.programmer)
  • Re: sed command line vs bash script problem
    ... not from a bash script. ... things in the pipe that look like commands? ... Is the problem the characters in the filename or in the contents ...
    (comp.os.linux.misc)