SHELL 入门

脚本执行:

test:

#!/bin/bash
a="Hello ,World!"
echo "A is:" $a

变为可执行

sudo chmod +x test


加入自动任务:

自动任务配置文件: /etc/crontab

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

/etc/cron.hourly下的脚本会被每小时运行一次,在每小时的17分时运行。
/etc/cron.daily下的脚本会被每天运行一次,在每天6点25分运行。
/etc/cron.weekly下的脚本会被每周运行一次,在每周第7天的6点47分运行。
/etc/cron.monthly下的脚本会被每月运行一次,在每月1号的6点52分运行。

运行命令:crontab -e

编辑加入:

*/1 **** date>>/var/www/plan/test.log

这个表示 开启一个计划任务 :每一分钟就像 test.log写入一条时间。

1 0 * * * php /var/www/newerp/index.php --task=daysales >> /var/www/newerp/application/logs/daysales.log
0 7-23 * * * php /var/www/newerp/index.php --task=skuscache --freash=true >> /var/www/newerp/application/logs/skuscache.log
5-59/30 7-23 * * * php /var/www/newerp/index.php --task=singlecache >> /var/www/newerp/application/logs/singlecache.log
9-59/30 7-23 * * * php /var/www/newerp/index.php --task=warningcache >> /var/www/newerp/application/logs/warningcache.log

#!/bin/bash 默认的liunx解释器

read 读取终端的输入的值。


WC:统计指定文件中的字节数、字数、行数,并将统计结果显示输出 


原文地址:https://www.cnblogs.com/canbefree/p/3854224.html