In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Linux
You can use crontab to create scheduled execution tasks under Linux. The system comes with crontab by default, which is demonstrated under Ubuntu 16.04.
Basic use of 1.crontab
# / etc/init.d/cron status # View status # / etc/init.d/cron start # start crontab service # / etc/init.d/cron stop # stop crontab service # / etc/init.d/cron reload # reload scheduled tasks # crontab-l # View scheduled task list 2. Open the log
The configuration file needs to be modified.
# sudo vim / etc/rsyslog.d/50-default.conf...cron.* / var/log/cron.log # removes the commentator before cron.
Restart rsyslog:
# sudo service rsyslog restart
3. Set timing to execute tasks
This demo regularly executes a Python script written by yourself, bash script or other should be similar. It is important to note that it is best to specify the absolute path of the script, and if it is found that it still cannot be solved, you can first switch to the script path for execution. But it's supposed to be OK.
.. 00 * python / home/kdv/Desktop/sync-opensource/sync.py # executes the script or @ daily cd / home/kdv/Desktop/sync-opensource;python / home/kdv/Desktop/sync-opensource/sync.py 0 01 * mon python / home/kdv/Desktop/sync-opensource/sync.py # regularly every day, or @ weekly cd / home/kdv/Desktop/sync-opensource;python / home/kdv/Desktop/sync-opensource/sync.py
Set daily or to be executed weekly as needed. For more information, please refer to the link.
After setting up the task, we can look at the task list and need to reload the task.
# crontab-l # can view the task we added # / etc/init.d/cron reload # overload scheduled task # vim / var/log/cron.log # View the log generated by scheduled task 4. test
In the figure, the script is executed every 5 minutes as an example for testing.
Left: during the run of the script, a log file named at the current time is generated to record the output of the script during execution.
On the right: crontab's log file, you can see that the script is executed regularly every 5 minutes.
Windows
The Windows system does not have the crontab command, but the Windows system has a command similar to the crontab command: the schtasks command. Operate on Win10.
1. Help documentation
Use the following command to view the help documentation for schtasks to learn more about the command.
C:\ Users\ Administrator > schtasks /? SCHTASKS / parameter [arguments] description: allows administrators to create, delete, query, change, run, and abort scheduled tasks on local or remote systems. Parameter list: / Create creates a new scheduled task. / Delete deletes the scheduled task. / Query displays all scheduled tasks. / Change changes the scheduled task properties. / Run runs scheduled tasks on demand. / End aborts the currently running scheduled task. / ShowSid displays the security identifier corresponding to the scheduled task name. /? This help message is displayed. Examples: SCHTASKS SCHTASKS /? SCHTASKS / Run /? SCHTASKS / End /? SCHTASKS / Create /? SCHTASKS / Delete /? SCHTASKS / Query /? SCHTASKS / Change /? SCHTASKS / ShowSid /?
We can create, query, change and delete tasks. If we are not familiar with the corresponding subcommands, such as creating commands, we can use SCHTASKS / Create /? For a further look at the detailed description.
two。 View system default tasks
Use the schtasks command, or with the query parameter, schtasks / query to query the currently executed task of the system.
C:\ Users\ Administrator > schtasks folder:\ task name next run time mode = Adobe Acrobat UpdateTask 2019-9-2 11:00:00 ready SogouImeMgr Nash A ready sync-opensource 2019-9-2 11:30:00 ready WpsUpdateTask_Administrator 2019-9-2 9:23:46 ready. 3. Create a scheduled execution task
Type schtasks / create /? at the command line to see a more detailed description of the parameters, listing only a few of the parameters we are most concerned about.
/ TN taskname specifies the string that uniquely identifies this scheduled task in the form of path\ name. / TR taskrun specifies the path and file name of the program running at this scheduled time. For example: C:\ windows\ system32\ calc.exe/SC schedule specifies the schedule frequency. = = > create a scheduled task "EventLog" to start running wevtvwr.msc SCHTASKS / Create / TN EventLog / TR wevtvwr.msc / SC ONEVENT such as MINUTE: 1 to 1439 minutes per minute, hourly, daily, weekly MINUTE: 1 to 23 hours; DAILY: 1 to days; WEEKLY: 1 to 52 weeks; / ST starttime specifies the start time to run the task. The time format is HH:mm (24-hour time), for example 14:30 means 2:30 PM. If / ST is not specified, the default value is the current time. / SC ONCE must have this option.
3.1 create Task
We create a script called "sync-opensource" that periodically executes some bat script, which is executed at 11:30 every day. The command to create the task is as follows.
Schtasks / create / tn "sync-opensource" / tr "E:\ PycharmProjects\ opensource\ sync.bat" / sc daily / st 11virtual 304 other
4.1 find the specified task
For example, find the sync-opensource task we created above.
C:\ Users\ Administrator > schtasks-query | find "sync-opensource" sync-opensource is ready at 11:30:00 on 2019-9-2
4.2 Delete a task
You can delete the specified task using the following command.
Schtasks / delete / tr taskname
Summary
The above is the method of setting up regular tasks under Linux Windows introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply you in time. Thank you very much for your support to the website!
If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
We are trying add the second member to DAG, but we were receiving the following error:To correct thi
© 2024 shulou.com SLNews company. All rights reserved.