Chinaunix

标题: 怎么在本地服务器获取年月日时分秒做变量,传递给海量服务器? [打印本页]

作者: 二马金弓    时间: 2013-09-27 10:58
标题: 怎么在本地服务器获取年月日时分秒做变量,传递给海量服务器?
本帖最后由 二马金弓 于 2013-09-30 17:22 编辑

怎么在本地服务器获取年月日时分秒做变量,传递给海量服务器?

已解决
作者: 关阴月飞    时间: 2013-09-27 11:18
目测,只要所有服务器时间一致就没这个问题了,所以,整个时间同步吧.....
作者: 二马金弓    时间: 2013-09-27 12:26
回复 2# 关阴月飞
  1. spawn ssh  root@${ip} " tar -Pcvf /data/bak.${backup_time}.tar `xargs < ${file_list}` "
复制代码
脚本里是ssh到远程服务器,那么在for循环里,这里的时间是不一样的。我是想用这个本地的时间作为“同一个时间“,写到备份的压缩包里
作者: yuloveban    时间: 2013-09-27 13:08
回复 1# 二马金弓


    做个NTP吧~~
作者: yuloveban    时间: 2013-09-27 13:10
回复 3# 二马金弓


    直接ssh 不行吗? 为什么要用spawn呢,这样就产生了一个子进程是吧?
作者: 二马金弓    时间: 2013-09-27 13:57
回复 6# yuloveban


    免输入密码吧,远程机器比较多。
作者: yuloveban    时间: 2013-09-27 16:47
回复 8# 二马金弓


    这个不能免输入密码吧, 又没有expect和做ssh互信哦~
作者: yuloveban    时间: 2013-09-27 16:47
回复 8# 二马金弓


    这个不能免输入密码吧, 又没有expect和做ssh互信哦~
作者: wenhq    时间: 2013-09-27 20:39
这么做的目的是什么呢?
paraller process with multi。。
作者: hanfeng122525    时间: 2013-09-28 17:57
本帖最后由 hanfeng122525 于 2013-09-28 18:00 编辑

[root@localhost ~]# more test.sh
#!/bin/bash

file_list=$1
backup_time=`date +%Y%m%d-%H%M%S`
ip=192.168.88.156

expect << EOF
set timeout 14400

set file_list [lindex $argv 1]
set backup_time [lindex $argv 2]

spawn ssh root@$ip "tar -zcvf /root/backup${backup_time}.tar.gz /root/*.php"
expect {
        "yes/no" {send "yes\r"}
        "password:" {send "root\r"}
}
puts "$ip fullbackup is ok\n"


spawn scp /root/${file_list} $ip:/root/
expect {
        "yes/no" {send "yes\r"}
        "password:" {send "root\r"}
}
puts "$ip scp file_list is ok\n"


spawn ssh root@$ip "tar -zvcf /root/backup${backup_time}.tar `xargs < /root/${file_list}`"   /
expect {
        "yes/no" {send "yes\r"}
        "*assword:" {send "root\r"}
}
puts "$ip backup_filelist is ok\n"

expect eof
EOF



这样可以
作者: 二马金弓    时间: 2013-09-29 10:25
回复 12# hanfeng122525


    谢谢了,比较了和我写的不同的地方了。学习啦。
作者: 二马金弓    时间: 2013-09-29 11:19
回复 12# hanfeng122525
  1. spawn ssh root@$ip "tar -zvcf /root/backup${backup_time}.tar `xargs < /root/${file_list}`"   /
复制代码
末尾的/,是多余的吧。
作者: 二马金弓    时间: 2013-09-29 17:27
回复 12# hanfeng122525


    你好,这个单IP的可以实现的。谢谢!
    多个IP怎么设置ip循环呢,我试了几个ip的循环没有成功。
作者: hanfeng122525    时间: 2013-09-29 21:37
[root@localhost ~]# more test.sh
#!/bin/bash

file_list=$1
backup_time=`date +%Y%m%d-%H%M%S`
ip=192.168.88.156

expect << EOF

foreach ip {
192.168.1.1
192.168.1.2
…………
} {
set timeout 14400

set file_list [lindex $argv 1]
set backup_time [lindex $argv 2]

spawn ssh root@$ip "tar -zcvf /root/backup${backup_time}.tar.gz /root/*.php"
expect {
        "yes/no" {send "yes\r"}
        "password:" {send "root\r"}
}
puts "$ip fullbackup is ok\n"


spawn scp /root/${file_list} $ip:/root/
expect {
        "yes/no" {send "yes\r"}
        "password:" {send "root\r"}
}
puts "$ip scp file_list is ok\n"


spawn ssh root@$ip "tar -zvcf /root/backup${backup_time}.tar `xargs < /root/${file_list}`"   /
expect {
        "yes/no" {send "yes\r"}
        "*assword:" {send "root\r"}
}
puts "$ip backup_filelist is ok\n"

expect eof
}
EOF
回复 15# 二马金弓


   
作者: 二马金弓    时间: 2013-09-30 10:07
回复 16# hanfeng122525


    hanfeng,你好。我想问一下:
1.这个ip=192.168.88.156是多ip列表里的吗?还是本机的ip呢?-----这个地方没看明白
2.foreach ip {
192.168.1.1
192.168.1.2
…………
}
这里的fo reach有空格吗



谢谢你在这个贴子里的跟帖回复指导。待完成这个,好好研究学习!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2