Skip to content

Commit 009712e

Browse files
author
Josiah Ritchie
committed
Adding a couple new scripts. vncserver_rc to control tightvncserver on Ubuntu and getswap.sh to show swap space usage by process.
1 parent 8085c81 commit 009712e

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

README.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ This is a little script I tossed together to audit a series of virtual LAMP serv
2121

2222
## getip.sh & getipv6.sh
2323
Simple scripts that returns the IP or IPv6 address of a linux box and nothing but. This can be pretty handy since Linux doesn't provide this info on its own without adding lots of other info.
24+
25+
## vncserver_rc
26+
This is a startup script for tightvncserver on ubuntu capable of handling multiple users. It requires a properly configured /etc/vncservers.conf and each user needs a .vnc/passwd and .vnc/xstartup for their service to startup properly. Manually run 'tightvncserver :1' for each user to do this and then 'tightvncserver -kill :1" to shut the server off. I don't yet have the status stuff working well, but start and stop function just fine. A sample vncservers.conf can also be found in this repo.
27+
28+
## getswap.sh
29+
Reports the swap space usage by Process on a linux box

getswap.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# Get current swap usage for all running processes
3+
# Erik Ljungstrom 27/05/2011
4+
SUM=0
5+
OVERALL=0
6+
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
7+
PID=`echo $DIR | cut -d / -f 3`
8+
PROGNAME=`ps -p $PID -o comm --no-headers`
9+
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
10+
do
11+
let SUM=$SUM+$SWAP
12+
done
13+
echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
14+
let OVERALL=$OVERALL+$SUM
15+
SUM=0
16+
17+
done
18+
echo "Overall swap used: $OVERALL"

vncserver_rc

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash -e
2+
### BEGIN INIT INFO
3+
# Provides: vncserver
4+
# Required-Start: networking
5+
# Default-Start: 3 4 5
6+
# Default-Stop: 0 6
7+
### END INIT INFO
8+
9+
set -e
10+
. /lib/lsb/init-functions
11+
12+
#Does the config file exist, if not halt
13+
[ -f /etc/vncservers.conf ] || { echo "Config file /etc/vncservers.conf does not exist" ; exit 1 ;}
14+
15+
#Prep some variables to received input from the config file
16+
unset VNCSERVERARGS
17+
VNCSERVERS=""
18+
[ -f /etc/vncservers.conf ] && . /etc/vncservers.conf
19+
20+
prog=$"VNC Server"
21+
22+
#### START THE SERVICES ####
23+
start() {
24+
REQ_USER=$2 #Check to see if a specific user's server need to be restarted
25+
26+
27+
echo -n $"Starting $prog: " #This line start the output and it appended below
28+
ulimit -S -c 0 >/dev/null 2>&1
29+
RETVAL=0
30+
31+
for display in ${VNCSERVERS} #iterate over the displays
32+
do
33+
export USER="${display##*:}"
34+
if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
35+
echo "${display} " #appends the display number to the output line
36+
unset BASH_ENV ENV
37+
DISP="${display%%:*}"
38+
export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
39+
su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && tightvncserver :${DISP} ${VNCUSERARGS}" #start a single display
40+
fi
41+
done
42+
}
43+
44+
#### STOP THE SERVICES ####
45+
stop() {
46+
REQ_USER=$2
47+
48+
echo -n $"Shutting down ${prog}: "
49+
50+
for display in ${VNCSERVERS}
51+
do
52+
export USER="${display##*:}"
53+
if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
54+
echo "${display} "
55+
unset BASH_ENV ENV
56+
export USER="${display##*:}"
57+
su ${USER} -c "tightvncserver -kill :${display%%:*}" >/dev/null 2>&1
58+
fi
59+
done
60+
61+
echo -e "${prog} Stopped"
62+
}
63+
64+
#### GET THE SERVICES STATUS ####
65+
status() {
66+
REQ_USER=$2
67+
exitcode=0
68+
69+
if test ${REQ_USER}
70+
then echo "Checking User Service: ${REQ_USER}"
71+
else echo "Checking ${VNCSERVERS}"
72+
fi
73+
74+
for display in ${VNCSERVERS}
75+
do
76+
if test ${REQ_USER}
77+
then status_of_proc -p "/tmp/.X${displayy%%:*}-lock" /usr/bin/Xtightvnc $display && exit 0 || exit $?
78+
else status_of_proc -p "/tmp/.X${displayy%%:*}-lock" /usr/bin/Xtightvnc $display && statuscode=$?
79+
if test $statuscode > $exitcode; then $exitcode=statuscode; fi
80+
fi
81+
done
82+
83+
exit $exitcode
84+
}
85+
86+
# See how we were called.
87+
case "$1" in
88+
start)
89+
start $@
90+
;;
91+
stop)
92+
stop $@
93+
;;
94+
restart|reload)
95+
stop $@
96+
sleep 3
97+
start $@
98+
;;
99+
condrestart)
100+
if [ -f /var/lock/subsys/vncserver ]; then
101+
stop $@
102+
sleep 3
103+
start $@
104+
fi
105+
;;
106+
status)
107+
echo "This doesn't quite work."
108+
status $@
109+
;;
110+
*)
111+
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
112+
exit 1
113+
esac

vncservers.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#NOTE: Before making changes to this file, stop the vncservers, otherwise, they may note start back up properly
2+
3+
# VNCSERVERS is an array of display numbers separated by a colon and then username associated with that display
4+
VNCSERVERS="1:flickerfly 2:josiah 3:jritchie"
5+
6+
# VNC Server preferances can be set by adding the cooresponding argument to the proper line below.
7+
# [1] indicates display 1
8+
VNCSERVERARGS[1]="-geometry 1280x992 -depth 16"
9+
VNCSERVERARGS[2]="-geometry 1024x768 -depth 16"
10+
VNCSERVERARGS[3]="-geometry 1024x768 -depth 16"

0 commit comments

Comments
 (0)