LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Redirecting Error Output (https://www.linuxquestions.org/questions/linux-newbie-8/redirecting-error-output-915458/)

rohit_6080 11-25-2011 04:08 AM

Redirecting Error Output
 
Hi can someone please guide me on how to redirect the standard error of a script into a file?

bluesatbridge 11-25-2011 04:26 AM

script-name 2> error.log

cheers

wsteward 11-25-2011 05:31 AM

This is an example of a cron job that redirects standard output and standard error of a script to a file called archive_backup.

#Archive Backup Log
01 7 1 * * /bin/bash -v /mnt/nfs-f13-live/my_scripts/archive_backup_log >>/home/bill/archive_backup.log 2>&1

rohit_6080 11-25-2011 06:01 AM

thanxx guys it worked...i appreciate your help......

rohit_6080 11-25-2011 06:10 AM

one more question :

how can i set error redirection within the script. i do not want to write scriptname.sh 2>error.log ,i just want to run the script normally like ./scriptname & want errors to be redirected in a file.Thanxx beforehand.

wsteward 11-25-2011 08:21 AM

For the errors to be trapped within the script you must write the redirects in the script and designate the error file. That way when you run your ./scriptname the errors generated within the script will be piped to the error file.

rohit_6080 11-25-2011 09:48 AM

i've been trying to do that but i m getting syntax error each time.

wsteward 11-25-2011 02:44 PM

What is the syntax error and command you are running?


All times are GMT -5. The time now is 04:27 AM.