Run Command After 1 Hour in Linux

How to run a script at a certain time on Linux?

Look at the following:

echo "ls -l" | at 07:00

This code line executes "ls -l" at a specific time. This is an example of executing something (a command in my example) at a specific time. "at" is the command you were really looking for. You can read the specifications here:

http://manpages.ubuntu.com/manpages/precise/en/man1/at.1posix.html
http://manpages.ubuntu.com/manpages/xenial/man1/at.1posix.html

Hope it helps!

How to execute a loop for every one hour in BASH?

Run an hourly cron job with the code to perform the checking.

17 * * * * grep -q "Build of target : PASS" main.txt && fuser -k main.txt

fuser -k is just a simple way to kill whoever is writing to main.txt on Linux; if you know the PID or are on another platform, there will be other ways to figure out which process exactly to kill.

How to execute the same loop for 1 hour in bash/ linux scripting?

Surely. Try:

#!/bin/bash
START=`date +%s`
while [ $(( $(date +%s) - 3600 )) -lt $START ]; do
....
done

date +%s shows the current time in seconds since 1970. The loop computes the current date of an hour ago and checks if it exceeds the start time.

Command to execute a script later

Take a look at the man page for at

man at

There are lots of ways you can specify the time. You can do something like:

at -f my_script.sh 23:00

Run a command at a specific time

You could try this:

at 1843 <<_EOF_
php /run/this/script.php
_EOF_

edit if what you want to do is run Firefox, try this:

at 1843 <<_EOF_
DISPLAY=:0.0 /usr/bin/firefox
_EOF_


Related Topics



Leave a reply



Submit