Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
Shell infinite loop to execute at specific time

I have access to a Linux CentOS box. (I can't use crontab sadly)

When I need to run a task everyday I have just created a infinite loop with a sleep. (it runs, sleeps ~24 hours and then runs again)

#!/bin/sh


while :
do
    /home/sas_api_emailer.sh |& tee first_sas_api

sleep 1438m
done

Recently I have a task that I need to run at a specific time everyday 6:00 am (I can't use crontab)

How can I create an infinite loop that will only execute @ 6:00 am?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Check the time in the loop, and then sleep for a minute if it's not the time you want.

while :
do
    if [ $(date '+%H%M') = '0600' ]
    then /home/sas_api_emailer.sh |& tee first_sas_api
    fi
    sleep 60
done
over 4 years ago · Santiago Trujillo Report

0

You have (at least!) three choices:

  1. cron

    This is hands-down the best choice. Unfortunately, you say it's not an option for you. Drag :(

  2. at

    at and batch read commands from standard input or a specified file which are to be executed at a later time.

    For example: at -f myjob noon

    Here is more information about at: http://www.thegeekstuff.com/2010/06/at-atq-atrm-batch-command-examples/

  3. Write a "polling" or "while loop" script. For example:

    while true
      # Compute wait time
      sleep wait_time
      # do something
    done
    

    Here are some good ideas for "compute wait time": Bash: Sleep until a specific time/date

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!