shell 监控
#!/bin/bash
#The shell function used to watch the file state
#if [ "$1"="" ] || [ "$2"="" ]
if [ "$1" = "" ] || [ "$2" = "" ]
then
echo "Please input the two file names"
exit 1
fi
#if [ -e "$2" ]
if [ -e $2 ]
then
echo "The file2 is exits"
#untile [ ! -f "$2" ]
until [ ! -f $2 ]
do
sleep 1
#The following is increased
done
echo "The file is deleted"
fi
#if [ !mv $1 $2 ]
if [ ! `mv $1 $2` ]
then
echo "mv success!"
else
echo "mv failure!"
fi
[root@localhost sourcetemp]# ./filewatch shell1 shell2
The file2 is exits
[root@localhost sourcetemp]# rm -f shell2
[root@localhost sourcetemp]# ./filewatch shell1 shell2
The file2 is exits
The file is deleted
mv success!
注意问题:
1.· ·是命令替换,也可以用()。
2.if [ "$1" = "" ] || [ "$2" = "" ] "=" 两边有空格。