executeScript function
This commit is contained in:
parent
d9e1e20afc
commit
4d8bf6e0d5
34
cmd/utils.go
34
cmd/utils.go
@ -13,6 +13,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"github.com/google/shlex"
|
||||||
"github.com/c2h5oh/datasize"
|
"github.com/c2h5oh/datasize"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -216,6 +217,39 @@ func executeCommandInJail(jail *Jail, cmdline string) (string, error) {
|
|||||||
return string(out), err
|
return string(out), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************************************
|
||||||
|
* Execute a script, or shell command. Need to double escape special characters
|
||||||
|
* Ex.: executeScript("echo '\\\\_o\\< \\~ COINCOIN' > /tmp/coincoin.txt")
|
||||||
|
*******************************************************************************/
|
||||||
|
func executeScript(script string) (string, error) {
|
||||||
|
var cmd []string
|
||||||
|
var out []byte
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if gUseSudo {
|
||||||
|
cmd = append(cmd, "sudo")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = append(cmd, []string{"/bin/sh", "-c"}...)
|
||||||
|
|
||||||
|
s, err := shlex.Split(script)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
cmd = append(cmd, strings.Join(s, " "))
|
||||||
|
|
||||||
|
//fmt.Printf("DEBUG: Prepare to execute %v\n", cmd)
|
||||||
|
|
||||||
|
if len(cmd) > 1 {
|
||||||
|
out, err = exec.Command(cmd[0], cmd[1:]...).CombinedOutput()
|
||||||
|
} else {
|
||||||
|
out, err = exec.Command(cmd[0]).CombinedOutput()
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(out), err
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* ZFS datasets/pools operations
|
* ZFS datasets/pools operations
|
||||||
|
Loading…
Reference in New Issue
Block a user