Book Image

Salt Cookbook

By : Anirban Saha
Book Image

Salt Cookbook

By: Anirban Saha

Overview of this book

Table of Contents (18 chapters)
Salt Cookbook
About the Author
About the Reviewer

Scheduling jobs with cron

There are numerous occasions, no matter which infrastructure tier we work in, that we need to run automated tasks at some point of the day, week, month, and so on. In Linux systems, this functionality is achieved with cron. In this module, you will learn how to configure cron jobs using Salt modules.

How to do it...

We will use the salt-minion minion that we configured in the previous recipe.

  1. Create a new state called cron in the staging environment.

  2. Create and edit the /opt/salt-cookbook/staging/cron/init.sls file to have the following entries:

        - name: find /opt/apache-tomcat-6.0.43/logs/ -mtime +30 -exec rm -rf {} \;
        - user: root
        - minute: 00
        - hour: 01
        - daymonth: '*'
        - month: '*'
        - dayweek: '*'
  3. Apply the state to the minion:

    [root@salt-master ~]# salt 'salt-minion' state.sls cron saltenv=staging
              ID: clean_tomcat_logs
        Function: cron.present
            Name: find /opt/apache...