David Coulson on 31 Aug 2011 09:21:43 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Bash I/O redirection


You can just do this:

logfile=/path/to/logs/script.$$.log
exec>  $logfile 2>&1


That will redirect stderr and stdout into the log file.

David

On 8/31/11 11:33 AM, Julien Vehent wrote:
Hey Guys,

I have this bash script that does an oracle backup (launched via crontab), and I'd like to redirect the output of the script to a file. The classic ways to do it would be:
   * use a wrapper script (that requires an additional script...)
   * call the script with '>' in the cron line (make my cron line ugly)
   * inside the script, put a ">>" after each command (berk !)

My question is: would there be a way to put a global redirection at the beginning of the script ?
something like
   "1 > /tmp/log.txt"
and then have all the subsequent commands go to the log file ?


Thanks,
Julien

___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug