-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcollect_service_logs.sh
executable file
·116 lines (115 loc) · 3.23 KB
/
collect_service_logs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
# Copyright (C) 2024 LEIDOS.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#######################################
# Prints the script's argument descriptions
# Globals:
# None
# Arguments:
# None
# Returns:
# 0
#######################################
set -e
function print_help() {
command cat <<-HELP
options:
-h, --help Show usage
--output, -o Name of the resulting zip file container CARMA Streets Service logs
--clear, -c Adding this flag will delete log directories after creating zip.
HELP
}
#######################################
# Prints a string to standard error
# Globals:
# None
# Arguments:
# String to print
# Returns:
# 0
#######################################
function err() {
echo "$*" >&2
}
#######################################
# Prints the script's usage
# Globals:
# None
# Arguments:
# None
# Returns:
# 0
#######################################
function print_usage() {
command cat <<-USAGE
usage: collect_service_logs.sh [-h | --help] [--output <zip_file_name>.zip]
[-c | --clear]
USAGE
}
#######################################
# Collects all service logs files and zips them into an archive and then configurable removes the source files.
# Globals:
# None
# Arguments:
# None
# Returns:
# 0
#######################################
function main() {
while :; do
case "$1" in
-h|--help)
print_usage
echo ""
print_help
exit 0
;;
-c|--clear)
echo "Clearing log directories after zip file is created!"
clear=true
;;
--output|-o)
shift
if [ "$#" -eq 0 ]; then
err "error: option 'output' requires a value"
print_usage
exit 129
fi
output="$1"
;;
*)
if [[ "$1" == -* ]]; then
err "unknown option '$1'"
print_usage
exit 129
fi
break
esac
shift
done
if [ "$output" ];
then
echo "Writing zip file ${output}.zip"
zip -rq ./"${output}".zip ./scheduling_service/logs ./intersection_model/logs ./tsc_client_service/logs ./message_services/logs ./signal_opt_service/logs ./sensor_data_sharing_service/logs
else
filename=$(date "+%FT%H%M%S")
echo "Writing zip file ${filename}.zip"
zip -rq ./"${filename}".zip ./scheduling_service/logs ./intersection_model/logs ./tsc_client_service/logs ./message_services/logs ./signal_opt_service/logs ./sensor_data_sharing_service/logs
fi
if [ "$clear" = true ];
then
rm ./scheduling_service/logs/* ./intersection_model/logs/* ./tsc_client_service/logs/* ./message_services/logs/* ./signal_opt_service/logs/* ./sensor_data_sharing_service/logs/*
fi
}
main "$@"