You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.8 KiB
42 lines
1.8 KiB
4 years ago
|
#! /bin/bash
|
||
|
|
||
|
function help () {
|
||
|
echo "Usage: $0 [OPTIONS] <file>"
|
||
|
echo "Cleans up xscreensaver graphic programs left behind after killing xscreensaver itself."
|
||
|
echo " -u specify a username for which to kill xscreensaver artifacts"
|
||
|
echo " -h display this output"
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
while getopts ':u:' opt ; do
|
||
|
case "$opt" in
|
||
|
u)
|
||
|
username="${OPTARG}"
|
||
|
userid=`id -u "$username" 2>/dev/null` || { echo "$username is not a user on this system" && exit 1 ;}
|
||
|
[ "$userid" -lt 1000 ] && echo "User $username seems to be a systemuser (uid: $userid). Please specify a normal user." && exit 1
|
||
|
;;
|
||
|
h) help ;;
|
||
|
:)
|
||
|
echo "$0: Must supply an argument to -$OPTARG." >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
?)
|
||
|
echo "Invalid option: -${OPTARG}."
|
||
|
exit 2
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
username="${username:-$USER}"
|
||
|
homedir=`eval echo "~$username"`
|
||
|
selected_graphic_nr=`grep selected "$homedir/.xscreensaver" | cut -f 2`
|
||
|
regex='/\\n\\/'
|
||
|
graphic_process_name=`cat "$homedir/.xscreensaver" | awk "$regex && ++n == "$selected_graphic_nr" {getline; print; exit}" | cut -f 5 | cut -d ' ' -f 1 `
|
||
|
echo "graphic_process_name: $graphic_process_name"
|
||
|
[ -z "$graphic_process_name" ] && { echo Could not find selected graphic application && exit 1; }
|
||
|
graphic_processes=`ps -U "$username" | grep "$graphic_process_name" | awk '{$1=$1};1' | cut -d ' ' -f 1 | tr '\n' ' ' ` || { echo "No screensaver graphic processes were found for $username" && exit 0; }
|
||
|
echo "graphic_processes: $graphic_processes"
|
||
|
[ -z "$graphic_processes" ] && { echo "No xscreensaver graphic processes seem to be running for $username" && exit 0; }
|
||
|
process_count=`echo $graphic_processes | wc -w`
|
||
|
kill $graphic_processes && echo "killed $process_count screensaver graphic processes for $username"
|