crontab settings for linux scheduled tasks

1.crontab installation
yum install vixie-cron Description: vixie-cron package is the main program of cron
yum install crontabs Description: crontabs package is a program used to install, uninstall, or list the tables used to drive the cron daemon.


Write a .sh scheduled task execution script according to the project
For example : project name + .sh ending


------- script file content -------
#!/bin/sh
cd /opt/traffic
java -jar xxxx .jar


crontab -e Edit the rules of the scheduled task script


Input i: enter INSERT mode
Input: wq: save and launch


cron is a built-in service of linux, but it does not start automatically, you can use the following methods to start and close this service:


service crond start //Start the service
service crond stop //Close the service
service crond restart //Restart the service
service crond reload //Reload the configuration
service crond status //View the crontab service status


The format of crontab explains the format of
each job (each line) It has six fields, the meanings of these six fields are
: Minute Hours Date (Day) Month Week
Number Range 0-59 0-23 1-31 1-12 0-7




In CentOS system, add automatic startup at boot: 
chkconfig --level 345 crond on


chkconfig command is mainly used to update (start or stop) and query system services for runlevel information. Keep in mind that chkconfig does not automatically disable or activate a service immediately, it simply changes the symlink.


Usage syntax:
chkconfig [--add][--del][--list][system service] or chkconfig [--level <level code>][system service][on/off/reset]


chkconfig is run without arguments When the usage is displayed. If you add a service name, then check if the service is started in the current runlevel. If yes, return true, otherwise return false. If on, off or reset is specified after the service name, chkconfi will change the startup information for the specified service. on and off refer to the service being started and stopped, respectively, and reset refers to resetting the service's startup information, regardless of what the init script in question specifies. The on and off switches are only valid for run levels 3, 4, and 5 by default, but reset can be valid for all run levels.


Parameter usage:
   --add adds the specified system service, allows the chkconfig command to manage it, and at the same time adds related data to the system startup description file.
   --del deletes the specified system service, which is no longer managed by the chkconfig command, and deletes the related data in the system startup description file at the same time.
   --level<level code> Specifies in which execution level the read system service should be enabled or disabled.
      Level 0 means: Indicates shutdown
      Level 1 means: Single user mode
      Level 2 means: Multi-user command line mode without network connection
      Level 3 means: Multi-user command line mode with network connection
      Level 4 means: Unavailable
      Level 5 means: With The multi-user mode level 6 of the graphical interface
      means: restart
      It should be noted that the level option can specify the run level to be viewed and not necessarily the current run level. For each runlevel, there can be only one start script or stop script. When switching runlevels, init will not restart services that have already been started, nor will it stop services that have been stopped again.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324591843&siteId=291194637