Crontab

From EventScripts Community Encyclopedia

Contents

Overview

Syntax: crontab <M H d m w> <"command"> [jobname] [overwrite?]

Note: Command parameters are described inside the < and > characters. Optional parameters are contained within [ and ] characters.

Description

Creates cronjobs for the HL2 engine similar to the Un*x crontab program.


Note: It doesn't expand server variables. Prefix the command with es to expand variables (es crontab).

Parameters

  • M H d m w - Minute, Hour, Day of the month, Month of the year, and Day of the week the job should be executed.
    • minutes - 0-59
    • hours - 0-23
    • day of the month - 1-31
    • month of the year - 1-12
    • day of the week - 0-6, 0 is Sunday
 SHORTCUTS
 Entry       Description             Equivalent To
--------------------------------------------------
 #yearly     Run once a year         0 0 1 1 *
 #annually   (same as #yearly)       0 0 1 1 *
 #monthly    Run once a month        0 0 1 * *
 #weekly     Run once a week         0 0 * * 0
 #daily      Run once a day          0 0 * * *
 #midnight   (same as #daily)        0 0 * * *
 #hourly     Run once an hour        0 * * * *
==================================================
Example:
crontab #daily "es_msg The server is restarting in 1 minute!; es_xdelayed 60 _restart"
  • "command" - The command you want to execute. Must be enclosed in quotes.
  • jobname - optional jobname that you want assigned to this job
  • overwrite bit - 0 is no, 1 is yes, Tells crontab to overwrite the command if one already exists with the jobname you supplied. If this is not given, it defaults to 0.
  • crontab run <jobname> - Will execute the job and update the timestamp in the database.
  • crontab del <jobname> - Will delete the job.
  • crontab search <type> <jobname or command> - Searches the database for <type> job or command that matches the jobname or command given. If a match is found, it is output to the server log.
  • crontab backup - Stores a copy of the current cronjob database. This is recommended before installing new scripts.
  • crontab restore - Restores the cronjob database from a previous backup.


Examples

Sample commands you can add to your scripts or enter into your server's console.

// Notes:
//   Use asterisks to denote all available times.
//   Use commas to separate different values within the same time denomination.
//   Use dashes to include all options between two numbers in the same time denomination.
//   Use diagonals to divide the time by a given number and execute on each match.
//   Read the examples and notes in es_crontab.txt carefully to understand each option.
 
// This "command" executes every 20 minutes, 8am-5pm, Mon-Fri
crontab 0,20,40 8-17 * * 1-5 "command"
 
// This "command" executes every 2 minutes
crontab */2 * * * * "command"
// This is the same as typing
crontab 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * "command"
 
// This "command" executes every 3 hours, 6pm-6am, Mon-Fri
crontab 0 18-6/3 * * 1-5 "command"
 
// This cronjob will be added only if the job does not exist already
crontab 0 4 * * * "command" cg_restart
// This does the same thing as the command above.
crontab 0 4 * * * "command" cg_restart 0
 
// This cronjob will overwrite any existing job by the same name
crontab 0 3 * * 0,6 "command" cg_weekend 1
 
// This "command" is executed every minute
crontab * * * * * "command"

Notes

  • Included with Eventscripts v1.5
  • If you do not assign a job name to your new cronjob, one will be created for you and output to server_var(_crontab_job_name) for scripters to use.
  • The third and fifth fields in the time are executed as an OR operation. If the day of the month OR the day of the week is correct, the command will execute. Everything else executes as an AND operation and all requirements must be met.

See also

blog comments powered by Disqus