|
|
|
@ -3,6 +3,7 @@ package core |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"net/rpc" |
|
|
|
"os/exec" |
|
|
|
"path" |
|
|
|
"path/filepath" |
|
|
|
"scagent/config" |
|
|
|
@ -90,36 +91,16 @@ func clientUploadFile(remote string, filePath string, uploadPath string) { |
|
|
|
logger := util.NewProductionLogger() |
|
|
|
defer logger.Sync() |
|
|
|
// 调用外部组件scalib 程序执行
|
|
|
|
// ./scalib -h 192.168.66.92:9098 -f /www/gfs/sync_zips/BIU_20251009_153640.zip /www/afs/logs/
|
|
|
|
// ./scalib -h 192.168.66.92:9098 -f /www/gfs/sync_zips/BIU_20251009_153640.zip -u /www/afs/logs/
|
|
|
|
// 执行命令
|
|
|
|
cmd := fmt.Sprintf("scalib -ip %s -port %s -file %s -upload %s", dstip, dport, filePath, uploadPath) |
|
|
|
cmd := fmt.Sprintf("./scalib -h %s -f %s -u %s", remote, filePath, uploadPath) |
|
|
|
fmt.Printf("cmd: %s\n", cmd) |
|
|
|
// 执行命令
|
|
|
|
err := util.ExecCommand(cmd) |
|
|
|
// 执行系统命令
|
|
|
|
err := exec.Command(cmd).Run() |
|
|
|
if err != nil { |
|
|
|
logger.Error("ExecCommand failed", zap.Error(err)) |
|
|
|
fmt.Printf("ExecCommand failed: %v\n", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 将服务器的信息拆分为ip和端口
|
|
|
|
harr := strings.Split(remote, ":") |
|
|
|
dstip := harr[0] |
|
|
|
dport := harr[1] |
|
|
|
|
|
|
|
// 连接到RPC服务器
|
|
|
|
service := fmt.Sprintf("%v:%v", dstip, dport) |
|
|
|
client, err := NewUpFileClient(service) |
|
|
|
if err != nil { |
|
|
|
logger.Error("NewUpFileClient failed", zap.Error(err)) |
|
|
|
} |
|
|
|
defer client.rpcClient.Close() |
|
|
|
// 调用 transferFile
|
|
|
|
err = transferFile(client, filePath, uploadPath) |
|
|
|
if err != nil { |
|
|
|
logger.Error("TransferFile failed", zap.Error(err)) |
|
|
|
fmt.Printf("TransferFile failed: %v\n", err) |
|
|
|
} |
|
|
|
fmt.Printf("TransferFile success\n") |
|
|
|
|
|
|
|
} |
|
|
|
|