1
- #! /usr/ bin/env bash
1
+ #! /bin/sh
2
2
3
- set +e # Disable exit on error
3
+ # Disable exit on error
4
+ set +e
4
5
5
6
# Check if PID is provided
6
7
if [ -z " $1 " ]; then
@@ -16,45 +17,56 @@ if [ -z "$1" ]; then
16
17
exit 0
17
18
fi
18
19
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)
20
22
PID=$1
21
23
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
+
24
28
configFile=" ${HERE} /${scriptName} _pid${PID} .cfg"
25
29
if [ ! -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
28
32
fi
29
33
34
+ # Initialize config values
35
+ config_agent=" "
36
+ config_hs_err=" "
37
+ config_java_home=" "
38
+
30
39
# 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
34
40
while 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
36
46
done < " $configFile "
37
47
38
48
# 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
42
52
fi
43
53
44
54
# 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 "
48
58
echo " PID: $PID "
49
59
50
60
# 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 "
52
62
RC=$?
53
- rm -f " ${configFile} " # Remove the configuration file
54
63
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"
57
69
else
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 "
60
72
fi
0 commit comments