1#!/bin/sh -e 2# 3# users: print the number of remote users on the machine 4# 5# Copyright (C) 2009 Raphaël Pinson. 6# Copyright (C) 2009 Canonical Ltd. 7# Copyright (C) 2011-2014 Dustin Kirkland 8# 9# Authors: Raphaël Pinson <raphink@ubuntu.com> 10# Dustin Kirkland <kirkland@byobu.org> 11# 12# This program is free software: you can redistribute it and/or modify 13# it under the terms of the GNU General Public License as published by 14# the Free Software Foundation, version 3 of the License. 15# 16# This program is distributed in the hope that it will be useful, 17# but WITHOUT ANY WARRANTY; without even the implied warranty of 18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19# GNU General Public License for more details. 20# 21# You should have received a copy of the GNU General Public License 22# along with this program. If not, see <http://www.gnu.org/licenses/>. 23 24__users_detail() { 25 ps -ef 2>/dev/null | grep "sshd:.*@" | grep -v grep 26} 27 28__users() { 29 local count=0 30 if [ "$USERS_DISTINCT" = "1" ]; then 31 count=$(pgrep -fl 'sshd:.*@' | cut -f3 -d\ | cut -f1 -d@ | sort -u | wc -l) 32 else 33 # Note: we'd like to use pgrep -c, however, this isn't available in 34 # busybox and some distro's pgrep (and it doesn't exit non-zero). 35 count=$(pgrep -f "^sshd:.*@|^/usr/sbin/sshd -i" | wc -l) || return 36 fi 37 if [ $count -gt 0 ]; then 38 color b w r; printf "%d" "$count"; color -; color w r; printf "##"; color -- 39 else 40 rm -f "$BYOBU_RUN_DIR/status.$BYOBU_BACKEND/users"* 41 fi 42} 43 44# vi: syntax=sh ts=4 noexpandtab 45