Run server jobs at certain Minutes, Hours, Days of the Week and Days of the Month. Admins will need the ROOT access flag to Add, Remove or View Cronjobs. To get a better idea of what cronjobs are, check out the official Wikipedia article here
Server Console Commands
- sc_addjob Minute Hour DayOfTheMonth Month DayOfTheWeek “Cronjob” – Adds a new cronjob that will run at the specified time
- sc_removejob cronid – Removes a cronjob using the cronid
- sc_removealljobs – Removes all the current cronjobs
- sc_printjobs – Prints out all the current cron jobs in the console
- sc_module_hour_adjust -23/+23 – Adjust the job hour value by -23 or +23 – This is for servers that are outside your local time zone and want jobs to run inside yours
Usage and Examples
All the tasks can be setup inside the sc_jobs.cfg file, or using sc_addjob from the server console. Few examples can be found inside with the config file with descriptions.
Format specification taken from the Cron Wikipedia article.
* * * * * server command to execute
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 – 6) (0 to 6 are Sunday to Saturday)
│ │ │ └────────── month (1 – 12)
│ │ └─────────────── day of month (1 – 31)
│ └──────────────────── hour (0 – 23)
└───────────────────────── min (0 – 59)
Example 1 – Say Hello Server – Every minute
sc_addjob * * * * * “say Hello Server”
This would “say Hello Server” – every single minute from the server.
Like you typed in “rcon say Hello Server” – because the input is all wildcards (ignored). So basically the runner thread which checks jobs schedules every single minute would know to ignore all input values and run the task.
Example 2 – Shutdown the server every morning at 5AM
sc_addjob 0 5 * * * “quit”
This would run the “quit” RCON command at 5am every single day – Be careful with this because any jobs you run outside a longer time span would get reset and the server would go back to the basic config which you start up with (autoexec.cfg/server.cfg).
Example 3 – Execute the christmas.cfg on the 1st of December at 12am
sc_addjob 0 0 1 12 * “exec christmas.cfg”
Execute the christmas.cfg on the 1st of December every year – if we added a day of the week to this instead of wildcard. This job would only execute if the 1st of December came on that specific weekday.
Example 4 – Execute an unluckyday.cfg on Friday the 13th at 12am
sc_addjob 0 0 13 * 5 “exec unluckyday.cfg”
Run an unluckyday.cfg on each Friday the 13th – 5 being a Friday with the Day of the Week option. We skip Day of the Month because in this instance it’s unnecessary.
- sc.smx -> addons\sourcemod\plugins
- sc_module.smx -> addons\sourcemod\plugins
- sc_jobs.cfg -> cfg\sourcemod
- sc_module.cfg -> cfg\sourcemod
- sc.sp -> addons\sourcemod\scripting
- sc_module.sp -> addons\sourcemod\scripting
- scrontab.inc -> addons\sourcemod\scripting\include
You can help support plugin development and server costs by white listing the website in your Adblock software or sign up for Vultr using my affiliate URL here for $100 credit, available for a limited time (Top 3 rated VPS host with multiple locations), Thanks.
FatallError – getTime idea from his shutdown plugin
Nican – Giving ideas for the module and teaching me the more advanced aspects of SourceMod
– Recoded the plugin to use new decals
– Crontabs are now based on the official UNIX format – Read up more about them here
– Added checks for a valid number of parameters – To avoid any potential problems
– Added a check for duplicate cron jobs getting added and a new native SC_DoesCronJobExist
– Plugin now checks for a duplicate job being added with the new native
– Rebuilt on the latest sourcepawn compiler
– Fixed the config file getting ignored for SC Module
– Moved to a global versioning inside the scrontab.inc
– Fixed the server error message when unloading the plugin, with invalid handles from KillTimer
– Enabled a console variable to enable-disable job server logging output – This can be edited inside sc_module.cfg
– Small source change for the latest version of sourcemod
– Plugin renamed from Basic Server Crontab to Server Crontab
– Rewritten – Changed some parts of code to support job start & end times
– Moved the plugin out of beta
– Big rewrite – now module based
– Wildcard character is now “?”
– New console vars – sc_addjob/sc_removejob/sc_removealljobs/sc_printjobs
– Minutes now support the wildcard option
– Jobs input weekday/hour/minute are now range checked
– The hour option can now use a wildcard “*”
– Renamed the plugin to Basic Server Crontab
– Fixed a bug with parsing the jobs.ini file
– Few more misc changes
– Initial public release