Saltstack use Tutorial (iii): Scheduled task management

Source: Internet
Author: User
Tags saltstack

Let's start with an example of adding a task:

Note: Although you can create a delete here, but the author does not recommend such use, management complex, recommended the bottom of the file Management Timing task method

/usr/sbin/ntpdate pool.ntp.org >>/dev/null 2>&1:  cron.present:     - user: root    - minute: 10[[email protected]  base]# salt  ' saltstack-node2.example.com '  state.highstatesaltstack-node2.example.com:---- ------          id: /usr/sbin/ntpdate pool.ntp.org  >>/dev/null 2>&1    Function: cron.present       result: true     comment: cron /usr/sbin/ntpdate  pool.ntp.org >>/dev/null 2>&1 added to root ' s crontab      started: 13:15:35.375887    duration: 68.023 ms      Changes:                 ----------              root:                   /usr/sbin/ Ntpdate pool.ntp.org >>/dev/null 2>&1summary------------succeeded: 1  ( changed=1) failed:    0------------total states run:      1

Annotations:

Minute #分钟hour #小时daymonth #日month #月dayweek #0 is Monday to Saturday, Sunday is 7

default Execution User "Root", the time is not filled by default is"*",Cycle Execution "*/2",Random Execution "Random",identifieris atask identifiers, similar to tasksID, specifying an identifier when changing a task makes it easy to modify.

You can use it now . Salt View Scheduled Tasks

[Email protected]e1~]# Salt ' saltstack-node2.example.com ' Cron.raw_cron root

saltstack-node2.example.com: # Lines Below here is managed by Salt, does not edit # Salt_cron_identifier:sync_time */10 * * * */usr/sbin/ntpdate pool.ntp.org >>/dev/null 2>&1

Delete a scheduled task

If you want to add a " echo "Test" "The timing task, the results found added wrong

[[Email protected]~]# Salt ' * ' cron.set_job root ' 1 ' * ' * ' * ' * ' * ' echo ' test '

Saltstack-node2.example.com:newsaltstack-node1.example.com:newyou have new mail in/var/spool/mail/root

[Email protected]~]# Salt ' * ' Cron.raw_cron root

saltstack-node1.example.com: * * * * * */usr/sbin/ntpdate pool.ntp.org # Lines Below here is managed by Salt, do no  T edit # test 1 * * * * echosaltstack-node2.example.com: # Lines Below here is managed by Salt, does not edit #    Salt_cron_identifier:sync_time */10 * * * */usr/sbin/ntpdate pool.ntp.org >>/dev/null 2>&1 # Test 1 * * * * echo

need to write like this                        

Salt ' target ' cron.rm_job user ${my_cron} ${exec_crondtion}

[Email protected]~]# Salt ' saltstack-node2.example.com ' cron.rm_job root echo minute= ' 1 '

Saltstack-node2.example.com:

Removed

[Email protected]~]# Salt ' * ' Cron.raw_cron root

saltstack-node1.example.com: # Lines Below here is managed by Salt, does not edit # test 1 * * * echosaltstack-n  ode2.example.com: # Lines Below here is managed by Salt, does not edit # salt_cron_identifier:sync_time */10 * * */usr/sbin/ntpdate pool.ntp.org >>/dev/null 2>&1 Note: Although this can be deleted, but the author does not recommend this use, recommend the following file Management Timing task method


Tips for file management Scheduled tasks:

in the Linux everything in it, CentOS Next is /var/spool/cron/ The corresponding file name is the user's scheduled task

You can manage the tasks by managing these files, but be sure to note the file permissions and the owner.


warning: Span style= "FONT-FAMILY:CALIBRI;FONT-SIZE:9PT;" lang= "en-us" xml:lang= "en-US" >salt management will completely overwrite all the contents of the original configuration, so use it with caution.

View the form of a timed task: [[email protected] ~]# cd /var/spool/cron/[[email protected] cron]#  LSBAI  ROOT[[EMAIL PROTECTED] CRON]# LLTOTAL 8-RW------- 1 bai   bai   22 sep 30 15:17 bai    # This is Bai this user's scheduled task file, 600 permissions-rw------- 1 root root 146 sep 30 14:56 root   Write state file below [[email protected] crontab]# vim test.sls/var/spool/cron/bai:   File.managed:    - source: salt://crontab/files/saltstack-node2.example.com.bai     - mode: 600    - user: bai     - group: bai      execution status [[Email protected] crontab]# salt   ' saltstack-node2.example.com '  state.highstatesaltstack-node2.example.com:----------           id: /var/spool/cron/bai    function: file.managed       result: true     comment: file /var/spool/cron/bai  updated     started: 15:40:33.193250    duration:  57.914 ms     Changes:                 ----------               diff:                   ---                    +++                    @@ -1,0 +1,1 @@                   +* * * * * echo  "hello  World " summary------------succeeded: 1  (changed=1) failed:    0------------ Total states run:     1 viewing timed tasks created [[email protected] crontab]#  salt  ' saltstack-node2.example.com '  cron.raw_cron baisaltstack-node2.example.com:     * * * * * echo  "Hello world" you have new  Mail in /var/spool/mail/root


This article is from the "Nginxs Small white" blog, please be sure to keep this source http://nginxs.blog.51cto.com/4676810/1699698

Saltstack use Tutorial (iii): Scheduled task management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.