Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9192871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:02:05+00:00 2026-06-17T21:02:05+00:00

I want to forward all my stdout and errout to a logger script that

  • 0

I want to forward all my stdout and errout to a logger script that log them with some extra info such as dateTime and the script caused the error. After some googling I finally wrote my bash program in this manner:
I added these two lines in my main script:

exec  1> >(xargs ./doLog)
exec  2> >(xargs ./doLog)

The ./doLog is somehow like this:

if [ -n $1 ]
then
    echo -n "Jaky: `date`: $@ " >> $Log_File
fi

So it takes every input from 1> and 2> and echo it to my log file.
The problem is that for some reason I need to convert the doLog script to a function that perform the same result. but I don’t know how to pass the input of exec 1 and 2 to a function. I tried xargs and other file descriptor but I couldn’t get the result.

Another problem is that the log passed to the doLog doesn’t contain end of line character, So all output appear connected to each other.
Some help please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:02:07+00:00Added an answer on June 17, 2026 at 9:02 pm

    You can’t use xargs for functions. That’s why you need to read tha data in the function direct from stdin. Do it using read. There is a small example below.

    Function:

    dolog()
    {
      while read log_entry
      do
       echo "Jaky: `date`: $log_entry " >> $Log_File 
      done
    }
    

    Usage:

    your-command | dolog
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to copy the interface of a groovy script exactly but forward all
Is there any straight forward way to do that? I want to give an
I simply want to disable Restlet's logging to stdout/stderr in my project and forward
How can I use common forward for all actions. I mean I don't want
Let's say I want to forward all requests at /js/* to a JavaScript controller
I am new to metafunctions. I want to write a function that replaces all
I want to capture all tcp packets on port 80 that are going to
I've been reading some on forward declarations, including in this forum. They all say
I have the following page that works as I want it to, all the
I want to forward declare a static member function of a class in another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.