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!

Directing output of script to a file

Status
Not open for further replies.

NavinB

Technical User
Apr 11, 2001
277
GB
Hi All,
I have written a script that transfers files (using ftp commands) from one Sun server to another.I want the screen output of the executable script to be directed to a file.
I am not running this script from the shell or cron but from an application.Is there any command which does this(directing screen o/p to a file)?

Although I have done this before,I am unable to remember it.
Any help would be appreciated.
 
Hi NavinB,

How I would suggest doing this is doing two print statements in your script. I'm hoping your wrote it in perl:

#!/usr/local/bin/perl

#whatever your previous functioning was to generate the
#messaged goes here

open(FH, >outputFile.txt); #opens outputFile for
#overwriting...use >>if you want to append
print FH $yourMessage; #places text into the file
print STDOUT $yourMessage; #places text to the screen
close FH;

HTH.

Mike
 
If the output is standard error (appearing in the console) try adding the following to the cron definition

* * * * * /your.script >> /new.file 2>&1

This will direct any messages that were being printed to the console (such as failures in execution in the script, god forbid), into a new file, keeping the previous entries in that file. What I'm saying is you are creating an error log for this application, but only when running from the crontab. Ian

"IF" is not a word it's a way of life
 
Thanx to u 2 4 u'r responses....but I'm still at the crossroads.I have written the script in unix using ftp commands and secondly I am not running this thru cron.
There is an Informatica application that is running this script and so I want something to be written in the script itself that directs the output.Any suggestions??
 
Hmm,

what you can do is... use a script command. This is what you should do.

1) root# script ftp-log <--- where ftp-log can be any name

2) ./ftp_bin <---- the FTP script/program

3) When the ftp script is done... type Control-D

4) All your output should be in the ftp-log

Good luck my friend,
-David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top