自动SCP脚本
来源:互联网 发布:淘宝店顺子电脑好不好 编辑:程序博客网 时间:2024/05/20 11:36
自动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的$@中,但是对我的工作安全用不着.
- 自动SCP脚本
- Linux自动SSH SCP脚本
- 使用scp+cron自动备份脚本
- 脚本自动判断关键字,符合的自动scp出去
- svn东西下来,远程自动scp脚本ubuntu
- 如何在脚本中执行scp时自动输入密码
- scp批量自动远程复制脚本不需要输入密码
- linux ssh scp expect/密钥 自动登录并自动执行脚本
- scp脚本生成
- 批量scp文件脚本
- shell脚本+scp命令
- Shell脚本:人机交互脚本-scp
- 通过mysqldump和SCP实现mysql定时自动备份到另外一台服务器脚本
- 两台服务之间定时SCP(免密码)自动传输文件脚本
- linux使用shell脚本实现自动登录scp传输文件到其他服务器
- 批量SCP文件的脚本
- scp命令与expect脚本
- Ssh,scp自动登陆方法
- MySQL user performance
- C/C++ 两大GUI库Qt & GTK比较
- Gtk+ Tutorials & Resources
- ssh keygen – 登入免密碼
- fatal error LNK1000: Internal error during IncrBuildImage
- 自动SCP脚本
- httplib HTTP协议客户端实现
- Python常用文件操作参考
- ActiveRecord多表查询,返回DataTable
- 预期中的尤文新帅-孔蒂
- Android MapView 申请apiKey
- viewWillAppear, viewDidAppear not being called, not firing
- tcp 三次握手 四次挥手 详细过程
- 如何生成jar文件