About
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.
Installation
- 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
Download
Download locally from here
SourceMod Thread can be found here
Support
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.
Credits
FatallError – getTime idea from his shutdown plugin
Nican – Giving ideas for the module and teaching me the more advanced aspects of SourceMod
Version History
v2.0.0.0
– 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
v1.0.1.3
– 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
v1.0.1.2
– Fixed the config file getting ignored for SC Module
– Moved to a global versioning inside the scrontab.inc
v1.0.1.1
– 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
v1.0.1.0
– Plugin renamed from Basic Server Crontab to Server Crontab
– Rewritten – Changed some parts of code to support job start & end times
v1.0.0.0
– 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
v1.0.0.2b
– Jobs input weekday/hour/minute are now range checked
– The hour option can now use a wildcard “*”
v1.0.0.1b
– Renamed the plugin to Basic Server Crontab
– Fixed a bug with parsing the jobs.ini file
– Few more misc changes
v1.0.0.0b
– Initial public release
Thak you for all the help.
I got it now.
You’re welcome – Good to hear you got everything working.
Feel free to give me a shout if you have any more problems and need help.
I also get this error when i add job thru console
] sc_addjob * * * * * “say Hello Server”
[SC] sc_addjob – Invalid usage
[SC] Usage: sc_addjob minute hour day_of_the_month month day_of_the_week “cronjob”
Can’t seem to replicate this issue. Just ran a test and everything was working fine.
Console Log Snippet:” triggered sm_hsay (text This server is running Server Crontab)
sc_addjob * * * * * “say Hello Server”
[SC] Cron job “say Hello Server” added successfully
L 01/16/2017 – 16:55:19: [sc_module.smx] Running cron job “sm_hsay This server is running Server Crontab”
L 01/16/2017 – 16:55:19: [sc_module.smx] Running cron job “say Hello Server”
L 01/16/2017 – 16:55:19: [basechat.smx] “Console<0>
Console: Hello Server
Which shows the job was added fine without problems. Which mod was this under and how was you adding the job?
Hi thanks you so much fpr the quick reåly abd these commands.
I chamged jobs in the cfg, when the server was running, is there any command to re read the jobs from the cfg file?
Hey. You’re welcome, The jobs config file is parsed when the plugin initially loads.
If you want to parse the config while the server is running. You’ll have to type this command in the server console:
“exec sourcemod/sc_jobs.cfg” – This just forces the server to execute a config file and exists amongst most source game mods.
Don’t worry about the same jobs getting added multiple times with that command – Plugin checks whether a job exists before saving internally.
Hi. Is there anyway i can “update” the tasks i add withput restarting my server? If i for example have added a new sm_say, i want it to show the new text.
Hey,
You can type in the console:
“sc_printjobs” – Prints all the cronjobs with their ID
Once you’ve found the job you want to modify, type:
“sc_removejob ID” – ID will be the number from the print jobs command that you want to remove.
Now you can add the modified job using:
“sc_addjob” – Using the data from job above with your personal modifications
Just double check you don’t have it in the sc_jobs.cfg and it won’t overwrite your custom settings.
Could add “sc_save_jobs” or something along them lines to the next update, that dumps all your current jobs to the config file.
If you need anymore help, feel free to comment back.