现在的位置: 首页 > web前端 > 正文

sftp automation script

2019年03月12日 web前端 ⁄ 共 1877字 ⁄ 字号 评论关闭

sftp automation script

秒速赛车公式 www.l19l7.cn ?

一觉亮天

?

If you want to download or upload some files from several sftp server, and the files have pattern in common, some kinds of tools to automate the process
is meaningful. I give an example script to make this thing happen.

?

/code begin

#get.sh

ips="10.68.104.205 10.68.104.206 /

10.68.104.207 /

10.68.104.208 /

10.68.104.155 /

10.68.104.156 /

10.68.104.157 /

10.68.104.158 /

10.68.104.159 /

10.68.104.160"

?

?

usr=sc

?

for ip in $ips; do

???????????sftp -bbatch.txt ${usr}@${ip}

done

?

/code end

?

/code begin

#batch.txt

cd /the/path/where/you/prefer

get *.tar

bye

/code end

?

The script get.sh loop through several hosts to login, and after that commands in batch.txt will be executed. Unfortunately things do not go on that smooth.
Each time you login a host, you have to input password manually. Even though, the scripts do help you in some extent. You can call it half-automation.

?

If you want to get rid of the step for inputing password, you have to do some preparation works in advance.?sftp uses public/private
key mechanism for authorization. You can ommit the step for inputing password benefiting from the mechanism. E.g., suppose this script is running in server A, and you need to fetch files in server B. After the steps followed, you do not need to input password
anymore.

?

#running in server A

>ssh-keygen -t rsa

>scp ~/.ssh/id_rsa.pub [email protected](server B’s IP):.ssh

?

#running in server B

>touch /root/.ssh/authorized_keys #skip this step if it already exists

>cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

?

Troubleshooting

1)check the permissions of the user's home directory on the Linux system. The group and worldpermissions should only have read and execute. If you put a writepermission on either, SSH will prompt you for the password.

2)Also, the'.ssh' subdirectory should only have read, write, and executepermmission for the owner permission. Permissions can make or breakyou if all else is set up correctly, at least this is what I havefound
with OpenSSH implementations.

3)One other thing I always do is force SSH version 2 connectivity (i.e.in OpenSSH's 'sshd-config' file the line would be "protocol 2" insteadof "#protocol 2,1" [which is the default]). (ssh -2)

?

抱歉!评论已关闭.

  • 一以贯之推进党的建设新的伟大工程 2019-03-19
  • 回复@真理论者:你天天在强坛攻击爱因斯坦是不是劳动?创造价值么?负价值也! 2019-03-19
  • 北京天安门广场更换花卉 2019-03-18
  • 党的自我革命是伟大社会革命的强大动力(深入学习贯彻习近平新时代中国特色社会主义思想) 2019-03-18
  • 人民日报人民时评:让安全生产理念成为基本共识 2019-03-18
  • “人民体育 健康中国”马拉松系列赛北京站 2019-03-17
  • 识破“假大学”并没那么难 2019-03-17
  • 佛山:用公积金买装配式住房 贷款额度或可上浮20% ——凤凰网房产北京 2019-03-17
  • 奥运冠军寄语Running Together国际迷你马拉松—在线播放—《奥运冠军寄语Running Together国际迷你马拉松》—体育—优酷网,视频高清在线观看 2019-03-17
  • 【理上网来喜迎十九大】西班牙学者:大国外交令中国成为建立世界新秩序的中流砥柱 2019-03-16
  • 马上背!十九大报告中的四个“新” 2019-03-16
  • 呼市赛罕区南门外小学开展庆父亲节亲子趣味足球赛 2019-03-16
  • 2017大皖客户端徽派栏目全面回顾宣传片 2019-03-15
  • 回复@海之宁:你想自主劳动?全民所有的生产资料凭啥让你自主? 2019-03-15
  • 重庆市南岸区:探索建立“微益坊” 2019-03-15
  • 736| 447| 350| 224| 915| 104| 42| 131| 814| 266|