#155·script

Unable to automatically enter password through pipeline

Author: liumou-siteCreated Dec 8, 2022Updated Dec 15, 2022

`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