File: atop.daily

package info (click to toggle)
atop 2.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,692 kB
  • sloc: ansic: 20,731; python: 253; sh: 220; makefile: 170
file content (66 lines) | stat: -rwxr-xr-x 1,519 bytes parent folder | download
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
#!/bin/bash
# this is called - on sysvinit systems - at midnight by cron
# on systemd systems this is called from the systemd unit

LOGOPTS="-R"				# default options
LOGINTERVAL=600				# default interval in seconds
LOGGENERATIONS=28			# default number of days

# allow administrator to overrule the variables
# defined above
#
DEFAULTSFILE=/etc/default/atop		# possibility to overrule vars

if [ -e "$DEFAULTSFILE" ]
then
	. "$DEFAULTSFILE"

	# validate overruled variables
	# (LOGOPTS and LOGINTERVAL are implicitly by atop)
	#
 	case "$LOGGENERATIONS" in
	    ''|*[!0-9]*)
		echo non-numerical value for LOGGENERATIONS >&2
		exit 1;;
	esac
fi

CURDAY=`date +%Y%m%d`
LOGPATH=/var/log/atop
BINPATH=/usr/bin
PIDFILE=/run/atop.pid

# verify if atop still runs for daily logging
#
if [ -e "$PIDFILE" ] && ps -p `cat "$PIDFILE"` | grep 'atop$' > /dev/null
then
	kill -USR2 `cat "$PIDFILE"`       # final sample and terminate

	CNT=0

	while ps -p `cat "$PIDFILE"` > /dev/null
	do
		let CNT+=1

		if [ $CNT -gt 5 ]
		then
			break;
		fi

		sleep 1
	done

	rm "$PIDFILE"
fi

# delete logfiles older than N days (configurable)
# start a child shell that activates another child shell in
# the background to avoid a zombie
#
( (sleep 3; find "$LOGPATH" -name 'atop_*' -mtime +"$LOGGENERATIONS" -exec rm {} \;)& )

# activate atop with an interval of S seconds (configurable),
# replacing the current shell
#
echo $$ > $PIDFILE
exec $BINPATH/atop $LOGOPTS -w "$LOGPATH"/atop_"$CURDAY" "$LOGINTERVAL" > "$LOGPATH/daily.log" 2>&1