现在的位置: 首页 > 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-05-25
  • 【十九大·理论新视野】动漫:“社会主义现代化强国”如何建成 2019-05-25
  • 太原黑臭水体治理接受国家专项督查 2019-05-24
  • 白芦笋:一年一会矜贵食 2019-05-24
  • 安徽通报2018年上半年全省旅游投诉情况 2019-05-24
  • 女性之声——全国妇联 2019-05-23
  • 【新华微视评】偏远农村的“智慧消防” 2019-05-23
  • 万花瞳:万花迷人眼 慧瞳观天下 2019-05-23
  • 视频:热心球迷!陈奕迅吴秀波惊现世界杯开幕式现场 2019-05-22
  • 【北京神龙京津车型报价】北京神龙京津4S店车型价格 2019-05-22
  • 国外看中国科技:中国隧道技术发展迅速享誉世界 2019-05-22
  • 孕妇在巴黎大区快线列车上产子 宝宝获赠“大礼” 2019-05-22
  • 【学习时刻】中国人民大学副校长刘元春:中央经济工作会议的四大亮点 2019-05-21
  • 环球佳酿举行新品发布会 百余款酒品集中发售 2019-05-21
  • 改造后的老旧楼房抗震能力是否提高?新老建筑是否共用逃生通道? 2019-05-21
  • 129| 429| 713| 621| 796| 116| 777| 375| 778| 330|