fix: avoid sed interpolation when prepending log summary
Use a temporary file to write the summary header and existing log content, then replace the original log atomically. This removes the dependency on sed for summary insertion and avoids unsafe string interpolation.
This commit is contained in:
+18
-4
@@ -10,7 +10,7 @@ showHelp() {
|
||||
}
|
||||
|
||||
checkDependencies() {
|
||||
local -a REQUIRED_CMDS=(ssh whiptail sed tee rm touch)
|
||||
local -a REQUIRED_CMDS=(ssh whiptail cat tee rm touch)
|
||||
local -a MISSING_CMDS=()
|
||||
local CMD
|
||||
|
||||
@@ -84,6 +84,22 @@ runSSH() {
|
||||
ssh "${SSH_USER}@${HOST}" "$@"
|
||||
}
|
||||
|
||||
prependLogSummary() {
|
||||
local SUMMARY_CONTENT="${1}"
|
||||
local TEMP_LOGFILENAME="${LOGFILENAME}.tmp"
|
||||
|
||||
{
|
||||
echo "Results :"
|
||||
echo "---------"
|
||||
echo ""
|
||||
echo -e "${SUMMARY_CONTENT}"
|
||||
echo ""
|
||||
echo ""
|
||||
cat "${LOGFILENAME}"
|
||||
} > "${TEMP_LOGFILENAME}"
|
||||
mv "${TEMP_LOGFILENAME}" "${LOGFILENAME}"
|
||||
}
|
||||
|
||||
selectNodes(){
|
||||
local -a OPTIONS=()
|
||||
local -a SELECTED_ITEMS=()
|
||||
@@ -152,9 +168,7 @@ selectNodes(){
|
||||
done
|
||||
done
|
||||
|
||||
sed -i "1s/^/${RESULT//\//\\\/}\n\n\n\n/" "${LOGFILENAME}"
|
||||
sed -i "1s/^/---------\n\n/" "${LOGFILENAME}"
|
||||
sed -i "1s/^/Results :\n/" "${LOGFILENAME}"
|
||||
prependLogSummary "${RESULT}"
|
||||
if [ -n "${LOGVIEWER}" ]; then
|
||||
"${LOGVIEWER}" "${LOGFILENAME}"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user