PowerScale OneFS: How to Edit Crontab
Summary: Crontab is a utility used for Task Scheduling and Task Automation.
Instructions
Procedure
View the crontab files.
Run the appropriate command to view either the cluster-wide crontab file or the local node crontab file.For cluster wide:
cat /etc/crontabFor local node crontab:
cat /etc/local/crontab.local
TreeDelete, the /etc/local/crontab.local file must be created. See below for more information.
OneFS generates the
/etc/crontab file. A sample crontab entry is displayed below.
#minute hour mday month wday who command # # Nightly Health check update 0 1 * * * root /usr/bin/isi_healthcheck_update -s
The following table explains the column headers:
|
header name |
allowed value |
allowed special characters |
|---|---|---|
|
minute |
0-59 |
* / , |
|
hour |
0-23 |
* / , |
|
mday |
day of month, 1-31 |
* / , ? L W |
|
month |
1-12 |
* / , |
|
wday |
day of week (0-6, Sunday =0) |
* / , ? L W |
|
who |
permissions group, such as root |
N/A |
|
command |
commands to be run |
N/A |
This table explains the special characters:
|
special character |
definition |
|---|---|
|
* |
Asterisks are used to indicate the cron expression matches for all values of the field. So, for the month field, every month would be indicated. |
|
/ |
Slashes are used to describe increments of ranges. For example, 3-59/15 for minutes would indicate the third minute of the hour and every 15 minutes thereafter. |
|
% |
Percent signs are changed into newline characters in commands. |
|
, |
Commas are used to separate items of a list. For example, THU, FRI, SAT |
|
- |
Hyphens are used to define ranges, such as 200-205. |
|
L |
Stands for "last." Used with the day-of-week field to specify constructs such as "last Friday" which would be 5L. |
|
W |
Used for the day-of-month field, to specify a weekday nearest the given day. For example, 14W would be the nearest weekday to the 14th of the month. |
|
# |
Used for day-of-week field and followed by a number between 1 and5 to specify constructs such as the second Monday of a given month. |
|
? |
Used instead of * for leaving day-of-month or day-of-week blank |
/etc/crontab file, instructions are given on where to add entries or make changes for customization. The /etc/local/crontab.local file and the /etc/mcp/override/crontab file is user-created so it does not have instructions.
Edit the crontab files.
/etc/crontab file must NOT be edited directly.
Adding entries or modifying entries to this file must be done in the
/etc/mcp/override/crontab file for cluster wide and the /etc/local/crontab.local for local node.
Crontab entries in the
/etc/local/crontab.local file do not survive a OneFS upgrade, however, entries in the /etc/mcp/override/crontab file are preserved.
If the
/etc/local/crontab.local file does not exist, use the command below to create:
touch /etc/local/crontab.localSimilarly, if the
/etc/mcp/override/crontab file does not exist, use the command below to create:
touch /etc/mcp/override/crontab
cp /etc/local/crontab.local /etc/local/crontab.local.backup
An entry can be added directly by running the following command:
vi /etc/local/crontab.localAnd similarly:
vi /etc/mcp/override/crontabPaste or type the required entry as shown in the below example:
To add
treedelete.sh to run at 11 PM daily:
0 23 * * * root /bin/sh /ifs/data/Scripts/treedelete.sh
Note: The spaces between entries are created by using the tab key. The asterisks indicate that the cron expression matches for all values of the field. In the previous example, it would be every day of the month, every month of the year, every day of the week.
Using isi_ropc in crontab entries
Adding isi_ropc to a crontab entry runs the passed command at most once per cluster per version no matter how many nodes it is run on. Without a flag, this would allow the command to run on the node with the lowest DevID. Alternatively, adding the -s flag would run the command on a random node. An example entry is below:
# rotate log files on /ifs, too -- one node per cluster at a time
15,45 * * * * root isi_ropc newsyslog -f /etc/newsyslog.ifs.conf
Add multiple entries to a crontab file.
If a crontab file requires multiple entries from another file, append the job entry. This example where path_to_file_with_entries is the file that contains the entries to be imported:
cat /ifs/<path_to_file_with_entries> >> /etc/local/crontab.local
Verify entries in a crontab file.
Verify that the entries are appended to the crontab files:
tail /etc/local/crontab.local
tail /etc/crontabOutput similar to the following is displayed:
tail /etc/crontab # X: ---------------- # X: LOCAL # X: This section contains entries local to this node # X: only. This section is populated from the contents of # X: the file /etc/local/crontab.local if it exists. # X: ---------------- 0 23 * * * root /bin/sh /ifs/data/Scripts/treedelete.sh tail /etc/local/crontab.local 0 23 * * * root /bin/sh /ifs/data/Scripts/treedelete.sh
Revert changes to the crontab file:
These steps revert the crontab.local file to the backup version that were created in the previous section.
- Open an SSH connection on any node in the cluster and log in using the root account.
- Run the following command to copy and then rename the original backup of the
crontab.localfile:
cp /etc/local/crontab.local.backup /etc/local/crontab.local
Additional Information
Prior to OneFS 9.5, /etc/mcp/override/crontab.smbtime was used to preserve entries through upgrades.
It has since been determined that beginning with OneFS 9.5 and later use, /etc/mcp/override/crontab instead of /etc/mcp/override/crontab.smbtime.