Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to log a unix script? 2

Status
Not open for further replies.

dallen43

Programmer
Mar 15, 2005
84
US
We have several unix scripts that move and/or ftp files. Sometimes the ftp fails. These scripts run in background. We would like to log what is happening during the script.

I know we could create logs by starting the script with > or >>. However, these scripts are being called by a program and we wouldn't like to change the program. Also with parameters, we may be close to the command line maximum size.

I tried the unix command 'SCRIPT filename', but it seems to cause the script to hang.

I also know that I could put an > or >> on each command line of the script. However, I was hoping for an easier and more elegant way to create the logs.

Any suggestions?

Thanks in advace.
 
At the beginning of the script you can put:

Code:
exec > /some/log/file 2>&1

...and all subsequent output will be logged in that file.

Annihilannic.
 
Thanks, that seems to work.
Is there any downside to this command?

Thanks.
 
Not sure what you mean really? No performance impact or anything like that...

Annihilannic.
 
The only thing that happens is that stdout and stderr are redirected to a log file.

So if for some reason the calling program's functioning depends on reading those streams itself and react to their content, then you'll probably break the workings of the calling program...


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top