linux shell 交换式登录

使用的脚步有四个:【backup_unasyn.sh          //备份所以执行的脚步
                    host_ip.sh                //循环捕捉我服务器的ip进行
                    db_china.sh              //服务器的hosts名
                    passwds.sh               //登录服务器使用的密码
                   】
服务器结构:
IP1:113.11.226.112    IP2:113.11.226.113~116         IP3:113.11.226.118
IP1:执行脚本服务器【back_unasyn.sh、host_ip.sh、db_china.sh、passwds.sh】
Ip2:要备份的服务器
IP3:数据存放服务器

脚步展示如下所示:
[root@data ~]# vi passwds.sh
#!/bin/bash
pw1=123456
pw2=654321

============================================
[root@data ~]# vi host_ip.sh
#!/bin/bash
hosts=(
#china
113.11.226.113
113.11.226.114
113.11.226.115
113.11.226.116
)

==================================
[root@data ~]# vi db_china.sh
#!/bin/bash

#get the sh file.
shfile=$1

#set the script file path.
thepath=/root
date=`date +%Y%m%d`
source /root/host_ip.sh
source /root/passwds.sh
#set the update files.
servers=(
china1_db
china2_db   //host名称对应ip
china3_db
china4_db
)
for i in ${servers[*]}
do
${thepath}/${shfile} ${i} $pw1 $pw2 $date $hosts  
done
=====================================
[root@data ~]#vi backup_unasyn.sh
#!/usr/bin/expect

set host       [lindex $argv 0]
set pwd1      [lindex $argv1]

set pwd2      [ lindex $argv2]
set date        [lindex $argv 3]
set hosts      [lindex $argv 4]
set back_host  "113.11.226.118"

#======================================
set timeout 3600
# ssh to target machine
spawn ssh -p 50589 dwy@$host
expect "password:"
send "$pwd1/n"

# su as root
sleep 3
expect -re ".*"
send "su -/n"

expect "Password:"
send "$pwd2/n"

expect "#"
send "cd /home/cyanogen/backup/n"

# sftp put backup database
expect "#"
send "sftp -oPort=50589 dwy@$back_host/n"
expect "password:"
send "$pwd1/n"
expect "sftp>"
send "cd backup/n"
expect "sftp>"
send "put slg-$hosts-$date.gz/n"
expect "sftp>"
send "quit/n"

expect "#"
send "cd /var/log/n"
expect "#"
send "tail -21 secure >> /home/dwy/put_backup.log/n"

expect "#"
exit

=============================
脚本执行的过程:
./db_china.sh backup_unasyn.sh 时:

我怎样调用host_ip.sh中的ip让它进行循环,来完成我的过程。

请各位高手帮帮我,我的邮箱:dwy1008@163.com

                           qq:969856985         

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值