The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-25-2005
Registered User
 

Join Date: Jun 2005
Location: Mississauga
Posts: 12
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
Reply With Quote
Forum Sponsor
  #2  
Old 07-25-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
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
vino
Reply With Quote
  #3  
Old 07-26-2005
Registered User
 

Join Date: Jun 2005
Location: Mississauga
Posts: 12
thanks Vino.. Ill try that out..! =)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0