赞
踩
import subprocess import datetime import time def run_scp_command(source_path, target_path): command = ['scp -r ', source_path, target_path] try: subprocess.run(command, check=True) print("File transferred successfully!") except subprocess.CalledProcessError as e: print("An error occurred:", e) while True: dt_start = datetime.datetime.now().strftime("%Y%m%d%H%M%S") source_path = 'xx.xx.xx.xx:/root/Algo/dt_resource/dtt_dg_prod/resource/scada/100_20221221_transient' target_path = './' + dt_start run_scp_command(source_path, target_path) time.sleep(5*60)
#!/bin/bash # 函数来执行scp命令 run_scp_command() { local source_path=$1 local target_path=$2 scp -r "$source_path" "$target_path" if [ $? -eq 0 ]; then echo "File transferred successfully!" else echo "An error occurred." fi } # 无限循环 while true; do # 获取当前时间并格式化 dt_start=$(date +"%Y%m%d%H%M%S") # 定义源文件路径和目标路径 source_path='xx.xx.xx.xx:/root/Algo/dt_resource/dtt_dg_prod/resource/scada/100_20221221_transient' target_path="./${dt_start}" # 运行scp命令 run_scp_command "$source_path" "$target_path" # 等待5分钟 sleep 300 done
添加权限
chmod +x download.sh
执行
./download.sh
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。