自动SCP脚本

自动scp脚本,使用了bash shell和expect:
1.进行单一文件或文件夹的传输
参数1:源单一文件或文件夹
参数2:目标地址
</home/jiang/bin/Auto/SingleScp>
#!/bin/bash
if scp -r $1 $2;then
echo $1 SingleScp Success
else
echo $1 SingleScp Not Success
fi

2.expect脚本,运行SingleScp,并提供scp的密码.
参数1:源单一文件或文件夹
参数2:目标地址
参数3:密码
</home/jiang/bin/Auto/AutoScp>
#!/usr/bin/expect
spawn /home/jiang/bin/Auto/SingleScp [lindex $argv 0] [lindex $argv 1]
#The Scptime is 10hours
set timeout 36000s
expect "*@*pass*"
send "[lindex $argv 2] "
expect "*SingleScp*Success*"

3.主脚本,可以用ln -s命令链接一系列特定的服务器上传脚本.
</home/jiang/bin/SelfScp>
#!/bin/bash
#to find the number of parameter
#这是密码设定,当然是不安全,但是方便,一般的为自己的常用密码
PassWord="password"
#这是用于
case $0 in
*ff*)
Goal="usrname@address:directory"
#可以设定密码
#PassWord="password"
;;
*farm*)
Goal="usrname@address:directory"
#PassWord="password"
;;
*li*)
Goal="usrname@address:directory"
;;
*zh*)
Goal=usrname@address:directory""
;;
*Self*)
echo "Enter the Goal(name@IPname):"
read Goal
echo "Enter PassWork:"
read PassWork
;;
*)
;;
esac

for i in $@
do
     if echo $i|grep ^/ ;then
    way1=$i
    else
    way1=$PWD/$i;
    fi
    echo Scp $way1 To $Goal
    /home/jiang/bin/Auto/AutoScp $way1 $Goal $PassWord
done
echo All Has Been Copied!

4.特定的服务器上传脚本
ln -s /home/jiang/bin/SelfScp /home/jiang/bin/farmscp
#就可以直接使用
farmscp 文件1 文件2

5.也可从服务器自动下载

</home/jiang/bin/SelfGet>
#!/bin/bash
#to find the number of parameter
PassWord="passwd"
MyD="/home/jiang/"
case $0 in
*ff*)
Goal="usrname@address:directory"
#可以设定密码
#PassWord="password"
;;
*farm*)
Goal="usrname@address:directory"
#PassWord="password"
;;
*li*)
Goal="usrname@address:directory"
;;
*zh*)
Goal=usrname@address:directory""
;;
echo "Enter the Goal(name@IPname):"
read Goal

echo "Enter the myself Main_Folder:(/home/jiang/)"
read MyD
if [ -z "$MyD" ];then
MyD="/home/jiang/"
fi

echo "Enter PassWord:"
read PassWord
if [ -z "$PassWord" ];then
PassWord="passwd"
fi

;;
*)
;;
esac

for i in $@
do
     if echo $i|grep ^/ ;then
    way1=$i
    else
    way1=$MyD$i;
    fi
    echo Scp $Goal$way1 To Local:$PWD
    /home/jiang/bin/Auto/AutoScp $Goal$way1 $PWD $PassWord
done
echo All Has Been Copied!

6.
ln -s /home/jiang/bin/SelfGet /home/jiang/bin/farmget



总结
当然可以将密码方到farmget的$@中,但是对我的工作安全用不着.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值