"Shell script Instance One" polls the files that are updated in the Mount directory

Source: Internet
Author: User

Instance one: monitors the specified file status in the mounted directory, polls for one second, and the file is updated to be taken to the specified directory.

1 #########################################################################2 #File Name:getshare.sh3 #Author:zoukch4 #########################################################################5 #!/bin/bash6 7 if[ $#! = 1]8  Then9Echo"input wrong!"Ten Exit One fi A  - if[-e/mnt/hgfs/share/$1 ] -  Then the     if[-E $HOME/workspace/log/Getshare.log] -  Then -Echo"[' Date +%y%m%d%h%m%s ']getsh.sh started!!!!!!">> $HOME/workspace/log/Getshare.log -     Else +Touch $HOME/workspace/log/Getshare.log -Echo"[' Date +%y%m%d%h%m%s ']getsh.sh started!!!!!!">> $HOME/workspace/log/Getshare.log + fi A  atLasttime= ' stat/mnt/hgfs/share/$1 | Grep-i Modify | Awk-f.'{print $}'| -Awk'{print $2$3}'| awk-f-'{print $1$2$3}'| Awk-f:'{print $1$2$3}'` -Echo"[' Date +%y%m%d%h%m%s ']the old modified time of $: $lastTime">> $HOME/workspace/log/Getshare.log -  -     if[-E./$1 ] -  Then inCP./$1 $. bak - fi to  +Cp/mnt/hgfs/share/$1 . - Else theEcho"[error]the/mnt/hgfs/share/$1 is not exist!" *Echo"[error]the/mnt/hgfs/share/$1 is not exist!">> $HOME/workspace/log/Getshare.log $ ExitPanax Notoginseng fi -  the  while[-e/mnt/hgfs/share/$1 ] +  Do ASleep 1 theNewtime= ' stat/mnt/hgfs/share/$1 | Grep-i Modify | Awk-f.'{print $}'| +Awk'{print $2$3}'| awk-f-'{print $1$2$3}'| Awk-f:'{print $1$2$3}'` -  $     if[$lastTime! =$newTime] $  Then -Lasttime=$newTime -Echo"[' Date +%y%m%d%h%m%s ']the Last modified time: $lastTime"> $HOME/workspace/log/Getshare.log theEcho"MODIFIED FILE at $newTime!">> $HOME/workspace/log/Getshare.log -CP./$1 $. bakWuyiCp/mnt/hgfs/share/$1 . the         if[-E./$1 ] -  Then WuEcho"[' Date +%y%m%d%h%m%s ']get $ success">> $HOME/workspace/log/Getshare.log - fi About fi $Done

There is no sun, no blue sky, otherwise I must go out for a walk.

no sunshine,no blue,or I'll take a walk. --zoukch

"Shell script Instance One" polls the files that are updated in the Mount directory

Related Article

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.