UNIX Log File Content - Duplication Issue


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers UNIX Log File Content - Duplication Issue
# 1  
Old 11-14-2019
UNIX Log File Content - Duplication Issue

I have a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file.

Error output is getting copied to err file and getting displayed in console too. But in log file the output and error message it getting redirected twice. I am not willing to use set -x option.

Code:
#! /bin/sh
errExit ()
{
    errMsg=`cat $1.log >> "$1".err`
    cat "$1".err | tee /dev/fd/3    
   return
}
test()
{
logfile=$1
exec 3>&1 1>>"${logfile}".log 2>&1
echo "$1"
echo "$2"
echo " "
echo "#################################################"
echo "Hi Hello,This is first function"
echo "#################################################"
if [[ -z "$2" ]];
then 
errExit $logfile
return
else
#<some Commands Here>
fi
}
test_1()
{
logfile=$1
exec 3>&1 1>>"${logfile}".log 2>&1
echo "$1"
echo "$2"
echo " "
echo "#################################################"
echo "Hi Hello,This is second function"
echo "#################################################"
if [[ -z "$2" ]];
then 
errExit $logfile
return
else
#<some Commands Here>
fi
}

# 2  
Old 11-15-2019
I see that you append the output to $logfile. Does it already exist when you run this?

Perhaps adding `date` to the Hi Hello echo statement might show you if this is from a previous run.

What output do you actually have from this?



Kind regards,
Robin
# 3  
Old 11-15-2019
Closing thread as this looks like homework, but mostly because once again you posted twice knowing its against our rules and for that reason you will receive yet again a infraction...
Please continue here:
Print Error in Console and both Error &amp; Output in Log file - UNIX
This User Gave Thanks to vbe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check specific content from log file

Hi all, i have a logfile which is continuously being updated. I have built a script to check for a specific content and if it is found, it sends a string into a file. Here's the current script: #!/bin/bash logfile=/opt/jboss-eap-6.3/standalone/log/server.log tail -fn0 $logfile | \... (7 Replies)
Discussion started by: nms
7 Replies

2. Shell Programming and Scripting

How to Modify a file content in UNIX and sort for only required fields ?

I have the below contents in a file after making the below curl call curl ... | grep -E "state|Rno" | paste -sd',\n' | grep "Disconnected" > test "state" : "Disconnected",, "Rno" : "5554f1d2" "state" : "Disconnected",, "Rno" : "10587563" "state" : "Disconnected",, "Rno" :... (2 Replies)
Discussion started by: Vaibhav H
2 Replies

3. Shell Programming and Scripting

Create archive and nil the content of log file using script

Plese help I need a urgent requirement. Ex: test.log requirement : using shell script I need to archive the log file and nil and the content of (test.log) file to 0 kb and then in the archive folder log files are name to test.tar test1.tar test2.tar EX: /home/abc/ test.log ... (1 Reply)
Discussion started by: johney1981
1 Replies

4. Shell Programming and Scripting

Need help to pick the content from Log file

Hi All, Below is my requirement. I need to pick the certain content from log file and display. for example log file consist of following information project1 project2 project3 filename1, size1, ower1, datecreated filename2, size2, ower2, datecreated filename3, size3, ower3,... (6 Replies)
Discussion started by: bbc17484
6 Replies

5. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

6. Shell Programming and Scripting

How to copy mail content in a file in Unix

Hi Guys I want to write a script which search mail with subject line and after that I want the mail content in a file please help guys. Thanks Atul Singh (3 Replies)
Discussion started by: atul9806
3 Replies

7. UNIX for Dummies Questions & Answers

Display the content of the unix file

cat is the normal unix command to display the content of a file. Is there any program to display the content of the file. If there is, then can you send me the code. (5 Replies)
Discussion started by: vedanjalig
5 Replies

8. UNIX for Advanced & Expert Users

File Descriptor redirection and duplication

i have many questions concerning the FD. it was stated that "to redirect Error to output std, you have to write the following code" # ls -alt FileNotThere File > logfile 2>&1 # cat logfile ls: cannot access FileNotThere: No such file or directory -rw-r--r-- 1 root root 0 2010-02-26... (9 Replies)
Discussion started by: ahmad.zuhd
9 Replies

9. Shell Programming and Scripting

File Duplication Script?

I have a file, let's say 1.jpg, and I have a text file that contains a list of filenames I would like to duplicate 1.jpg as (i.e., 2.jpg, 3.jpg, 4.jpg, etc.). The filenames that I want to create are all on separate lines, one per line. I'm sure there's a simple solution, but I'm not claiming to... (7 Replies)
Discussion started by: futurestar
7 Replies

10. Windows & DOS: Issues & Discussions

File Duplication

hi all how to find the file duplication in a windows 2000 server as usual replies are sincerely appreciated. thanks raguram R (3 Replies)
Discussion started by: raguramtgr
3 Replies
Login or Register to Ask a Question