Lots to do today: we practice using sudo and creating new users and groups, look at logging, and explore a new scripting language (Perl).
Modify the sudo configuration file to include an entry for your account and to permit it to run commands as root. Verify that it works by executing sudo /sbin/fdisk -l /dev/sda to see the partitions defined on your hard drive.
Now use sudo and lvrename to change the name of your lv_home logical volume to be named lv_swap2, so that the next person who looks at your logical volumes is not confused. Note that this means you'll also need to change /etc/fstab so that your system finds your new swap volume at next boot.
Create an account for a friend using useradd and passwd. Notice that it automatically created a home directory and a personal group in /etc/group. Look at the password you created in /etc/shadow to see whether it is md5 or not. How can you tell?
Establish an account for me, called prof, with the specific password: $6$9lAKxQZj$1Agt39ynQJRY28OsnwM/Kh8omTqhix0CpdBg8gLIPnV7qL39gWftM6DqmM4duDfMgfCamD0Kt8EvRrbmTIV0n0 so that I can log in with a password that I know. Create a new entry in /etc/group for a new group, and add your personal account and the prof account to it. Verify that your account is now in two groups using the groups command.
Start the firefox browser. From a shell, use ps aux to find the PID for firefox. Now use the kill command to stop the firefox process; what happens when you move the firefox window around or click on its menus? Now send it the continue signal, and notice that it recovers. This is essentially the same situation if you were to press ctrl-z at a shell that is currently running some program (like emacs) which then stops functioning (because it has been suspended).
Log in as root. Use crontab -e to create and edit a crontab file for root. Add a crontab entry that will run the uptime command every minute for today only, and capture the output by appending to a file in /var/log. For example,
Then save and quit your editor. Later in the lab, take a look to see the results in this log file.
Look in /var/log/cron to see what cron has been doing. What scripts are run daily?
One is typically attached to the departmental network. We usually leave the second empty, for use in the future for networking-specific exercises.
Running ifconfig with no arguments generates a list of all network devices and their configurations. Note the list includes another device we have not mentioned -- the network loopback device, which is defined to be 127.0.0.1 for all systems, and is usually defined with the DNS name of "localhost". You can, for example, ping localhost with the same effect as pinging with the current name of your machine.
Revise the local boot script from lab #3 to incorporate the output of ifconfig on every boot. (No, it doesn't need to be all on one line this time.)
If you are unfamiliar with Perl, start by skimming through the section on Perl in chapter 2 of ULSAH. If you are uncertain of your programming skills, I suggest: Picking Up Perl. If you are more confident, try Perl in 20 pages.
There is lots of Perl documentation online and there are multiple books on Perl in the Lehigh Safari e-book library.
Now write a very simple Perl script that prints out the parameters given to it, like the echo(1) command. It should work like this:
% ./echo.pl hello world
hello world
The following script will write the words 'hello world' to syslog, along with the PID of the logger.pl process. Modify it to write the contents of all parameters of the script instead (like the echo script above).
Verify that it works by running it and checking /var/log/messages.#!/usr/bin/perl use strict; # compile-time checks use warnings; # enable run-time warnings use Sys::Syslog qw(:DEFAULT setlogsock); # library for syslog functions setlogsock('unix'); # use a unix domain socket openlog("logger.pl", 'pid', 'user'); # register ourselves syslog('info', 'hello world'); # the syslog call closelog(); # close the socket
Challenge task (optional): modify your local boot script so that it extracts the IP address from ipconfig and adds it to the single line output (and ignores the rest of the ipconfig data). Then write a perl script that replicates the functionality of your improved local boot script.
If you have time, you might start looking at Project #1 (due in two weeks).