[Linux] shell script programming – count the device number in the log file to send the notification email


1. List of log files

For example, / data1 / logs / 2019 / 08 / 15/


2. Count a keyword shell script in the log

Zcat *. Gz|grep keyword|grep – op “deviceid = [^] +” |uniq|sort – U > / TMP / 20190815.log

Date formats the date and other information, and splices them into paths.

WC – L / TMP / 20190815.log, get the number of rows

PHP / xxxxx / sendmail. PHP “information”


3. Call the third-party SMTP of PHP script to send the notification letter

Use $argv [1] to receive parameters

The sendmail command cannot be used because postfix may not be installed

PHP uses the phpmailer class, mainly the SMTP class, to call a third party to send a message


4. Add cron timing task

Call the shell script at 8 o’clock every day

0 8 * * * xxxxxx


My blog is about to be synced to Tencent cloud + community. I invite you to join us: https://cloud.tencent.com/developer/support-plan? Invite? Code = 2ttpphefailogs