本帖最后由 imes 于 2022-6-13 11:56 编辑
已经修复,等后续更新即可,已奖励宝塔币300,这三百个宝塔币不知道能干什么,有一半得归功于@flyqie 不知道能不能分出去
附赠一个宝塔的邮件检查程序,自带的mail通知很烦人,用golang重写了命令,解压后chmod +x mail 然后放到/usr/bin/里,任意目录执行mail命令就能查看 算了,loc不能上传程序,就放源码吧
- package main
-
- import (
- "bytes"
- "fmt"
- "os/exec"
- )
-
- //function to execute linux shell command
- func execCommand(command string) (string, error) {
- cmd := exec.Command("/bin/sh", "-c", command)
- var out bytes.Buffer
- cmd.Stdout = &out
- err := cmd.Run()
- return out.String(), err
- }
-
- // main function
- func main() {
- // output notice to user to chose command
- // if input is "check" then execute check command "cat /var/spool/mail/root"
- // elif input is "clean" then execute clean command "cat /dev/null > /var/spool/mail/root"
- // else exit
- println("Please input command: check or clean")
- var command string
- _, err := fmt.Scanln(&command)
- if err != nil {
- println("Error: " + err.Error())
- return
- }
- if command == "check" {
- println("Execute command: cat /var/spool/mail/root")
- out, err := execCommand("cat /var/spool/mail/root")
- if err != nil {
- println("Error: " + err.Error())
- return
- }
- println(out)
- }
- if command == "clean" {
- println("Execute command: cat /dev/null > /var/spool/mail/root")
- out, err := execCommand("cat /dev/null > /var/spool/mail/root")
- if err != nil {
- println("Error: " + err.Error())
- return
- }
- println(out)
- }
- if command != "check" && command != "clean" {
- println("Error: Invalid command")
- return
- }
- }
复制代码
|