Posting to a log file in KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Posting to a log file in KSH
# 1  
Old 07-25-2005
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
# 2  
Old 07-26-2005
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
# 3  
Old 07-26-2005
thanks Vino.. Ill try that out..! =)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: How to write the log file simultaneously when .sql file executes by UNIX process

Hello Team- we would like to implement an approach which has to write the log file simultaneously when .sql file is executing by Unix process. At present,it is writing the log file once the process is completed. I've tested the current process with the below approaches and none of them... (1 Reply)
Discussion started by: Hima_B
1 Replies

2. Shell Programming and Scripting

ksh : need to get the 4 th line above and 2 nd below the matched pattern in the log file

I have a log file as given below 012/01/21 10:29:02 (111111) Processing Job '23_369468343464564' 2012/01/21 10:29:02 (111111) Making Job '23_369468343464564.0'... 2012/01/21 10:29:04 (111111) Jobnumber '23_369468343464564' was successful 2012/01/21 10:29:04 ... (12 Replies)
Discussion started by: rpm120
12 Replies

3. Shell Programming and Scripting

Create Log File in ksh itself

Hi, I want to create a log file for a running ksh , and the log file absolute path I want to give in ksh itself. To elaborate this - Say I have a ksh - timer.ksh and I want to create a log timer_log.log when I run, to trace this. I am aware of the fact that this can be done using redirection... (4 Replies)
Discussion started by: vinay4889
4 Replies

4. Shell Programming and Scripting

create csv in ksh from tricky log file

hi guys, trying to create a csv from a tricky log file in ksh, using 'awk '{print $1" "$14" "$15" "$16" "$17" "$18" "$19}' >> $TMP_FILE' on another set of files I have an output file with hundreds of lines in which looks like so: ABC_DEFGHI_16_JKLMNP11.20101115_095412_374.log:09:54:29.579... (3 Replies)
Discussion started by: rich@ardz
3 Replies

5. Shell Programming and Scripting

Read from Log file in Ksh

I have a log file like.. IMPORT from /dataserver/ftp/bits/mdr/mdr_data_discon.dat OF DEL ..... Number of rows read = 1376 Number of rows skipped = 0 Number of rows inserted = 1374 Number of rows updated = 0 Number of rows rejected = 2 Number of rows... (4 Replies)
Discussion started by: ramse8pc
4 Replies

6. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

7. Shell Programming and Scripting

ksh script that echo " please insert your name " and store the output to a login.log file.

Hello All Nice to meet you all here in this forum, it's my 1rst time here i'm asking about a little issue that i face i added a ksh script that echo " please insert your name " and store the output to a login.log file. the script is working fine with normal telnet but Xstart is not working... (8 Replies)
Discussion started by: islam.said
8 Replies

8. HP-UX

KSH to find a ORA error in a log file

Hi: i have writen a script that needs a finishing Pourpouse is to find a particular error in a file after we enter file name and the return msg would describe if >there is a error -> "Contact DBA" if there is no oracle error ->"No ora error found." for the same i have written a script... (6 Replies)
Discussion started by: techbravo
6 Replies

9. Shell Programming and Scripting

need help ksh scripting for log file

I have log files that contain data generated every 5 minutes. I want to extract data from the log files to another log file In each 5 minute series <log4j:event logger="VistaMonitor" timestamp="1200688175425" time="Fri Jan 18 15:29:35 EST 2008" Generated twice (I only to get the date... (2 Replies)
Discussion started by: CathyPro
2 Replies

10. Shell Programming and Scripting

How can remove -ksh.log

Hi I tried to remove the -ksh.log from my directory using rm -f -ksh.log but i cann't do it ,please help how can i do it and also would like to know when this file will be created. many thanks in advance... Regards, HAA (0 Replies)
Discussion started by: HAA
0 Replies
Login or Register to Ask a Question