From d1f88363c1b088d02e5cf59d5eae4771063f074b Mon Sep 17 00:00:00 2001 From: SukkaW Date: Mon, 15 Jan 2024 16:36:31 +0800 Subject: [PATCH] Write log to tmpfs when avaliable --- hetrixtools_agent.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hetrixtools_agent.sh b/hetrixtools_agent.sh index 4f9a0d7..44421e1 100644 --- a/hetrixtools_agent.sh +++ b/hetrixtools_agent.sh @@ -651,8 +651,22 @@ json='{"version":"'"$Version"'","SID":"'"$SID"'","agent":"0","user":"'"$User"'", # Compress payload jsoncomp=$(echo -ne "$json" | gzip -cf | base64 -w 0 | sed 's/ //g' | sed 's/\//%2F/g' | sed 's/+/%2B/g') +# Set hetrixtools path +HetrixAgentLogPath="$ScriptPath/hetrixtools_agent.log" +# Get data path +if [ -d "/run" ] +then + # On newer Linux, tmpfs is mounted at /run + HetrixAgentLogPath="/run/hetrixtools_agent.log" +elif [ -d "/var/run" ] +then + # On older Linux, tmpfs is mounted at /var/run + HetrixAgentLogPath="/var/run/hetrixtools_agent.log" +fi +# The default path /run/hetrixtools_agent.log will be used if both /run and /var/run are missing + # Save data to file -echo "j=$jsoncomp" > "$ScriptPath"/hetrixtools_agent.log +echo "j=$jsoncomp" > $HetrixAgentLogPath # Post data -wget --retry-connrefused --waitretry=1 -t 3 -T 15 -qO- --post-file="$ScriptPath/hetrixtools_agent.log" "$SecuredConnection" https://sm.hetrixtools.net/v2/ &> /dev/null +wget --retry-connrefused --waitretry=1 -t 3 -T 15 -qO- --post-file="$HetrixAgentLogPath" "$SecuredConnection" https://sm.hetrixtools.net/v2/ &> /dev/null