Running the Kontrollcomm script on a schedule
Sometimes you will have a server and template that contains commands that you want to run at certain intervals during the day, week, or month. In this case it's important to schedule the script
to run via crontab - the scheduler used in Unix and Linux systems.
Setting up the script user and crontab schedule
We can run the scripts as the root user (bad idea) or as a dedicated user. Let's name the user "kontrollcomm" for consistency.
ROOT-(0)> useradd -m kontrollcomm
ROOT-(0)> passwd kontrollcomm
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
We then need to put the agent file into a directory - in this case "/usr/local/bin" and make the script executable by the user.
cp kontrollcomm_agent.py /usr/local/bin/
chown kontrollcomm:kontrollcomm /usr/local/bin/kontrollcomm_agent.py
chmod 0700 /usr/local/bin/kontrollcomm_agent.py
Then we'll put the correct entries in the /etc/crontab file -
you can also use the user's crontab if you want.
I like the system crontab because it's eaier to see all of the
jobs in one file than in multiple user's files.
Here are my /etc/crontab entries.
ROOT-(0)> cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
#
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
#
#Kontrollbase client server polling script
*/5 * * * * kontrollcomm /usr/local/bin/kontroll_agent.py > /dev/null 2>&1
Notice that we are running the script as the user "kontrollcomm".
You will want to change that if you decided to call the user something else,
or if you are running them as root (not recommended).
There you see that the script runs every 5 minutes -
so we're downloading the template and running the report every 5 minutes. If you like, you can change this to any interval you choose.