Run Command 'At ' 5 Seconds from Now

Run command `at ` 5 seconds from now

There's no seconds in at :

man at said :

  • specification of a date must follow the specification of the time of day. You can also give times like now + count time-units,
    where the time-units can be minutes, hours, days, or weeks and
    you can tell at to run the job today by suffixing the time with today and to run the job tomorrow by suffixing the time with
    tomorrow.

So instead of at, you could use a sleep I think.

See man 1 sleep


If you'd like to run ssh user@server 'simulation/script' without waiting, simply do :

ssh user@server 'simulation/script' &

the command will run in the background.

Moreover, as Rawkode said, nohup will help there.

So finally :

nohup ssh user@server 'simulation/script' &

with nohup, you can quit your terminal and have the ssh process alive.


EDIT: if you want to run the ssh command and close the connection :

ssh user@server 'simulation/script &'

Add x seconds to the current date in Linux

You can add 5 seconds to the current time in one command using date -s "5 seconds".

The full manual regarding all of the date input formats that all of GNU coreutils accepts can be found online at https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html.

Executing a command every second while taking into account the time it takes the command to run

Use a main ticking timer and run the set_clock in the background until end of current second like this:

#!/usr/bin/env bash

set_clock() {
printf -v clock_time '%(%H:%M:%S)T'

convert \
-size "$monitor_resolution" \
"xc:$background_color" \
-font "$clock_font" \
-fill "$clock_color" \
-pointsize "$clock_size" \
-gravity 'Center' \
-draw 'text' '0,0' "$clock_time" \
"$config_dir/background.png"

feh --bg-scale "$config_dir/background.png"
}

while :; do
# Start the clock update in the background
set_clock&

# Sleep until the end of the current second
sleep .$((10**9-10#$(date +%N)))

# If there is a background child set_clock still running, kill it!
{ kill -0 $! && kill $!;} 2>/dev/null
done

Bash script that executes php file every 5 seconds

An alternative answer is to run you scripts for 12 times only, and put it in crontab

#!/bin/bash
for loop in 1 2 3 4 5 6 7 8 9 0 1 2; do
/home/user/public_html/website.com/test.php &
sleep 5
done

-- OR --

#!/bin/bash
loop=0
while [ $loop -lt 12 ]; do
/home/user/public_html/website.com/test.php &
sleep 5
loop=$(($loop+1))
done

--update--

If your goal is not to have more than one test.php, use this script: (Run it once only, do not putting it in the crontab):

#!/bin/bash

while true; do
begin=`date +%s`
/home/user/public_html/website.com/test.php
end=`date +%s`
if [ $(($end - $begin)) -lt 5 ]; then
sleep $(($begin + 5 - $end))
fi
done

Explanation: This script calls test.php, and wait for it to terminate (since it dose not have & in the end). Then it measure the time: if it's already passed 5 seconds, it call test.php right away. otherwise, it sleeps for the remaining time so that next test.php will be called at the next 5 seconds starting from the beginning of the previous test.php

Execute function after 5 seconds in Android

You can use the Handler to add some delay.Call the method displayData() as below so that it will be executed after 5 seconds.

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
displayData();
}
}, 5000);

Note : Do not use the threads like Thread.sleep(5000); because it will block your UI and and makes it irresponsive.

How to start a shell script in one minute later in linux?

Simple. you want to use 'at' to schedule your job. and 'date' to calculate your moment in the future.

Example:

echo b.sh | at now + 1 minute

or:

echo b.sh | at -t `date -v+60S "+%Y%m%d%H%M%S"`

-v+60S adds 60 seconds to current time. You can control exactly how many seconds you want to add.

But usually, when people wants one program to launch a minute after the other, they are not 100% sure it will not take more or less than a minute. that's it. b.sh could be launched before a.sh is finished. or a.sh could have finished 30 seconds earlier than "planned" and b.sh could have started faster.

I would recommend a different model. Where b.sh is launched first.
a.sh creates a temp file when it starts. execute is tasks and delete its temp file at the end.
b.sh watch for the temp file to be created, then deleted. and start its tasks.

Repeat bash command for n seconds


timetorun=30    # In seconds
stoptime=$((timetorun + $(date +%s)))
while [ $(date +%s) -lt $stoptime ]; do
something
done

Note that this will keep running the command until timetorun seconds have passed, so generally it'll actually run longer than that. For an extreme example, if timetorun is 30 seconds and the program takes 29 seconds, it'll run twice (and hence take 58 seconds).



Related Topics



Leave a reply



Submit