[WBEL-users] Writing a script in bash

Erik Williamson erik at cpsc.ucalgary.ca
Tue May 24 10:30:56 CDT 2005


Hi,

Try this:

./backup >> /var/log/backup.log 2>&1

The part that I added on basically says "send error messages (the '2') 
to the same place you send standard output messages (the '1', which in 
this case, you've redirected to /var/log/backup.log with the '>>')"

For a more detailed explanation, see here:
http://www.tldp.org/LDP/abs/html/io-redirection.html

Hope This Helps,
Erik.

Jean Lee wrote:
> Hello,
> 
> I am not sure this is the correct list to ask this question but I don't 
> know where to ask it. If somebody knows, please redirect me.
> 
> I am writing a backup script using bash and I want to log the output in 
> "/var/log/backup.log"
> The saved files have to be stored on an external hard drive on "/dev/sda1"
> 
> the script works and contains :
> 
>    mount /dev/sda1
>    ....
>    cp /usr/Users/FolderToBackup /mnt/usb0/
>    ....
>    umount /dev/sda1
> 
> On the terminal command line, I type :
> 
>    ./backup >> /var/log/backup.log
> 
> nothing is returned on the terminal and all the output is redirected to 
> "/var/log/backup.log".
> It works always fine.
> 
> Now, if the external hard drive is not present on "/dev/sda1" and I type :
>    ./backup >> /var/log/backup.log
> 
> On the terminal, I have :
>    /dev/sda1 : Input/Output error
>    mount : you must specify the filesystem type
>    umount : /dev/sda1 not mounted
> 
> My questions are :
> 
> Why are these lines not logged in "/var/log/backup.log" ?
> Is there a way to redirect it ?
> 
> Or perhaps that I made a mistake in my script architecture (This is my 
> first script) :
> I want to test an external  hard drive availability  on "/dev/sda1" by 
> doing a grep in "/var/log/backup.log". Does anybody knows a better way 
> to do it ? (better than logging the output of "mount" in 
> "/var/log/backup.log" and then testing it with a grep)
> 
> Thank you for any answer,
> 
> Jean LEE
> 
> 
> 
> _______________________________________________
> Whitebox-users mailing list
> Whitebox-users at beau.org
> http://beau.org/mailman/listinfo/whitebox-users

-- 
e r i k   w i l l i a m s o n                     erik at cpsc.ucalgary.ca
  system admin . department of computer science . university of calgary



More information about the Whitebox-users mailing list