linux文件远程传输客户端shell脚本与分布式客户机时间同步脚本

本文介绍了一种用于批量部署代码及配置文件到多个worker节点的bash脚本,并实现远程服务器的时间同步。该脚本能够自动读取worker节点列表和服务列表,进行文件夹创建、文件复制等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/bash
# 将代码和脚本传送至worker节点
# 改变当前工作目录
cd ${AMAZONCRAWLER_HOME}
#读取worker节点ip列表
i=0
while read line1
do
    #去除空格
    line1=`echo $line1 | sed s/[[:space:]]//g`
    #若为空则忽略本行
    if [ "$line1"x = x ]; then
        continue
    fi
    #若是注释行 忽略
    startChar=${line1:0:1}
    if [ "$startChar"x = "#"x ]; then
        continue
    fi
    #存储至worker_ips数组
    worker_ips[$i]=$line1
    ((i++))
done < ./conf/system/worker
#读取service列表
i=0
while read line1
do
    #去除空格
    line1=`echo $line1 | sed s/[[:space:]]//g`
    #若为空则忽略本行
    if [ "$line1"x = x ]; then
        continue
    fi
    #若是注释行 忽略
    startChar=${line1:0:1}
    if [ "$startChar"x = "#"x ]; then
        continue
    fi
    #存储至services数组
    services[$i]=$line1
    ((i++))
done < ./conf/system/services
worker_ips[0]='59.77.132.28'
for worker_ip in ${worker_ips[*]}
do
    echo ------------------------------------------
    echo copy to ${worker_ip}
    ssh -p 22 fzuir@${worker_ip} "(. /etc/profile;mkdir -p ${AMAZONCRAWLER_HOME}/conf/system)"
    scp conf/system/configuration.properties conf/system/chromedriver fzuir@${worker_ip}:${AMAZONCRAWLER_HOME}/conf/system
    for service in ${services[*]}
        do
            ssh -p 22 fzuir@${worker_ip} "(. /etc/profile;mkdir -p ${AMAZONCRAWLER_HOME}/SharedStorage/${service})"
            scp -r SharedStorage/${service}/*.jar fzuir@${worker_ip}:${AMAZONCRAWLER_HOME}/SharedStorage/${service}
            scp -r SharedStorage/${service}/*.sh fzuir@${worker_ip}:${AMAZONCRAWLER_HOME}/SharedStorage/${service}
        done
    scp -r SharedStorage/*.sh fzuir@${worker_ip}:${AMAZONCRAWLER_HOME}/SharedStorage
done

多服务机同步时间

#!/bin/bash  
   
 #变量定义  
ip_array=("59.77.233.195" "59.77.233.197" "59.77.233.196" "218.193.126.186" "218.193.126.188" "218.193.126.191" "218.193.126.192")  
user="fzuir"  
cmd="sudo date -s '2016-9-24 16:34:00'" 
port="22"
   
 #本地通过ssh执行远程服务器的脚本  
for ip in ${ip_array[*]}  
do 
    ssh -t -p $port $user@$ip $cmd 
done

  

 

转载于:https://www.cnblogs.com/zeze/p/5903434.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值