Python Learning--day10 (while for if statements and writing scheduled tasks)

Source: Internet
Author: User
Tags crontab example

About the While loop:

While

Do

Done

For example

1, about the real-time operation of Memory:

(1), vim a.sh

(2), enter the following while loop

(3),./a.sh Execute Script

2, since the addition of one of the operation:

(1), Vim b.sh

(2), first assigns the value Xyy=1, then enters when xyy<=10, then outputs the XYY value, and executes the command which adds 1 (namely xyy++), until equals 10, the final output each time the result

(3),./b.sh Execute Script

3, about the login loop operation:

(1), Vim 2.sh

(2), please enter the user name and password, if the matching account password is correct, then the output login success, if the account password is incorrect, then the output, account and password is wrong

(3),./2.sh Execute Script

About the For statement:

For i in {}

Do

Done

For example:

1, the value from 1-100, and will be taken to the value of the output:

(1), Vim 3.sh

(2), in means to take the value from {} to I

(3),./3.sh Execute Script

2. You can ping the IP address to see what can be used:

(1), Vim 3.sh

(2), in means to take the value from {} to I

(3),./3.sh Execute Script

About the IF statement

For example:

Start Nginx Service

(1), Vim 4.sh

(2), chmod +x 4.sh (to 4.sh executable permissions)

(3),./4.sh Execute Script

About writing a task plan: crontab Command writing

Crontab commands to write scheduled tasks

Syntax: crontab [-u < user name >][profile] or crontab [-u < user name >][-ELR]

Crontab task Configuration Basic format:
* * * * * command
Minutes (0-59) hours (0-23) Date (1-31) month (1-12) week (0-6, 0 for Sunday) command

The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to run

Parameters
-e Edit the user's timer settings.
-l lists the user's timer settings.
-R removes the user's timer settings.
-u< User name > Specifies the user name to set the timer.

crontab Example

* * * */usr/local/etc/rc.d/apache restart #每晚的21:30 restart Apache

4 1,10,22 * */usr/local/etc/rc.d/apache restart #每月1, 10, 22nd 4:45 Restart Apache

1 * * 6,0/usr/local/etc/rc.d/apache restart #每周六, Sunday 1:10 restart Apache

0,30 18-23 * * */usr/local/etc/rc.d/apache restart #每天18:00 to 23:00 restart Apache every 30 minutes

0 * * 6/usr/local/etc/rc.d/apache Restart #每星期六的11: PM Restart Apache

* 23-7/1 * * * */usr/local/etc/rc.d/apache restart #晚上11点到早上7点之间, restart Apache every hour

* */1 * * * */usr/local/etc/rc.d/apache restart #每一小时重启apache

0 4 * Mon-wed/usr/local/etc/rc.d/apache restart #每月的4号与每周一到周三的11点重启apache

0 4 1 Jan */usr/local/etc/rc.d/apache restart #一月一号的4点重启apache

*/30 * * * * */usr/sbin/ntpdate 210.72.145.44 #每半小时同步一下时间

0 */2 * * * www/usr/bin/somecommand >>/dev/null 2>&1 #以用户www的身份每两小时就运行某个程序:


0 1 * * */home/testuser/test.sh
Call/home/testuser/test.sh every night 1 o'clock

*/10 * * * */home/testuser/test.sh
Call once every 10 clock/home/testuser/test.sh
* * * * */usr/local/etc/rc.d/lighttpd restart
The above example shows that 21:30 restarts Apache per night.

4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 4:45 restarts Apache on the 1, 10, and 22nd of the month.

1 * * 6,0/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows that 1:10 restarts Apache every Saturday and Sunday.

0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart
The above example shows that Apache restarts every 30 minutes from 18:00 to 23:00 every day.

0 * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD restart
The above example shows the restart of Apache every Saturday at 11:00am.

* */1 * * * */usr/local/etc/rc.d/lighttpd restart
Restart Apache every hour

* 23-7/1 * * * */usr/local/etc/rc.d/lighttpd restart
From 11 o'clock to 7 in the morning, restart Apache every hour.

0 4 * mon-wed/usr/local/etc/rc.d/lighttpd restart
4th per month with 11-point restart from Monday to Wednesday Apache

0 4 1 Jan */usr/local/etc/rc.d/lighttpd restart
4-point restart of Apache on January 1

*/30 * * * */usr/sbin/ntpdate 210.72.145.44
Synchronize time every half hour

Python Learning--day10 (while for if statements and writing scheduled tasks)

Related Article

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.