This commit is contained in:
2026-04-04 00:09:02 +08:00
commit 38e896363e
117 changed files with 119311 additions and 0 deletions

56
work_tests/main.go Normal file
View File

@@ -0,0 +1,56 @@
package main
import (
"fmt"
"log"
"os"
"strings"
)
type outputStruct struct {
RootHistory []rootHistoryCommand `json:"root_history_command"`
}
type rootHistoryCommand struct {
Id int `json:"id"`
ExecutionTime string `json:"excution_time"`
Command string `json:"command"`
}
func main() {
var o outputStruct
var err error
o.RootHistory, err = getRootHistory()
if err != nil {
log.Fatalln(err)
}
for _, rh := range o.RootHistory {
fmt.Printf("%d %s %s\n", rh.Id, rh.ExecutionTime, rh.Command)
}
}
func getRootHistory() ([]rootHistoryCommand, error) {
var rootHistoryCommands []rootHistoryCommand
rawHistory, err := os.ReadFile("/home/kbn/.bash_history")
if err != nil {
err = fmt.Errorf("Ошибка при открытии файла /home/kbn/.bash_history : %s", err.Error())
return nil, err
}
i := 0
execTime := ""
for _, line := range strings.Split(string(rawHistory), "\n") {
var c rootHistoryCommand
if strings.HasPrefix(line, "#") {
execTime = strings.TrimLeft(line, "#")
} else {
c.Id = i
i += 1
c.ExecutionTime = execTime
c.Command = line
execTime = ""
rootHistoryCommands = append(rootHistoryCommands, c)
}
}
return rootHistoryCommands, err
}