Operating System - HP-UX
1752294 Members
4644 Online
108786 Solutions
New Discussion юеВ

Re: Keeping errors in a error file

 
SOLVED
Go to solution
Manuales
Super Advisor

Keeping errors in a error file

when i run a script i am getting some errors

$ prueba
find: cannot stat /prodftp
find: cannot stat /rutaprueba

i want to keep these errors in a file called errors.txt, but they are not being kept :( as follows:
$ prueba 2>>/home/errors.txt

cat /home/errors.txt
"nothing, i thought i would see find: cannot..."

what do i have to do?
9 REPLIES 9
Pete Randall
Outstanding Contributor
Solution

Re: Keeping errors in a error file

have you tried

$ prueb 1>/home/errors.txt 2>&1


Pete

Pete
Steven E. Protter
Exalted Contributor

Re: Keeping errors in a error file

Shalom,

Redirect standard error.

2>&1

Try:

2>filename

Play around a bit on the command line.


SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Arturo Galbiati
Esteemed Contributor

Re: Keeping errors in a error file

Hello,
it depend if the message you see online is written by the command (i presume find) on stdout or on stderr. type man command to understand this.
Best way is to redirect stdout and stderr in one file:
prueba 1>/home/errors.txt 2>&1
in this way all messages will be in the file.
HTH,
Art
Manuales
Super Advisor

Re: Keeping errors in a error file

Hi, ...
i have a problem...

if i run this, it works:
prueba 1>/home/errors.txt 2>&1


but if i run the shell waiting a parameter it is not working :(
prueba value1 1>/home/errors.txt 2>&1

please let me know how i can fix it
thanks.
James R. Ferguson
Acclaimed Contributor

Re: Keeping errors in a error file

Hi:

> but if i run the shell waiting a parameter it is not working :(

This suggests that your script has already re-directed STDERR (perhaps to the bit-bucket).

Look at your script for a line like:

# exec 2> /dev/null

If that exists, then that is why you see the behavior that you do.

Regards!

...JRF...
Manuales
Super Advisor

Re: Keeping errors in a error file

I think that 2>/dev/null is not the issue ...

the issue is when i add $1 = /home/user1/ is causing the issue ...

prueba /home/user1/ 1>/home/user1/errors.txt 2>&1

i donot understand why ????
Patrick Wallek
Honored Contributor

Re: Keeping errors in a error file

Can you post the 'prueba' script? The ability to analyze the script may help us to diagnose your problem.

Just the act of adding a parameter to a command should not effect redirection of stderr and stdout.
Steven E. Protter
Exalted Contributor

Re: Keeping errors in a error file

Shalom again,

The original issue was that you were trying to append output to a file that was not created. >>

If you start a script process and redirect the output to a file as shown in my first post, all output will go to the file you are choosing.

You want error output only to a file. That goal has been achieved.

Your last question expanded the question. You need to step back and get a basic understanding for how input/output works in Unix.

This link might help with that:
http://www.codecoffee.com/tipsforlinux/articles2/042.html

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Manuales
Super Advisor

Re: Keeping errors in a error file

thannk you so much
you had reason
i had 2>/dev/null into the script
i delete that and worked!!!

thank you so muchhhh