![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Posting a file from Unix to URl | PoojaM | UNIX for Advanced & Expert Users | 1 | 05-06-2008 02:57 AM |
| File posting through FTP connection | komalkumar | IP Networking | 6 | 04-08-2008 04:10 AM |
| posting a file | sannu | Shell Programming and Scripting | 1 | 09-06-2004 03:06 AM |
| posting requirements | Optimus_P | Post Here to Contact Site Administrators and Moderators | 1 | 06-10-2003 11:27 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Posting to a log file in KSH
Hello,
I am writing this script in ksh (consisting of various functions such as -> read_file, write_file, pront_output and initialise) which basically process input files based on the parameters it contains. My task now is to write any error conditions trapped by any of the function above to a log file. What is the easiest way that it can be done..? logfile_name=$logfile_dir/create_vobs_`date +%d%b%y_%T`_$$.log ....and this is what I want it to do.... function read_structure_file { # -------------------------------------------------------------------------------------------------------- # Purpose: A compound array (STRUCTURE_FILE) is read in and based on the parameters, data is stored in # successive arrays # No arguments # -------------------------------------------------------------------------------------------------------- struc_file=/develop/sid/si.dat if [ ! -f $struc_file ] then echo "$logfile_dir/create_vobs_Structure file doesn't exist`date +%d%b%y_%T`_$$.log" exit 1 else exec < $struc_file ......blah blah Write the one highlighted above to the log created everytime the program is run. Thanks in advance. Sid |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Why dont you abstract out the error logging as another function. This function will take in as parameter the exact error message i.e. Structure file doesn't exist.
How about this ? I have retained your code. And removed the process-id $$ construct. Code:
function errorLog()
{
# Get the exact error message and post it into
# the logfile along with date.
ERROR="$@"
echo "$logfile_dir/create_vobs_$ERROR $(date +%d%b%y_%T)" >> $logfile_dir.log
}
function read_structure_file
{
# --------------------------------------------------------------------------
# Purpose: A compound array (STRUCTURE_FILE) is read in and based on the
# parameters, data is stored in
# successive arrays
# No arguments
# --------------------------------------------------------------------------
struc_file=/develop/sid/si.dat
if [ ! ?f $struc_file ]
then
errorLog "Structure file doesn't exist"
exit 1
else
exec < $struc_file
|
|
#3
|
|||
|
|||
|
thanks Vino.. Ill try that out..! =)
|
|||
| Google The UNIX and Linux Forums |