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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write to log files 1

Status
Not open for further replies.

N45333M

Programmer
Apr 27, 2005
2
US
have a ksh script that moves new files..
i want to able to write the output to a log file.
can you help. i thought this would work, only thing i can it to write is the date to the logs
#!/bin/ksh

1
2
3

txt >> ${OUTPUT_LOG}
 
man date

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The question doesn't really make sense... can you try asking again please?

Annihilannic.
 
ok maybe i was vague. how do i get my script to run output to logfiles.
 
You could use the following construct, in your script:

echo "Output text to logfile" >> /path/to/logfile

Which could be improved as:

OUTPUT_FILE=/path/to/logfile

echo "The log file is ${OUTPUT_FILE}" >> ${OUTPUT_FILE}


I hope that helps.

Mike
 
Don't forget >> appends to an existing file. Use > to create a new file or overwrite and existing file.
 
look into the "tee" command too. That will allow writing to more than one location at the same time. (man tee)

Add a little color to your PUTTY terminal: faq52-6627
 
Alternatively, when you run the script you can redirect all output to a file:

[tt]/path/to/scriptname > /path/to/scriptname.out 2>&1[/tt]

Or for convenience, to save typing if the script is normally run manually, you can add a line near the beginning of the script, e.g.:

[tt]#!/bin/ksh

exec > /path/to/scriptname.out 2>&1

# rest of script...[/tt]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top