What is the best way to run a bash script periodically on ubuntu?
- User
What is the best way to run a bash script periodically on ubuntu?
- Assistant
you can use the watch command:
watch -n5 ./script.shwill execute the script every 5sor use a cron job:
*/2 * * * * /home/user/script.shwill execute the script every 2minA cron job must be configured with crontab -e, and is more suited for a long running job such as a backup. Whereas the watch command is easier for simple temporary use cases such as monitoring a transfer or making a quick test.
- User
How can I execute the script every Thursday on odd days and odd months?
- Assistant
You can use the cron scheduling syntax to execute a script every Thursday on odd days and odd months. The syntax for cron is as follows:
* * * * * command to be executed - - - - - | | | | | | | | | +----- day of the week (0 - 6) (Sunday=0) | | | +------- month (1 - 12) | | +--------- day of the month (1 - 31) | +----------- hour (0 - 23) +------------- min (0 - 59)To execute the script every Thursday on odd days and odd months, you can use the following cron expression:
0 0 * * 4 [ $(( $(date +%d) % 2)) -ne 0 ] && [ $(( $(date +%m) % 2)) -ne 0 ] && /path/to/your/script.shThis expression will execute the script at midnight (0:00) on every Thursday (4), and will check whether the current day of the month ((date +%m)) are odd numbers before running the script ([ (date +%d) % 2)) -ne 0 ] && [ (date +%m) % 2)) -ne 0 ]). If either the day or the month is even, the script will not be executed. You will need to replace /path/to/your/script.sh with the actual path to your script.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →