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.
51 lines
2.1 KiB
51 lines
2.1 KiB
#! /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 " -d dummy; just check if screensaver graphic program is running and exit." |
|
echo " -h display this output" |
|
exit 1 |
|
} |
|
|
|
while getopts ':u:dh' 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 |
|
;; |
|
d) dummy='true';; |
|
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_program_name=`cat "$homedir/.xscreensaver" | awk "$regex && ++n == "$selected_graphic_nr" {getline; print; exit}" | cut -f 5 | cut -d ' ' -f 1 ` |
|
[ -z "$graphic_program_name" ] && { echo Could not find selected graphic application && exit 1; } |
|
echo "graphic_program: $graphic_program_name" |
|
|
|
graphic_processes=`ps -U "$username" | grep "$graphic_program_name" | awk '{$1=$1};1' | cut -d ' ' -f 1 | tr '\n' ' ' ` || { echo "No screensaver graphic processes were found for $username" && exit 0; } |
|
[ -z "$graphic_processes" ] && { echo "No xscreensaver graphic processes seem to be running for $username" && exit 0; } |
|
echo "graphic_processes: $graphic_processes" |
|
[ "$dummy" = 'true' ] && exit 0 |
|
process_count=`echo $graphic_processes | wc -w` |
|
kill $graphic_processes && echo "killed $process_count screensaver graphic processes for $username" |
|
sleep 1 |
|
for pid in `ps -U "$username" | grep "$graphic_program_name" | awk '{$1=$1};1' | cut -d ' ' -f 1`; do |
|
echo "Grahpic with PID $pid didn't exit, sending SIGKILL" |
|
kill -9 "$pid" |
|
done |
|
|
|
|