Skip to content

Unable to automatically enter password through pipeline #155

Description

@liumou-site

`liumou@liumou-PC:~/LinuxData/git/golang/dmeo$ cat demos.go
package main

import (
"gitee.com/liumou_site/logger"
"github.com/bitfield/script"
)

func main() {
// file := "/tts"
pd := "1"
c := "sudo -S rm -f /testing"
res, err := script.Args().Echo(pd).ExecForEach(c).Stdout()
logger.Debug("Exit code: ", res)
if err != nil {
logger.Error("Delete failed: ", err)
} else {
logger.Info("Deletion succeeded")
}
}
liumou@liumou-PC:/LinuxData/git/golang/dmeo$ go run demos.go
请输入密码
sudo: no password was provided
exit status 1
2022-12-09 00:10:59 [DEBG] [/home/liumou/LinuxData/git/golang/dmeo/demos.go:13] Exit code: 61
2022-12-09 00:10:59 [INFO] [/home/liumou/LinuxData/git/golang/dmeo/demos.go:17] Deletion succeeded
liumou@liumou-PC:
/LinuxData/git/golang/dmeo$ cat demo.sh
#!/bin/bash
file = "/tts"
password = "demo"
cmd = "rm -f ${file}"
echo $password | sudo -S $cmd
`
How do I handle the shell script function later

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions