#!/bin/bash # Shell script to display ps for specified user or for user who runs # the script (when no argument is given). # Version 4.2 - Enhanced to deselect scriptname, bash process from script and # options in output. # Version 4.3 - Filter user with option 'u'. # Version 4.4 - Add option to show threads. # Version 4.5 - Add option to show only background processes. # ------------------------------------------------------------------------- # Author R.W.H. Vermare 2008 - 2022 - # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of the Doctor Linux collection # ------------------------------------------------------------------------- BIN=${0##*/} help_function(){ echo "Usage: $BIN : Displays all processes from current user." echo " $BIN : Displays all given processes." echo " $BIN b : Displays all specified background processes." echo " $BIN t : Displays all given processes and threads." echo " $BIN u : Displays all specified processes for" echo " current user." } [ "$1" != "" ]; if [ -z "$1" ] then user=`whoami` ps axu | grep $(whoami) | sed '/'$BIN'/d' | sed '/grep '$user'/d' | sed '/ps axu/d' elif [ "$1" = "-help" ]; then help_function elif [ "$1" = "u" ]; then [ "$2" != "" ]; if [ -z "$2" ] then help_function else ps -U $(whoami) -u $(whoami) u | grep $2 | sed '/'$BIN' u '$2'/d' | sed '/grep '$2'/d' fi elif [ "$1" = "t" ]; then [ "$2" != "" ]; if [ -z "$2" ] then help_function else ps -eLf | grep $2 | sed '/'$BIN' t '$2'/d' | sed '/grep '$2'/d' fi elif [ "$1" = "b" ]; then [ "$2" != "" ]; if [ -z "$2" ] then help_function else ps axu | grep $2 | sed '/'$BIN' b '$2'/d' | sed '/grep '$2'/d' | sed '/pts\//d' fi else ps axu | grep $1 | sed '/'$BIN' '$1'/d' | sed '/grep '$1'/d' exit 0 fi