linux automatically added to empty the cache

1. cleanCache.sh

vim cleanCache.sh

! # / bin / bash
# once every two hours to clear the cache
echo "start clearing the cache"
Sync; Sync; Sync # written to the disk to prevent data loss
sleep 10 # 10-second delay
echo 3> / proc / sys / vm / drop_caches

2. The cache join regular tasks

echo '0 0 2/2 * * ? sh /opt/script/cron/cleanCache.sh' >> /var/spool/cron/root

Once every two hours to clean up cache.
First, the service crond status view crond running state ( I toss for a long time because of this problem, and found that the state is stopped! ), If the display crond (pid ****) is running ... , it indicates normal operation, if display is stopped (stop), then turn on the service, service crond start, if command not found is displayed, then did not follow this service, you need to install, install the code execution is:
yum install vixie-cron
yum install crontabs
after running over two lines of code, to complete the installation, and then check crond running.
Then, the input crontab -e, written into the code to be performed: For example: ** / 1 * * * * curl http://www.jsdaima.com, said access codes each minute js http: //www.jsdaima .com / site.
Note: If the link is accessible with & parameter passing, you need to escape or double quotes.
Such as access to:
http://www.jsdaima.com/index.php?m=Index&a=test
you need to write
** / 1 * * * * curl http://www.jsdaima.com/index.php?m = Index & a = test
or
** / 1 * * * * curl "http://www.jsdaima.com/index.php?m=Index&a=test"
After more than two steps, that is easy for PHP scheduled tasks, such as the timing of a trigger method , clear the cache and so on, it is widely used.

More detailed example of command format is as follows:
Basic format:
* * * * * Command
sharing command periphery moon and
the first column represents 1 minute to 59 minutes per * or * / 1 indicates
the second column represents 1 to 23 hours ( 0 indicates 0:00)
the third column indicates 1 to 31
fourth column represents the month 1 to 12
of five identification number week 0 to 6 (0 = Sunday)
in column 6 of the command to run
some examples crontab file:
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
the example above indicates nightly 21:30 restart apache.
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
the above example is 1, 10, 422 days per month: 45 restart apache.
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
the above examples represent every Saturday, Sunday 1: 10 to restart apache.
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
the above example are shown in day 18: 00-23: 00 every 30 minutes to restart apache.
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
the above examples represent every Saturday in 11: 00 pm restart apache.
* * / 1 * * * /usr/local/etc/rc.d/lighttpd restart
every hour restart Apache
* 23-7 /. 1 * * * the restart /usr/local/etc/rc.d/lighttpd
23:00 between 7 am, every hour restart Apache
0 4 *. 11 Mon-Wed /usr/local/etc/rc.d/lighttpd the restart
of each month 4 11:00 every Monday to Wednesday restart Apache
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
January 1st of 4:00 restart apache
name: crontab
Access: All users
use:
crontab file [-u the user] - replace with the specified file the current crontab.
crontab - [- u user] - replace the current standard input crontab.
the crontab-. 1 [User] - List of current users crontab.
crontab-e [user] - edit the user the current crontab.
crontab-D [User] - delete the user the current crontab.
crontab crontab-C DIR- specified directory.
crontab file format: the MHD MD cmd.
M: min (0-59).
H: Hour (0-23).
D: day (1-31).
m: month (1-12).
d: days of the week (Sunday to 0 ~ 6,0).
cmd to run a program, the program is sent to sh executed, the shell only USER, HOME, SHELL three environment variables
Description:
crontab is used to allow users at a fixed time or at regular intervals with enforcement proceedings, in other words, when the user is similar schedule. -u user refers to the setting specified
user time-table, the premise is that you must have permission (for example, a root) can specify the time-table of others. If you do not use the -u user, then, is set represents
set their own time-table.
Parameters:
crontab -e: execute a text editor to set the time-table, the default text editor is VI, if you want to use another text editor, please set the VISUAL environment variable
to specify the text editor (For example, the VISUAL joe setenv)
crontab -r: delete the current time-table
crontab -l: lists the current time-table
crontab file [-u user] - replace the current crontab with the specified file.
Time-table format is as follows:
f1 F2 F3 F4 F5 Program
which is a minute f1, f2 for hours, f3 represents a month in the first few days, f4 represents the month, f5 represents the day of the week. program pledged to execute
a program line.
When f1 represents * represents every hour is executing a program, to be executed when the rest by analogy per minute program, f2 * is
expressed from within a minute to a minute of b to be performed this time, when f1 is ab, f2 ab must perform when expressed from a to b of hours, the rest by analogy
when f1 is * / n when n represents each of a minute time intervals, f2 is * / n represents the time intervals every n hours once, the rest by analogy
denotes a, b, c when f1 is a, b, c, denotes a, b, c ... when ... minutes to perform, f2 is a, b, c, ... when ... hours to be performed, the rest by analogy
users can also all of the first set stored in the archive file, the way with crontab file to set the time-table.
Examples:
# 7:00 executed once per day / bin / LS:
0. 7 * * * / bin / LS
within 12 months, 6 to 12 o'clock in the morning every day, every three hours to perform a / usr / bin / Backup:
0 6-12 / 12 is. 3 * * / usr / bin / Backup
Monday to Friday 5:00 pm every day to send a letter to [email protected]:
0 17 * * 1-5 mail -s "hi" [email protected] </ tmp / the MAILDATA
monthly midnight every day 0:00 20 minutes, 2:20, 4:20 .... execute echo "haha"
20 0-23 / 2 * * * echo "haha"
Note:
when your program is executed in the time specified, the system will send letter to you to show the contents of the program execution, if you do not wish to receive such a letter, please leave a space in each row of
rear plus> / dev / null 2> & 1 to
example 2:
# every morning 6:10
10. 6 * * * DATE
# every two hours
0 * / 2 * * * date
every two hours between # 11 pm to 8:00 am, 8:00 am
023-7 / 2,8 * * * date
No. 4 and each week Monday # month to 11 am Wednesdays
0 11 4 * Mon-Wed dATE
1 Yuefen morning 4:00 #
0 4 1 jan * dATE
paradigm
$ crontab -l lists the user the current crontab.

Guess you like

Origin www.cnblogs.com/shigfdengys/p/12067130.html