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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:33:53+00:00 2026-05-16T20:33:53+00:00

I have this Perl script for monitoring a folder in Linux. To continuously check

  • 0

I have this Perl script for monitoring a folder in Linux.

To continuously check for any updates to the directory, I have a while loop that sleeps for 5 minutes in-between successive loops :

while(1) {

    ...
    sleep 300;
}

Nobody on my other question suggested using cron for scheduling instead of a for loop.

This while construct, without any break looks ugly to me as compared to submitting a cronjob using crontab :

0 */5 * * * ./myscript > /dev/null 2>&1
  • Is cron the right choice? Are there any advantages of using the while loop construct?
  • Are there any better ways of doing this except the loop and cron?

Also, I’m using a 2.6.9 kernel build.

  • 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-16T20:33:53+00:00Added an answer on May 16, 2026 at 8:33 pm

    The only reasons I have ever used the while solution is if either I needed my code to be run more than once a minute or if it needed to respond immediately to an external event, neither of which appear to be the case here.

    My thinking is usually along the lines of: cron has been tested by millions and millions of people over decades so it’s at least as reliable as the code I’ve just strung together.

    Even in situations where I’ve used while, I’ve still had a cron job to restart my script in case of failure.

    My advice would be to simply use cron. That’s what it’s designed for. And, as an aside, I rarely redirect the output to /dev/null, that makes it too hard to debug. Usually I simply redirect to a file in the /tmp file system so that I can see what’s going on.

    You can append as long as you have an automated clean-up procedure and you can even write to a more private location if you’re worried about anyone seeing stuff in the output.

    The bottom line, though, is that a rare failure can’t be analysed if you’re throwing away the output. If you consider your job to be bug-free then, by all means, throw the output away but I rarely consider my scripts bug-free, just in case.

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

Sidebar

Related Questions

I have this Perl script with many defined constants of configuration files. For example:
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
I have following perl script #!/usr/bin/perl $userinput = <STDIN>; chomp ($userinput); while ( $userinput
I have this being created by my perl script. print qq| \$('textarea[name=category$row[0]]').keydown(function(event) { \$(input[value=$row[0]]).attr('checked',
I have this legacy code base (Compaq PERL) , about 1500 lines of code,
I have this code in jQuery, that I want to reimplement with the prototype
I have this Perl CGI program and I allow the user to select the
I have some Perl code (for performance analysis) first developed under Linux which now
Suppose you have a script that takes a couple of command-line arguments and dumps
Possible Duplicate: How do I fix this Perl code so that 1.1 + 2.2

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.