===========================================================================
if define a PATH variable in a statement the path that raised the command bug where path change occurs problem
- Original script file: INotify +rsync Live Sharing
#!/bin/bash
path=/data/
ip=172.16.1.41
CD $PATH &&\ switch to a new variable.
/usr/bin/inotifywait-mrq--format '%w%f '-e create,moved_to,close_write,delete $PATH |while read line
Do
If [-f $line];then the rsync command at this time is no longer available (workaround absolute path)/usr/bin/rsync
Rsync-az $line--delete [email protected] $IP:: Nfsbackup--password-file=/etc/rsync.password
Else
CD $PATH &&\
Rsync-az./--delete [email protected] $IP:: Nfsbackup--password-file=/etc/rsync.piassword
Fi
Done
===========================================================================
- Sh-x the validation process
[Email protected] scripts]# vim jiankong2.sh
#cd $PATH &&\
Do
If [-F $line];then
echo 01 specifically adds the display content to the current variable path in a convenient location
Echo $PATH
echo 03
Rsync-az $line--delete [email protected] $IP:: Nfsbackup--
Password-file=/etc/rsync.password
Else
echo 01
Echo $PATH
Sh-x Viewing process
[Email protected] scripts]# sh-x jiankong2.sh
+ path=/data/
+ ip=172.16.1.41
+ Read Line
+/usr/bin/inotifywait-mrq--format%w%f-e create,moved_to
+ ' ['-f/data/oldgirl '] '
+ Echo 01
01
+ The path of the Echo/data/path variable is converted to/data/so the command reads the path
/data/
+ Echo 03
03
+ rsync-az/data/oldgirl--delete [email protected]:
Jiankong2.sh:line 13:rsync:command Not found conclusion: if the error command cannot be found
+ Read Line
+ ' ['-f/data/oldgirl '] '
+ Echo 01
01
+ echo/data/
/data/
+ Echo 03
03
+ rsync-az/data/oldgirl--delete [email protected]:
Jiankong2.sh:line 13:rsync:command not found the same command cannot be found
+ Read Line
===========================================================================
- Workaround One define the variable to and path Differentiate Open Delete CD to the variable path
[email protected] scripts]# cat jiankong2.sh
#!/bin/bash
weizhi=/data/
ip=172.16.1.41
#cd $PATH &&\
/usr/bin/inotifywait-mrq--format '%w%f '-e create,moved_to,close_write,delete $WEIZHI |while read line
Do
If [-F $line];then
Rsync-az $line--delete [email protected] $IP:: Nfsbackup--password-file=/etc/rsync.password
Else
#cd $PATH &&\
Rsync-az $WEIZHI--delete [email protected] $IP:: Nfsbackup--password-file=/etc/rsync.password
Fi
Done
===========================================================================
Use absolute paths to jump out of the current defined path environment
/usr/bin/rsync
===========================================================================
A bug in the shell script that defines the PATH variable