[ Agent ] [ CMII ] - 新增大量功能

This commit is contained in:
zeaslity
2024-01-10 15:11:41 +08:00
parent 22faf15665
commit 7ce838289b
10 changed files with 879 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
package executor
import (
"bufio"
"bytes"
"fmt"
"io"
@@ -115,6 +116,40 @@ func BasicGrepItemInFile(item string, fileName string) bool {
return false
}
func BasicFindContentInFile(content string, fileName string) bool {
// Open the file
file, err := os.Open(fileName)
if err != nil {
log.ErrorF("[BasicFindContentInFile] - file not exits ")
return false
}
defer file.Close()
// Create a scanner to read the file line by line
scanner := bufio.NewScanner(file)
// Set the split function for the scanner
scanner.Split(bufio.ScanLines)
// Iterate over the lines of the file
for scanner.Scan() {
// Get the current line
line := scanner.Text()
// Check if the current line contains the search term
if strings.Contains(line, content) {
return true
}
}
// Check for any errors that occurred during scanning
if err := scanner.Err(); err != nil {
log.ErrorF("[BasicFindContentInFile] - scanner error ! %s", err.Error())
}
return false
}
func BasicDockerImageExists(imageName, imageVersion string) bool {
if !BasicCommandExistByPath("docker") {