Sponsored Content
Top Forums UNIX for Beginners Questions & Answers UNIX Log File Content - Duplication Issue Post 303041106 by sarathy_a35 on Thursday 14th of November 2019 10:21:53 PM
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
}

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
line(1) 						      General Commands Manual							   line(1)

NAME
line - Reads one line from standard input SYNOPSIS
line STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: line: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None DESCRIPTION
The line command copies one line, up to and including a newline, from standard input and writes it to standard output. Use this command within a shell command file to read from your terminal. The line command always writes at least a newline character. NOTES
The line utility has no internationalization features and is marked LEGACY in XCU Issue 5. Use the read utility instead. EXIT STATUS
Success. End-of-File. EXAMPLES
To read a line from the keyboard and append it to a file, enter: echo 'Enter comments for the log:' echo ': c' line >>log This shell procedure displays the message: Enter comments for the log: It then reads a line of text from the keyboard and adds it to the end of the file log. The echo ': c' command displays a : (colon) prompt. See the echo command for information about the c escape sequence. SEE ALSO
Commands: echo(1), ksh(1), read(1), Bourne shell sh(1b), POSIX shell sh(1p) Functions: read(2) Standards: standards(5) line(1)
All times are GMT -4. The time now is 05:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy