Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda