What should I do to run a script on specific time without cron?
14,672
Solution 1
If you want to run it only once, you can use the at command : https://en.wikipedia.org/wiki/At_(command)
Example :
echo "echo \"this is a test program\" >> /tmp/xyz.log" | at 1127 apr 11
If you want to run it every day, you might need to use a loop :
#!/bin/bash
while true;
do
DATE=`date | cut -d' ' -f4`
echo $DATE
if [[ $DATE == "11:33:00" ]]
then
echo "this is a test program" >> xyz.log
sleep 1s
fi
done
Solution 2
You can use at
:
at -f "$script" 'now + 24 hours' &>/dev/null
The at command explained with an example
I found this also:
watch -n <the time> <your command or program or executable>
Related videos on Youtube
Author by
Roushan Jha
Updated on September 18, 2022Comments
-
Roushan Jha over 1 year
I want to run a script without using cron at specific time. But it is not working.
#!/bin/sh DATE=`date | cut -d' ' -f4` #Date is getting printed, if I run it manually, without any error. But file is not created at scheduled time. echo $DATE if [[ $DATE == "07:06:55" ]] then echo "this is a test program" >> xyz.log fi
-
αғsнιη about 5 yearsthis askubuntu.com/q/844533/283843 can help you?
-
muru about 5 yearsIf you want to run it daily, please explain why you can't use cron.
-
Kusalananda about 5 yearscron is the correct service to use for running a a command daily at a specific time. If not using cron, you will have to arrange for the script to re-execute itself at a particular time in the future, maybe using
at
(which is part of cron), or by sleeping (which would make the executions drift over time), and you would additionally have to set up an initial execution of the script at reboots (again, this is easy to do with cron, or with some other system service).
-
-
Roushan Jha about 5 years#!/bin/sh echo "this is a test program" >> xyz.log | at 0745 It didn't work, since I want to run it daily.
-
Joji Antony about 5 yearsOK, I have updated the answer
-
Silas Cheeseman over 4 yearsat still uses the cron facility.