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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:23:09+00:00 2026-05-14T00:23:09+00:00

Greetings, I need to store the filename of a log into a variable so

  • 0

Greetings,

I need to store the filename of a log into a variable so my script can perform some checks on the daily log files. These logs always have a different name because they have a timestamp in the name. Currently I’m using a hodge podged method that pipes an ls command to sed, sort, cut, and tail in order to get the name out.

CRON_LOG=$(ls -1 $LOGS_DIR/fetch_cron_{true,false}_$CRON_DATE*.log 2> /dev/null | sed 's/^[^0-9][^0-9]*\([0-9][0-9]*\).*/\1 &/' | sort -n | cut -d ' ' -f2- | tail -1 )

UPDATE:

$CRON_DATE is supplied as an argument to the script. It is the date (to the day) that the log was created on. Sometimes multiple logs will exist for the same day so I want this to get the most recent one.

Some typical filenames:
fetch_cron_false_031810090452.log
fetch_cron_true_031310090001.log
etc…

Please keep in mind that this works as is. I just think it is ugly and am trying to find a better way to pull it off.

I’m pretty sure I kluged this together from some stuff I found google a few months ago. it works now but I’m not really happy with the technique. I have some ideas about how to do this better but I have had great success on this site before and thought it might be best to refer to the stackoverflow gods first. All answers are greatly appreciated.

Thanks,
Ryan

  • 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-14T00:23:09+00:00Added an answer on May 14, 2026 at 12:23 am

    How about

    CRON_LOG=$(ls -c $LOGS_DIR/fetch_cron_*$CRON_DATE* | head -1)
    

    EDIT: You’re right bta, I should have caught that. Fixed.

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

Sidebar

Related Questions

Greetings all, I need help combining some htaccess rewrites, these crazy regular expressions screw
Greetings good people - I need some help. I have until now buildt web-pages
SO buddies, greetings. I have some password requirements I need to implement and one
Greetings all. I need to get some opinions from those outside of my work
Greetings Friends, I need some help! I've built an address finder where you enter
Greetings. Need some assistance with creating a computed column on this table: USE [ScienceWorksSummary]
Greetings everyone. I'm in need of some experiance here as how to deal with
greetings, could you please help? i need to get a variable (name) in string
Greetings, I'm in need of a way where I can execute methods on the
Greetings, I need to install oci8 drivers for PHP, but I’m having some trouble.

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.