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
The standard way to run a bash script or other command periodically on linux operating systems is using cron. First, run the following command:
bash$ crontab -eThis will open the crontab file for the current user in your system's default command line editor. This file specifies what commands to run and when to run them. To add your script to your crontab, add a line in the following format:
crontab<minute> <hour> <day of month> <month> <day of week> /path/to/scriptEach of the fields above represents the time at which the command should run as a number, starting from 0. To run the command for all of one of these intervals, use
*in place of a number. You can additionally run a command everynof a particular interval by writing*/nfor that field. - User
Thanks! Is there a way to schedule irregular intervals with crontab? Like running something every three days? Or skipping months? Running once a week one month and then twice a week the next month?
If that can be done with crontab, please write the line or lines that are needed. If that has to be done with a script that gets called by crontab, please write both the crontab line(s) and the script.
- Assistant
Sure! Here's a an example crontab line that runs a command every 3 days at midnight:
code0 0 */3 * * <command>Here's another example runs at noon on the first day of each month, skipping April through August.
code# '-' specifies an inlcusive range of times, while ',' specifies joining two ranges or numbers 0 12 0 0-2,9-11 * <command> # Can also be written as 0 12 0 jan-mar,sep-dec * <command>A simple way to run a command once a week one month and twice a week another month is to add two entries for a command:
code# Run at noon on Sunday in January... 0 12 * jan sun <command> # ... and at noon on Sunday and Wednesday in February 0 12 * feb sun,wed <command>
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 →