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 8586667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:21:55+00:00 2026-06-11T22:21:55+00:00

How do you log messages to a log file in a specific path from

  • 0

How do you log messages to a log file in a specific path from a bash script?

A naive implementation would be commands like:

echo My message >>/my/custom/path/to/my_script.log

But this probably has many disadvantages (no log rotation for example).
I could use the ‘logger’ command, but it does not support logs in custom paths as far as I know and is not easy to configure if you have lots of bash scripts that could use a custom log file.

In a scripting language like Ruby all this is quite easy: https://github.com/rudionrails/yell/wiki/101-the-datefile-adapter
I could also make my own logger command based on this ruby library and call it from my bash scripts, but I guess there is already a well known solution that provides similar behavior for shell scripts?

  • 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-11T22:21:56+00:00Added an answer on June 11, 2026 at 10:21 pm

    You can simply append text to a log file from a bash script in that way:

    echo "My message" >> /my/custom/path/to/my_script.log
    

    Rotation is handled by logrotate, you just need to add the settings to the .conf in /etc/logrotate.conf. The config is pretty self explanatory and the man page is also quite helpful, but in short if you want to rotate weekly and keep 4 weeks worth of logs in compressed format and create a new empty log as it rotates out the last, you would simply put in the .conf:

    /my/custom/path/to/my_script.log {
        rotate 4
        weekly
        create
        compress
        endscript
    }
    

    There are many other options you can check out at the man page (man logrotate) such as emailing the log files, executing commands on rotation, rotate when the files reach a certain size, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to detect lines with error messages in a log file, but not
i want to log messages from multiple classes. the problem is that currently i
I am implementing a log server in C++; that accepts log messages from a
What is the recommended way to log application-specific messages in web2py? I found the
I am writing Perl script. In that I have to read log4j.xml file from
My teams ant task pulls in developer specific info from a build.properties file by
i want to derive from std::exception to add specific information to my log files,
I am trying to implement a script that wait for a specific message in
I need to log debugging messages from the same class into different files. What
I'm searching for a way to get specific informations out of a log file.

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.