forked from jackyaz/scMerlin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtailtop
More file actions
36 lines (30 loc) · 1015 Bytes
/
tailtop
File metadata and controls
36 lines (30 loc) · 1015 Bytes
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
#!/bin/sh
######################################################
# Last Modified: 2026-Apr-11
#-----------------------------------------------------
# shellcheck disable=SC2039
#-----------------------------------------------------
trap '' SIGHUP
renice 15 $$
# Give priority to built-in binaries #
export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
if [ $# -eq 0 ] || [ -z "$1" ] || \
! echo "$1" | grep -qE "^([1-9][0-9]{0,2})$"
then sleepSecs=60
else sleepSecs="$1"
fi
while true
do
top -b -n 1 | tail -n +5 | head -n -1 | sed 's/S </S</g;s/S N/SN/g;s/S D/SD/g;s/R N/RN/g;' | \
awk -F" " -v OFS=',' '{if ($5 ~ /m[^\s\\]/){
printf "%s,%s,%s,%s,%s,%s,%s,", $1,$2,$3,$4,gensub(/m([^\s\\])/,"m,\\1","g",$5),$6,$7;for(i=8; i<=NF; ++i) printf "%s ", $i; print ""
}
else{
printf "%s,%s,%s,%s,%s,%s,%s,%s,", $1,$2,$3,$4,$5,$6,$7,$8;for(i=9; i<=NF; ++i) printf "%s ", $i; print ""
}
}' | \
sed 's/,$//g;s/S</S </g;s/SN/S N/g;s/SD/S D/g;s/RN/R N/g;' > /tmp/scmerlin-top
sleep "$sleepSecs"
done
renice 0 $$
#EOF#