#!/bin/bash
#!/bin/bash
#作者:罗红江
#QQ:123769752
#mail:g_linux@qq.com
#原创---请你转载说明出处,请支持别人的劳动成果。
#sendfile+backupfile
declare -i backup sfstat
backup=0 #备份1为备份
sfstat=0 #为sendproc 验证参数
#!/bin/bash
#作者:罗红江
#QQ:123769752
#mail:g_linux@qq.com
#原创---请你转载说明出处,请支持别人的劳动成果。
#sendfile+backupfile
declare -i backup sfstat
backup=0 #备份1为备份
sfstat=0 #为sendproc 验证参数
#########################################################
IP="192.168.1.3"
##########################################################
main() #....
{
if (( $# < 1 ));then
echo "$0 [<-r file or directory> ,<-s file or directory>]"
exit
else
while getopts ":r:s:b:h" opt;
do
case $opt in
s)
sourcefile=$OPTARG
sfstat=$sfstat+1
;;
r)
rpatch=$OPTARG
sfstat=$sfstat+1
;;
b)
backup=1
btype=$OPTARG
;;
h)
echo $0 "[-r ,-s ,-b]"
echo "-r will sending remote file directory"
echo "-s will sending source file or directory"
echo "-b will backup file "
;;
:)
echo ">>> Error: '-$OPTARG' requires an argument"
exit
esac
done
fi
ipdbo
}
IP="192.168.1.3"
##########################################################
main() #....
{
if (( $# < 1 ));then
echo "$0 [<-r file or directory> ,<-s file or directory>]"
exit
else
while getopts ":r:s:b:h" opt;
do
case $opt in
s)
sourcefile=$OPTARG
sfstat=$sfstat+1
;;
r)
rpatch=$OPTARG
sfstat=$sfstat+1
;;
b)
backup=1
btype=$OPTARG
;;
h)
echo $0 "[-r ,-s ,-b]"
echo "-r will sending remote file directory"
echo "-s will sending source file or directory"
echo "-b will backup file "
;;
:)
echo ">>> Error: '-$OPTARG' requires an argument"
exit
esac
done
fi
ipdbo
}
send_proc() #....
{
if (( $sfstat >=2 ));then
if [[ -e $sourcefile ]] ;then
if (( $backup == 1 ));then
bakupfile $1
fi
scp -r $sourcefile >>sdf.log
else
echo "no find $sourcefile">>sdf.log
fi
fi
}
{
if (( $sfstat >=2 ));then
if [[ -e $sourcefile ]] ;then
if (( $backup == 1 ));then
bakupfile $1
fi
scp -r $sourcefile >>sdf.log
else
echo "no find $sourcefile">>sdf.log
fi
fi
}
bakupfile() #....
{
if (( ${#btype} >2 ));then
bkname=${btype:2}
else
bkname=${btype}
fi
cd /root
ssh "find ${rpatch} -name ${btype} -exec tar -cvf $1-$bkname.tar {} +"
{
if (( ${#btype} >2 ));then
bkname=${btype:2}
else
bkname=${btype}
fi
cd /root
ssh "find ${rpatch} -name ${btype} -exec tar -cvf $1-$bkname.tar {} +"
}
ipdbo() #IP.
{
for i in ${IP[*]}
{
send_proc $i
}
}
{
for i in ${IP[*]}
{
send_proc $i
}
}
main $@