Crontab
Set the xp_crontab
"crontab.txt" variable to the file where your crontab script is.
A crontab is basically a list of commands that are executed at a given date/time.
The syntax format is the same as the *nix crontab use.
Short overview
Each line has the format: minute hour day month dayofweek /command
For any of the above values, an asterisk (*
) can be used to specify all valid values. For example, an asterisk for the month value will execute the command every month within the constraints of the other values.
A hyphen (-
) between numbers specifies a range. For example, 1-4
will expand to 1, 2, 3 and 4.
A list of values separated by commas (,
) specifies a list. For example, 3,4,6,8
indicate those four specific numbers (note that there are no spaces between the commas).
The forward slash (/
) can be used to specify step values. The value of an number can be skipped within a range by following the range with /
. For example, 0-59/2
can be used to define every other minute in the minute field. Step values can also be used with an asterisk. For instance, the value */3
can be used in the month field to run the task every third month.
Any lines that begin with a hash mark (#
) or a double slash (//
) are comments and are not processed. Additionally, an slash followed by an asterisk (/*
) indicates the start of a comment, which can be spread across multiple lines until an asterisk followed by an slash (*/
) is found.
Example:
# examples * * * * * /say this is executed every minute! * * * * 1 /say this is executed every minute but only on mondays! */5 * * * * /say this is executed every 5 minutes! 0 15 5 2 * /say this is executed on the 5th February at 15:00 o'clock! # display motd popup message every 5 minutes */5 * * * * /motd all welcome_message.txt # display greeting with hostname every half an hour 10,40 * * * * /say ^2Welcome on ^7$(sv_hostname)^7 # display g_motd command info into crontab every 5 minutes */5 * * * * /say $(g_motd) # display number of active players every 3 minutes */3 * * * * /say ^7There is currently ^2$(xp_activeClients) ^7players on the server! # randomize rotation * * * * * /execstr set xp_rotateStep $sv_serverid # change config at midnight 0 0 * * * /exec your-midnight-fun.cfg
Conditional processing
Basic if-else structures are supported in crontab files. This allows you to execute commands only if a certain condition is met. The syntax of if-else structures is the same as the one used in the Rotation System, so refer to it for further information.
Example:
// remind the users to remove the password at the end of a war if ( g_needpass ) { */10 * * * * /say ^3Remember to remove the password at the end of the war! } // say something depending on the number of clients if ( xp_activeClients >= 14 ) { */5 * * * * /say ^3Wow, server is really crowded! :D } else if ( xp_activeClients >= 8 ) { */5 * * * * /say ^3Expecting more players to come :P } else if ( xp_activeClients > 0 ) { */5 * * * * /say ^3Please don't leave the server! :( } else { */5 * * * * /say ^3To any spectator, join the game and stop wasting server slots!! :@ }