Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to automatically enter password through pipeline #155

Open
liumou-site opened this issue Dec 8, 2022 · 1 comment
Open

Unable to automatically enter password through pipeline #155

liumou-site opened this issue Dec 8, 2022 · 1 comment

Comments

@liumou-site
Copy link

`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

@ifraixedes
Copy link

This is working for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants