sunty
2020-04-16 7a522df01bec7e5bcecd983bd4b3f20a3297be6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package script
 
import (
    "fmt"
    "strings"
    "swfs/config"
    "swfs/util"
)
 
//根据搜索内容替换整行内容
func ReplaceLineContentBySearch(replaceContent string, searchContent string, scriptPath string, scriptFile string) {
    resSearchContent := GetNowLineContent(scriptPath+"/"+scriptFile, searchContent)
    replaceStr := "sed -ie 's/" + resSearchContent + "/" + replaceContent + "/g' " + scriptPath + "/" + scriptFile
    util.RunScript(replaceStr)
}
 
//获取查找内容当前行内容
func GetNowLineContent(filePath string, searchContent string) string {
    scriptStr := "cat " + filePath + "| grep " + searchContent
    fmt.Println("scriptStr: ", scriptStr)
    return strings.Split(util.RunScript(scriptStr), "\n")[0]
}
 
//启动服务
func StartServer(scriptPath string) {
    //fmt.Println("sh " + scriptPath + "/" + StartServerScript)
    util.RunScript("sh " + scriptPath + "/" + config.StartServerScript)
}
 
//停止服务
func StopServer(scriptPath string) {
    //fmt.Println("sh " + scriptPath + "/" + StopServerScript)
    util.RunScript("sh " + scriptPath + "/" + config.StopServerScript)
}