Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
How to run a scrip if the time is matched with a time in another time zones

Currently, I am using cloud VMs to run my code and because of that I am assigned with a new VM that is in a different time zone. I want to run a bash script that runs a python script at 7:30 pm (Eastern time). From here I know how to run a bash script at a specific time, e.g., echo "ls -l" | at 07:00. From here I know how to get the current time of Eastern time, e.g., TZ=America/New_York date. Also, from here I know how to get only the time using date +%R.

I am a Python coder and tried my best to write a sudo code that shows what I am trying to accomplish as a bash script:

while true
do
Now=TZ=America/New_York date +%R
if [Now -eq 7:30pm] 
then
python3 myfile.py
done
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

As you already know how to set the at command to execute a command at the specified time, and how to convert the EST to the local time, you can just combine them:

echo "python3 myfile.py" | at $(date -d "19:30 EST" +%R)

When you invoke the at command, it always warns "commands will be executed using /bin/sh". It will matter only if we invoke a bash specific command such as:

echo "shopt -s globstar; ls **" | at ..

which will fail.

In our case, the command python3 myfile.py will run with both /bin/sh and /bin/bash then you do not worry about the warning.

date -d STRING interprets the STRING as a date/time representation and prints the converted date/time in the specified format +%R.

If you want to send the output to a file, you can say:

echo "python3 myfile.py > /path/to/a/file" | at $(date -d "19:30 EST" +%R)

In order to output to the current terminal, first identify the terminal with tty command:

$ tty
=> /dev/pts/0

Then redirect the output to the terminal with:

echo "python3 myfile.py > /dev/pts/0" | at $(date -d "19:30 EST" +%R)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda