# 2 Notes

• Commands preceded with "$" imply that you should execute the command as a general user - not as root. • Commands preceded with "#" imply that you should be working as root with "sudo" • Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>") imply that you are executing commands on remote equipment, or within another program. # 3 Exercise ## 3.1 Install a new software package (Apache) We will now install the Apache web server on your machine: $ sudo apt-get install apache2

Say "Y" or "Yes" if prompted. Once the apt program finishes you will have the Apache web server running on your machine.

http://vmN.ws.nsrc.org/

... where "N" is the number of your machine.

You should see something like "It Works!" on the page.

If not, you may need to create a simple web page:

$sudo -s # echo "Hello, world" > /var/www/index.html # exit$ 

## 3.2 Stopping and starting a service

Now, let's stop the web server (Apache) that is installed on your virtual machine. To do this you can do:

$sudo service apache2 stop In your web browser, try and reload the web page for your machine. It should indicate that no web server was found. Now let's start the service again: $ sudo service apache2 start

You can see if a service is running by typing:

$sudo service apache2 status If a process ID is displayed, then the service is running, but our next exercise will show you another way to verify this. # 4 Finding and stopping processes If you wish to find something that is running and then stop it you can use the "ps" (process) command with "grep" and "kill". Let's do this by opening two connections to your virtual machine. 1. Using SSH, open two terminal connections to your Linux server • user: sysadm • machine: vmN.ws.nsrc.org 2. Once you have opened two terminals go in to one terminal and type: $ tail -f /var/log/syslog

This will let you look at the end of the syslog log file in real time. If events take place that are logged you will see them as they happen. Now, in your other terminal let's look for this process:

$ps aux | grep tail The "aux" are options to the ps (process) command. The options mean display all process running that belong to you and to other users and provide information about who owns what process. You will likely see something like this: sysadm 5200 0.0 0.0 3764 540 pts/6 S+ 13:50 0:00 tail -f /var/log/syslog sysadm 5208 0.0 0.0 3908 820 pts/5 S+ 13:50 0:00 grep --color=auto tail Question: what is process 5208 above, and why are we seeing it ? Tip: you can add the "w" option to enable "wide output", and you can use "w" twice ("ww") to display the entire command line regardless of how long it is and wrap it in your window. Try it! $ ps auxww | grep tail

You could press "CTRL-C" in the terminal window where the tail command is running, or to stop the process right now you can use the kill command. You need to replace the Process ID (PID) with the process ID number of the tail command running on your machine. In this example the number is "5200". At the command prompt type:

$kill NNNN ... where NNNN is the PID of your tail process. Once you do this return to the other terminal screen. The "tail -f" process should now have exited and you should see something like: Terminated sysadmt@vmN:~$