save-sensors-data argument (#52)
This commit is contained in:
parent
76e28b9d7c
commit
d13d02ab36
@ -26,6 +26,10 @@ BACKUP_DIR="$SCRIPT_CWD/backup"
|
||||
pvemanagerlibjs="/usr/share/pve-manager/js/pvemanagerlib.js"
|
||||
nodespm="/usr/share/perl5/PVE/API2/Nodes.pm"
|
||||
|
||||
# Debug location
|
||||
DEBUG_SAVE_PATH="$SCRIPT_CWD"
|
||||
DEBUG_SAVE_FILENAME="sensorsdata.json"
|
||||
|
||||
###############################################
|
||||
|
||||
# Helper functions
|
||||
@ -54,7 +58,7 @@ function err {
|
||||
|
||||
# Function to display usage information
|
||||
function usage {
|
||||
msgb "\nUsage:\n$0 [install | uninstall]\n"
|
||||
msgb "\nUsage:\n$0 [install | uninstall | save-sensors-data]\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -768,6 +772,35 @@ function restart_proxy {
|
||||
systemctl restart pveproxy
|
||||
}
|
||||
|
||||
function save_sensors_data {
|
||||
# Check if DEBUG_SAVE_PATH exists and is writable
|
||||
if [[ ! -d "$DEBUG_SAVE_PATH" || ! -w "$DEBUG_SAVE_PATH" ]]; then
|
||||
err "Directory $DEBUG_SAVE_PATH does not exist or is not writable. No file could be saved"
|
||||
return
|
||||
fi
|
||||
|
||||
# Check if command exists
|
||||
if (command -v sensors &>/dev/null); then
|
||||
# Save sensors output
|
||||
local filepath="${DEBUG_SAVE_PATH}/${DEBUG_SAVE_FILENAME}"
|
||||
echo "Sensors data will be saved in $filepath"
|
||||
|
||||
# Prompt user for confirmation
|
||||
read -p "Do you wish to continue? (y/n): " choice
|
||||
case "$choice" in
|
||||
y|Y )
|
||||
sensors -j > "$filepath"
|
||||
msgb "Sensors data saved in $filepath"
|
||||
;;
|
||||
* )
|
||||
echo "Operation cancelled by user."
|
||||
;;
|
||||
esac
|
||||
else
|
||||
err "Sensors is not installed. No file could be saved"
|
||||
fi
|
||||
}
|
||||
|
||||
# Process the arguments using a while loop and a case statement
|
||||
executed=0
|
||||
while [[ $# -gt 0 ]]; do
|
||||
@ -785,6 +818,12 @@ while [[ $# -gt 0 ]]; do
|
||||
uninstall_mod
|
||||
echo # add a new line
|
||||
;;
|
||||
save-sensors-data)
|
||||
executed=$(($executed + 1))
|
||||
msgb "\nSaving current sensor readings in a file for debugging..."
|
||||
save_sensors_data
|
||||
echo # add a new line
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
Loading…
Reference in New Issue
Block a user