1- #! /usr/ bin/env bash
1+ #! /bin/sh
22
3- set +e # Disable exit on error
3+ # Disable exit on error
4+ set +e
45
56# Check if PID is provided
67if [ -z " $1 " ]; then
@@ -16,45 +17,56 @@ if [ -z "$1" ]; then
1617 exit 0
1718fi
1819
19- HERE=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) " # Get the directory of the script
20+ # Get the directory of the script
21+ HERE=$( cd " $( dirname " $0 " ) " > /dev/null 2>&1 && pwd)
2022PID=$1
2123
22- # Get the base name of the script
23- scriptName=$( basename " $0 " .sh)
24+ # Get the base name of the script (without .sh)
25+ scriptName=$( basename " $0 " )
26+ scriptName=${scriptName% .sh}
27+
2428configFile=" ${HERE} /${scriptName} _pid${PID} .cfg"
2529if [ ! -f " $configFile " ]; then
26- echo " Error: Configuration file not found: $configFile "
27- exit 1
30+ echo " Error: Configuration file not found: $configFile "
31+ exit 1
2832fi
2933
34+ # Initialize config values
35+ config_agent=" "
36+ config_hs_err=" "
37+ config_java_home=" "
38+
3039# Read the configuration file
31- # The expected contents are:
32- # - agent: Path to the agent jar
33- # - hs_err: Path to the hs_err log file
3440while IFS=" =" read -r key value; do
35- declare " config_$key " =" $value "
41+ case " $key " in
42+ agent) config_agent=$value ;;
43+ hs_err) config_hs_err=$value ;;
44+ java_home) config_java_home=$value ;;
45+ esac
3646done < " $configFile "
3747
3848# Exiting early if configuration is missing
39- if [ -z " ${ config_agent} " ] || [ -z " ${ config_hs_err} " ] || [ -z " ${ config_java_home} " ]; then
40- echo " Error: Missing configuration"
41- exit 1
49+ if [ -z " $config_agent " ] || [ -z " $config_hs_err " ] || [ -z " $config_java_home " ]; then
50+ echo " Error: Missing configuration"
51+ exit 1
4252fi
4353
4454# Debug: Print the loaded values (Optional)
45- echo " Agent Jar: ${ config_agent} "
46- echo " Error Log: ${ config_hs_err} "
47- echo " JAVA_HOME: ${ config_java_home} "
55+ echo " Agent Jar: $config_agent "
56+ echo " Error Log: $config_hs_err "
57+ echo " JAVA_HOME: $config_java_home "
4858echo " PID: $PID "
4959
5060# Execute the Java command with the loaded values
51- " ${ config_java_home} /bin/java" -jar " ${ config_agent} " uploadCrash " ${ config_hs_err} "
61+ " $config_java_home /bin/java" -jar " $config_agent " uploadCrash " $config_hs_err "
5262RC=$?
53- rm -f " ${configFile} " # Remove the configuration file
5463
55- if [ $RC -eq 0 ]; then
56- echo " Error file ${config_hs_err} was uploaded successfully"
64+ # Remove the configuration file
65+ rm -f " $configFile "
66+
67+ if [ " $RC " -eq 0 ]; then
68+ echo " Error file $config_hs_err was uploaded successfully"
5769else
58- echo " Error: Failed to upload error file ${ config_hs_err} "
59- exit $RC
70+ echo " Error: Failed to upload error file $config_hs_err "
71+ exit " $RC "
6072fi
0 commit comments