-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstop_monitor.sh
executable file
·33 lines (28 loc) · 969 Bytes
/
stop_monitor.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
#!/bin/bash
[ "$#" -lt "2" ] && echo Usage: "$0 MONITOR HOSTNAME [TARGET_FN]" && exit 1
MONITOR=$1
HOST=$2
[ $MONITOR == "ocount" ] && PREFIX="sudo"
[ $MONITOR == "perf" ] && PREFIX="sudo"
[ $MONITOR == "operf" ] && PREFIX="sudo"
[ $MONITOR == "gpu" ] && MONITOR="nvidia-smi"
if [ "$HOST" == "$(hostname)" ] || [ "$HOST" == "$(hostname -s)" ]
then
# run locally
PIDS=$(pgrep $MONITOR)
PIDS=$(echo $PIDS | perl -pe "s/$$//") # $$ is the PID of this script
$PREFIX kill $PIDS # killall didn't work here
else
# use ssh. Retrieve file from /tmp directory
#ssh $HOST "$PREFIX killall -SIGINT $MONITOR"
ssh $HOST "$PREFIX pkill $MONITOR"
if [ "$#" -eq "3" ]
then
TARGET_FN=$3
REMOTE_FN=/tmp/${USER}/pid_monitor/$(basename $3)
echo Copying $MONITOR data from $HOST:$REMOTE_FN to $TARGET_FN
scp -r $HOST:$REMOTE_FN $TARGET_FN
[ "$?" -eq 0 ] && ssh $HOST "$PREFIX rm $REMOTE_FN"
fi
fi
echo Successfully stopped $MONITOR on $HOST