【问题标题】:How to run commands to change file text file in remote host using bash script?如何使用 bash 脚本运行命令以更改远程主机中的文件文本文件?
【发布时间】:2014-06-10 17:53:24
【问题描述】:

您好,我正在运行 bash 脚本来更改文本文件上的关键字,但它位于@我的远程主机 (10.101.5.91),我尝试使用此示例代码,但它不会更改该文件上的任何内容,也没有错误要显示。


changeConfig(){
    shopt -s globstar
    for file in $1
    do
            sed -i.bak 's/$2/$3/g' $file
    done
}

remoteFunction(){
    ssh ppuser@10.101.5.91 "`declare -f changeConfig`; changeConfig /var/www/file.txt
}

remoteFunction

谁能帮帮我?谢谢.... :)

【问题讨论】:

标签: bash ubuntu ssh


【解决方案1】:

以下将更改该关键字

#!/bin/bash
file='/path/on/remotehost/filename'      #PATH on remote host
ssh ppuser@10.101.5.91 "sed -i.bak "s/$2/$3/g" $file"    #Would work without password if ssh keys exchanges else will ask $ wait for password

虽然不知道你在用$1 做什么。

【讨论】:

    猜你喜欢
    • 2013-02-04
    • 2021-12-18
    • 1970-01-01
    • 2016-11-01
    • 2023-04-02
    • 2015-06-08
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多