aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarehbein <arehbein@sysmocom.de>2022-11-13 14:24:30 +0100
committerarehbein <arehbein@sysmocom.de>2022-11-13 14:24:30 +0100
commit103dff282db44ea6b492c5b175b81688fb5e09c9 (patch)
tree8bd364ef9a6279d00ad2fa6a69a1afdf14c03f69
parent579055bc211feb7ba172b222e01685048bd20ffb (diff)
WIP: dumpcap-start/stop: Make script fail, not hang on sudo promptarehbein/ttcn3-dumpcap-changes
- Also: Fix output of '-e' option in pure POSIX shell Change-Id: Id160384bf624a4eb0f419cb8ba07d8b69bb693f3
-rwxr-xr-xttcn3-dumpcap-start.sh16
-rwxr-xr-xttcn3-dumpcap-stop.sh19
2 files changed, 23 insertions, 12 deletions
diff --git a/ttcn3-dumpcap-start.sh b/ttcn3-dumpcap-start.sh
index eb390fdd..c4ead8c3 100755
--- a/ttcn3-dumpcap-start.sh
+++ b/ttcn3-dumpcap-start.sh
@@ -13,9 +13,21 @@ GSMTAP_PORT=4729
TESTCASE=$1
+if ! [ "$(id -u)" = "0" ]; then
+ SUDOSTR="sudo -n"
+ # Check if sudo /usr/bin/kill, sudo /usr/bin/tcpdump can always be run without password prompt (otherwise this script may hang)
+ sudo -k
+ if ! (sudo -n echo test >/dev/null 2>&1); then
+ echo "Error: Make sure 'sudo /usr/bin/kill' and 'sudo /usr/bin/tcpdump' can be executed without a password (NOPASSWD in sudoers file)" >&2
+ exit 1
+ fi
+else
+ SUDOSTR=""
+fi
+
kill_rm_pidfile() {
- if [ -e $1 ]; then
- kill "$(cat "$1")"
+ if ! [ -e "$1" ] && [ -s "$1" ]; then
+ $SUDOSTR kill "$(cat "$1")" 2>&1 || grep -v "No such process"
rm $1
fi
}
diff --git a/ttcn3-dumpcap-stop.sh b/ttcn3-dumpcap-stop.sh
index e13fbc0f..64f261a3 100755
--- a/ttcn3-dumpcap-stop.sh
+++ b/ttcn3-dumpcap-stop.sh
@@ -5,18 +5,17 @@ PIDFILE_NETCAT=/tmp/netcat.pid
TESTCASE=$1
VERDICT="$2"
+if ! [ "$(id -u)" = "0" ]; then
+ SUDOSTR="sudo -n"
+else
+ SUDOSTR=""
+fi
+
kill_rm_pidfile() {
-if [ -e $1 ]; then
- PSNAME="$(ps -q "$(cat "$1")" -o comm=)"
- if [ "$PSNAME" != "sudo" ]; then
- kill "$(cat "$1")"
- else
- # NOTE: This requires you to be root or something like
- # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
- sudo kill "$(cat "$1")"
+ if ! [ -e "$1" ] && [ -s "$1" ]; then
+ $SUDOSTR kill "$(cat "$1")" 2>&1 || grep -v "No such process"
+ rm $1
fi
- rm $1
-fi
}
date