Bashscript. How to execute a command at a given time?

Asked

Viewed 277 times

1

I am trying to create code in Bash Scripting, and I need it to run this script in the background and run this command daily at this predetermined time and run only once. I’m having problems, because it keeps giving loops endless, example giving the command 'id'. Here is the code:

#!/bin/bash

RUNT="15:07"
exec='id'

while [ 1 ]
do
    DATE=`/bin/date +%H:%M`
    if [ $DATE. = $RUNT. ]
    then
        $exec
    fi
done &

2 answers

2

You must use cron. For this, you must edit your file crontab. Utilize:

sudo crontab -e

And insert the following content:

07 15 * * * /Path/to/your/script.sh

It will run the script every day at 3:07 pm. To understand more like the syntax cron works, you can consult this website.

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.