Unix cmd line: capture return code
Posted on 2010-09-23
This can't be very hard, yet I could not put my finger on it.
On several (>100) servers I need to check if a file is present.
A cmd to check that out can be done in an automated way (through TWS, job scheduling software) but I don't want to have a script for it put on each system.
Therefore a cmd is execute on each server, the output of which is written in a "job log". So far no problem.
What I need to see in that joblog is the return code.
If I work with a [test] cmd I would need to see a 0 if exist, a 1 if not.
How would such a cmd look like?
test filename | echo $?
returns always a 0 whether the file is there or not.
Related: I don''t think I can parse a script into a cmd line, can I? If so that woud solve my problem too...
Thanks for your help!