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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:24:24+00:00 2026-05-11T20:24:24+00:00

I am writing a script to capture disk usage on a system (yes, I

  • 0

I am writing a script to capture disk usage on a system (yes, I know there is software that can do this). For database reporting purposes, I want the interval between data points to be as equal as possible. For example, if I am polling disk usage every 10 minutes, I want every data point to be YYYY-MM-DD HH:[0-5]0:00. If I’m am polling every 5 minutes, it would be YYYY-MM-DD HH:[0-5][05]:00.

If I have a ksh script (or even a Perl script) to capture the disk usage, how can I let the script come active and wait for the next “Poll time” before taking a snapshot, and then sleep for the correct number of seconds until the next “Poll time”. If I am polling every 5 minutes, and it is 11:42:00, then I want to sleep for 180 seconds so it will take a snapshot at 11:45:00 – and then sleep for 5 minutes so it will take another snapshot at 11:50:00.

I wrote a way that works if my poll time is every 10 minutes, but if I change the poll time to a different number, it doesn’t work. I would like it to be flexible on the poll time.

I prefer to do this in shell script, but if it is way too much code, Perl would be fine too.

Any ideas on how to accomplish this?

Thanks in advance!

Brian

EDIT: Wow – I left out a pretty important part – that cron is disabled, so I will not be able to use cron for this task. I am very sorry to all the people who gave that as an answer, because yes, that is the perfect way to do what I wanted, if I could use cron.

I will be using our scheduler to kick off my script right before midnight every day, and I want the script to handle running at the exact “poll times”, sleeping in between, and exiting at midnight.

Again, I’m very sorry for not clarifying on crontabs.

  • 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-11T20:24:25+00:00Added an answer on May 11, 2026 at 8:24 pm

    If I were doing this, I would use the system scheduler (cron or something else) to schedule my program to run every 180 seconds.

    EDIT: I might have misunderstood your request. Are you looking more for something along the following lines? (I suspect there is a bug or two here):

    ANOTHER EDIT: Remove dependency on Time::Local (but now I suspect more bugs 😉

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use POSIX qw( strftime );
    
    my $mins = 5;
    
    while ( 1 ) {
        my ($this_sec, $this_min) = (localtime)[0 .. 1];
    
        my $next_min = $mins * ( 1 + int( $this_min / $mins ) );
        my $to_sleep = 60 * int( $next_min - $this_min - 1 )
                     + 60 - $this_sec;
    
        warn strftime('%Y:%m:%d %H:%M:%S - ', localtime),
            "Sleeping '$to_sleep' seconds\n";
    
        sleep $to_sleep;
    }
    
    __END__
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 162k
  • Answers 162k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't do that since <a> is an inline element,… May 12, 2026 at 12:05 pm
  • Editorial Team
    Editorial Team added an answer Search terms: comet, long-polling These are mostly used in an… May 12, 2026 at 12:05 pm
  • Editorial Team
    Editorial Team added an answer John Fishers approach looks good. But if you want to… May 12, 2026 at 12:05 pm

Related Questions

I am writing a Perl module, and I am using carp to throw a
I am writing a Perl script that is searching for a term in large
Refering to a previously asked question , I would like to know how to
I am making use of AJAX on my site and I would like to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.