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