serv-log 1.54 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2016, 2020  Etersoft
# Copyright (C) 2016, 2020  Vitaly Lipatov <lav@etersoft.ru>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

20 21 22
__serv_log_altlinux()
{
	local SERVICE="$1"
23 24
	local PRG="less"
	[ "$2" = "-f" ] && PRG="tail -f"
25 26 27

	case "$SERVICE" in
		postfix)
28
			sudocmd $PRG /var/log/mail/all /var/log/mail/errors
29
			;;
30
		sshd)
31
			sudocmd $PRG /var/log/auth/all
32
			;;
33
		cups)
34
			sudocmd $PRG /var/log/cups/access_log /var/log/cups/error_log
35 36
			;;
		fail2ban)
37
			sudocmd $PRG /var/log/$SERVICE.log
38 39 40 41 42 43 44
			;;
		*)
			fatal "Have no suitable for $SERVICE service"
			;;
	esac
}

45 46 47 48 49 50 51
serv_log()
{
	local SERVICE="$1"
	shift

	case $SERVICETYPE in
		systemd)
52
			sudocmd journalctl -b -u "$SERVICE" "$@"
53 54
			;;
		*)
55
			case $DISTRNAME in
56
			ALTLinux|ALTServer)
57 58
				FF="" ; [ "$1" = "-f" ] && FF="-f"
				__serv_log_altlinux "$SERVICE" $FF
59 60 61 62 63
				return ;;
			*)
				fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
				;;
			esac
64 65
	esac
}