I want to run a script without using cron at specific time. But it is not working.


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" ]]
echo "this is a test program" >> xyz.log

  • this askubuntu.com/q/844533/283843 can help you? – αғsнιη Apr 11 at 5:59
  • 2
    If you want to run it daily, please explain why you can't use cron. – muru Apr 11 at 6:06
  • cron 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). – Kusalananda Apr 11 at 6:46

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>

The watch command on the web


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 :


while true;
    DATE=`date | cut -d' ' -f4`
    echo $DATE
    if [[ $DATE == "11:33:00" ]]
            echo "this is a test program" >> xyz.log
            sleep 1s
  • #!/bin/sh echo "this is a test program" >> xyz.log | at 0745 It didn't work, since I want to run it daily. – Roushan J. Apr 11 at 5:45
  • OK, I have updated the answer – simula67 Apr 11 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.