Crontab is designed to run tasks at specified intervals, but it does not support intervals shorter than one minute. To run a script every 30 seconds, you can use a combination of crontab and a loop in your script.
Here's how to do it:
Open the crontab editor by running the command crontab -e.
Add the following line at the end of the file:
javascript
Copy code
* * * * * /path/to/script.sh >/dev/null 2>&1
This will run the script every minute.
Save and close the file.
Open your script in a text editor and add a loop that sleeps for 30 seconds between each iteration. Here's an example script:
bash
Copy code
#!/bin/bash
while true
do
# Add your script commands here
echo "Hello, world!"
sleep 30
done
This script will print "Hello, world!" every 30 seconds.
Save the script and make it executable by running the command chmod +x /path/to/script.sh.
Run the script manually by executing the command /path/to/script.sh. This will start the loop and print "Hello, world!" every 30 seconds.
The crontab job will automatically start running the script every minute. The script's loop will ensure that it runs every 30 seconds.
Comments
Post a Comment