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

160
Views
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 answers
Answer question

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 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!