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