There is a server as a Web application, there is a directory (/data/web/attachment) that is not timed to be on the user

Source: Internet
Author: User

There is a server as a Web application, there is a directory (/data/web/attachment) is not timed to be uploaded by users of new files, but do not know when to upload. So, we need to do it every 5 minutes to detect if a new file is generated.

Please write a shell script to complete the detection. If a new file is available after detection, the list of new files needs to be output to a log that is divided into names by year, month, day, hour.


Train of thought: every 5 minutes, that must have a scheduled task, every 5 minutes to perform. When the script detects, it uses the Find command to find the files that have been updated in 5 minutes, and if there is an update, the command will output something, otherwise there is no output. We can compare the number of rows of the output result to see if it is greater than 0.


#! /bin/bashd= ' date-d '-5 min "+%y%m%d%h%m ' m=/data/web/attachmentfind $m/-type f-mmin-5 >/tmp/newf.txtn= ' wc-l/tmp /newf.txt |cut-d '-f1 ' if [$n-gt 0]then/bin/mv//tmp/newf.txt/tmp/$d. Logfi




To set executable permissions for a script: chmod +x filename


Scheduling with cron tasks

crontab-e to open an edit task schedule

Write

*/5 * * * * */tmp/filename.sh# #表示每5分钟执行一次


From left to right: minute, time, day, week, command

"*" represents a number in the range of values

"/" represents each

"-" represents from a number-a number

"," separate a few discrete numbers

Crond: Service Crond Status

Start a scheduled Task: Service Crond Start

There is a server as a Web application, there is a directory (/data/web/attachment) that is not timed to be on the user

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.