1
Objectives
Programming in a shell scripting language is an essential ability for Systems Administrators
who administer UNIX or UNIX-typed systems such as LINUX. This assignment provides an
opportunity for you to show your ability in understanding shell scripts which perform a real
task.
Part A (30 marks)
The BASH shell script shown on next page named a1-partA_11T1 is an old version of bash
shell script called vncserver. The vncserver was used to start or stop a virtual network
computing (VNC) desktop. Your task to create an annotated explanation of this shell script
which provides a detailed description of what each line of this shell script does. The shell
script file can be downloaded from the course website.
For example, the first command line in the script is
#!/bin/bash
This line tells your system to run the shell script by using bash
environment and should be the first line of the shell script. It simply tells
the shell which interpreter to use to run this script. Just in case you do not
have bash as your standard shell.
Assessment criteria for Part A
30 marks have been given to this part and will be assigned in the following ways:
25 to 30 marks : A very good and in depth explanation of the shell script. Shows good
understanding of all the material.
20 to 25 marks : Has a few misunderstandings or explanations that aren’t quite up to scratch.
15 to 20 marks :Passable solutions, a few mistakes, some major and not very descriptive.
10 to 15 marks :Major problems. Does not demonstrate a good understanding of the
material.
Less than 10 : Essentially nothing correct.
1 #!/bin/bash
2 #
3 # chkconfig: - 91 35
4
5 # description: Starts and stops vncserver. \
6 # used to provide remote X administration services.
7
8 # Source function library.
9 . /etc/init.d/functions
10
11 # Source networking configuration.
12 . /etc/sysconfig/network
13
14 # Check that networking is up.
15 [ ${NETWORKING} = "no" ] && exit 0
16
17 VNCSERVERS=""
18 [ -f /etc/sysconfig/vncservers ] && . /etc/sysconfig/vncservers
19
20 prog=$"VNC server"
21
22 start() {
23 echo -n $"Starting $prog: "
24 ulimit -S -c 0 >/dev/null 2>&1
25 RETVAL=0
26 for display in ${VNCSERVERS}
27 do
28 echo -n "${display} "
29 unset BASH_ENV ENV
30 WIDTH_HEIGHT="640x480"
31 initlog $INITLOG_ARGS -c \
32 "su ${display##*:} -c \"cd ~${display##*:} && [ -f .vnc/passwd ] && vncserver :${display%%:*} -geometry ${WIDTH_HEIGHT} -depth 15 \""
33 RETVAL=$?
34 [ "$RETVAL" -ne 0 ] && break
35 done
36 [ "$RETVAL" -eq 0 ] && success $"vncserver startup" || \
37 failure $"vncserver start"
38 echo
39 [ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/vncserver
40 }
41
42 stop() {
43 echo -n $"Shutting down $prog: "
44 for display in ${VNCSERVERS}
45 do
46 echo -n "${display} "
47 unset BASH_ENV ENV
48 initlog $INITLOG_ARGS -c \
49 "su ${display##*:} -c \"vncserver -kill :${display%%:*}\" >/dev/null 2>&1"
50 done
51 RETVAL=$?
52 [ "$RETVAL" -eq 0 ] && success $"vncserver shutdown" || \
53 failure $"vncserver shutdown"
54 echo
55 [ "$RETVAL" -eq 0 ] && rm -f /var/lock/subsys/vncserver
56 }
57
58 # See how we were called.
59 case "$1" in
60 start)
61 start
62 ;;
63 stop)
64 stop
65 ;;
66 restart|reload)
67 stop
68 start
69 ;;
70 condrestart)
71 if [ -f /var/lock/subsys/vncserver ]; then
72 stop
73 start
74 fi
75 ;;
76 status)
77 status Xvnc
78 ;;
79 *)
80 echo $"Usage: $0 {start|stop|restart|condrestart|status}"
81 exit 1
82 esac
Part B (10 marks)
As a System Administrator, you will easily come across shell scripts written by former
employees that have typos, bugs, or logical errors. A BASH shell script on next page named
a1-partB_11T1 shows how to create links (either hard or symbolic links) to files from
different directories into the current directory. It can save space by not duplicating the
contents of the files. However, the script does not work as it has ten (10) mis