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

  • Home
  • SEARCH
  • 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 6351031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:55:28+00:00 2026-05-24T21:55:28+00:00

A bash script is run from cron, stderr is redirected to a logfile, this

  • 0

A bash script is run from cron, stderr is redirected to a logfile, this all works fine.
The code is:

*/10 5-22 * * * /opt/scripts/sql_fetch 2>> /opt/scripts/logfile.txt

I want to prepend the date to every line in the log file, this does not work, the code is:

*/10 5-22 * * * /opt/scripts/sql_fetch 2>> ( /opt/scripts/predate.sh >> /opt/scripts/logfile.txt )

The predate.sh script looks as follows:

#!/bin/bash
while read line ; do
    echo "$(date): ${line}"
done

So the second bit of code doesn’t work, could someone shed some light?
Thanks.

  • 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-05-24T21:55:29+00:00Added an answer on May 24, 2026 at 9:55 pm

    I have a small script cronlog.sh to do this. The script code

    #!/bin/sh
    echo "[`date`] Start executing $1"
    $@ 2>&1 | sed -e "s/\(.*\)/[`date`] \1/"
    echo "[`date`] End executing $1"
    

    Then you could do

    cronlog.sh /opt/scripts/sql_fetch >> your_log_file
    

    Example result

    cronlog.sh echo 'hello world!'
    
    [Mon Aug 22 04:46:03 CDT 2011] Start executing echo
    [Mon Aug 22 04:46:03 CDT 2011] helloworld!
    [Mon Aug 22 04:46:03 CDT 2011] End executing echo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bash script I want to run every 5 minutes from cron...
I have done a a bash script which run php script. It works fine
I have a script that I'm trying to run from cron. When I run
I have a bash script that is invoked from a cron job which has
I previously used to copy Python/Perl scripts to access from my bash script. Duplication
I have this bash script on the server that runs every hour, via cron.
In xcode 3, using a bash script, I could run xcode from the command
I want to run a program from inside a bash script, such that it
I am using a bash script to launch a ruby script. this works very
I have a bash backup script run as root (cron) that delegates certain tasks

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.