Main Content

Ruby, Perl, Linux, MySQL - some training notes

Archive - Originally posted on "The Horse's Mouth" - 2008-11-23 12:12:20 - Graham Ellis

We have just come to the end of a solid 12 days of training ... and we are just getting ready for the next week, with delegates arriving this evening. There's a lot going on behind the scenes, even over this weekend, with the hotel to be prepared as well as the training course. (Picture - our clean bedding racks at Well House Manor)

So I'm taking an all too brief opportunity to post up some pictures from the last hectic fortnight, before the next hectic fortnight begins in a few hours time. You'll find, below, some technical notes and scripts mixed in with some rather less technical stuff.





If you're writing / installing a web based application that used Perl and CGI to access a MySQL database, don't just plug all the components in and hope they work first time ... they might, but if they don't you'll have a woozie of a job sorting out which is functioning and which not.

Test your database first - that's (1) on the diagram. Then add in a Perl application from the command line - using the DBD and DBI modules, and make sure that works. That's (2) on the diagram. The add in your web server, and CGI, and run it from a browser - step (3). Three easy steps rather than one very difficult one.

From our MySQL course, with reference made to Perl on the Web





In Ruby, you have no fewer that four different ways of changing the flow control with jumps. They are break, next, redo and retry, and the diagram shows the effect of each of them if used within a condition inside a loop.

Computer Science purists will tell you that you should never use a goto statement as it rapidly turns your logic into spaghetti - and indeed Ruby does not have such a statement. However, it has been argued that these four jumps are tame forms of the 'goto', and that they should be used with caution.

From our Ruby Programming course





Melksham Chamber of Commerce met at Well House Manor during the recent run of courses (we're nothing if not versatile!) for their AGM and an EGM.

With the current re-organisation of local government in Wiltshire, which sees the replacement of five bodies by just one, with a more than halving of the number of elected representatives, this is a time for local traders who do business with these bodies to be aware of what's happening, and to position themselves to do well in 2009 and beyond. It was frightening (at another recent meeting) for those of us who live in Melksham to hear the chiefs of the new council talking, as if to a script, of the three largest towns in the county when they spoke of future development, ignoring the fourth (Melksham) and many others places ... the Chamber of Commerce could be so important next year.





Q: If you have a database table with 32 patients in it, and another table in the same database with 50 clinical operations in it, how do you link the tables together?

A: With a join. But it's not necessarily as simple as that. If you have some patients who have never had any operations, will they appear in your resulting data set? That depends on whether or not you specified JOIN or LEFT JOIN. And what about operations that have been erroneously entered into your database as they relate to patients who aren't a part of your sample group ...

In this example, we show how you can have five different sets of results:
• All the records that match
• All the records that match PLUS and extra record for each patient who hasn't had any operations
• All the records that match PLUS and extra record for each operation which isn't assigned to any patient
• Just the records for each patient who hasn't had any operations
• Just the records for each operation which isn't assigned to any patient.

From our MySQL course, or if you want more detail see our join v left join page





The /etc directory of the Unix and Linux operating systems includes many configuration files ... the rather poor picture to the left showing the more important ones (or the ones which were more important to the delegates on my recent LAMP deployment course on which we set ul Linux, and a Web server with MySQL and PHP.

The directory /etc/sysconfig/network-scripts. In this directory you'll find the configuration files for the network interfaces, where the IP address, netmask, gateway address, and so on are set.

The directory /etc/init.d. Holds all the scripts you could (possibly) want to start up and shut down daemon services. Each script responds to the parameters "start" and "stop" to (you guessed it!) start and stop services. Whether a script is actually run or not depends on directorys such as rc5.d

The directory /etc/rc5.d. A directory full of Symbolic links to /etc/init.d. You place a link to a file in /etc/init.d, and you name that link starting with an S, if you want the particular daemon to be started as the computer restarts into "run state 5". You place a link starting with K if you want the daemon to be properly closed down on shutdown. The naming of the links is important as they are run is ACSIIbetic order. If you are running a server which is NOT running the X Windows System, you'll be concerend with /etc/rc3.d and not /etc/rc5.d

/etc/inittab. Linux / Unix startup script. The only thing you many commonly change is the initial run state - i.e. to control whether or not the X Windows GUI is activated on bootup.

/etc/fstab. The mounting of the various disc drives, slices, and pseudo devices onto the Linux / Unix file tree.

/etc/nsswitch.conf. This file controls where the operating system looks for login accounts, host computer names, and much more - whether to look in local files, in network services, or in both ... and in what order.

/etc/resolv.conf. The IP addresses of the machines that your system is to contact to help it resolve unknown host computer names back to IP addresses. "The next step in the DNS chain".

/etc/hosts. Maps locally known host names to IP addresses and vice versa.

/etc/passwd. Local user account definitions - user name, user number, home directory, program to run when the user logs in. In fact everything EXCEPT the password, in spite of the name of the file.

/etc/shadow. A file of user names and their encoded passwords. This was separated out from /etc/passwd a good few years ago, so that the encoded password information could be held in a file with fewer access rights than /etc/passwd. If you're editing this file with vi, remember to save it with :w! rather than :w to override its read-only nature.

/etc/group. A file that defines names for each of the groups, and also defines any uses who are in a group in addition to their default group which is specified in /etc/passwd.

/etc/bashrc. A file of bash shell commands which is run by each user when they log in - allows for the centralised setting of default file permission via umask, for example.

The directory /etc/skel. A skeleton directory that's duplicated to each newly created user if the appropriate option is selected when you run the useradd command.

From our Introduction to Linux Administration course.





It's always a fine line during a training course as to whether we should go out for lunch - taking a little longer, but giving delegates a good break and a chance to stretch their legs, or eat in - allowing us to make the maximum use of course time.

Here are Thursday's Pizzas, prepared and cooked by Sharon, so that we could make the very best of the time we had on our Deploying Apache httpd and Tomcat course. In fact, even though the lunch break was brief we ran on until 6 p.m. in the afternoon, as a disparate group of delegates had a lot of wonderful questions to ask, and none of them wanted to run too late on Friday!





There are a number of different shell programs (programs that look after the user's keyboard commands, and the operating system's responses to the user) available on Unix / Linux. Ask me sometime to tell you about the Bourne Shell (sh), the C Shell (csh) and the Korn Shell (ksh) - the latter two remaining popular in some quarters. Under Linux, thoughh, the most commonly used shell is now the Bourne Again Shell or bash.

This slide shows you some of those extra facilities of bash which are different to (or absent from) some of the other shells.

• If you press [tab] while entering the name of an existing file, bash will attempt to auto-complete it for you. Not only time saving, but also helps avoid too many mistakes - if a [tab] doesn't respond, it can be a quick way of finding a spelling mistake you've already made.

• The set -x causes subsequent shell commands to be echoed back to you, with details of how the shell / operating system has interpreted them. A great debug and learning tool which can be switched back off with set +x

• The history mechanism in bash is similar to that of the cshell. (and different to that in ksh!). So you can use:
!$ Last parameter, previous line
!! Rerun the last command
!gr Rerun the last command starting with gr
!442 Rerun command number 442

From our Linux Basics course.





Directory navigation on a Unix / Linux box is controlled by how you start the file or directory name that you're typing in:

If you start with a /, you're talking about an absolute path from the top of the file system tree.

If you start with a ./, you're talking about something in the current directory.

If you start with ../, you're going up from the current directory.

If you start with ~/, you're going relative to your home directory.

If you start with ~fred/, you're going relative to fred's home directory.

and is you start with another character, you'll be looking within the current directory that you're in.





The vi editor is the only editor that you can be sure of finding on any Unix or Linux system - and it's darned good. However - it is easy to use once you know it, rather than being easy to learn. That's why some people will tell you that vi stands for "virtually inoperable" rather that "visual interactive".

The "trick" to learning vi is to understand that each key on the keyboard is a command - usually a single letter command - when you enter vi, with upper case, lower case, and control keys each meaning something different. Once you have entered an insert mode (i or a or o or cc or cw .... or others), you are in insert mode and anything you type is added in to your text. You return to command more by pressing the [esc] key. A final mode - "ex mode" is entered by pressing the colon key, and in this mode you type in a command followed by a [cr].

The diagram on the left shows a minimum of vi commands - we have an article that takes you through those commands here.





The week finished with a trip to the station to drop off a delegate for the train to take him home, from Melksham to Luton via London. And, this evening, the next course will start with me meeting the train and greeting our next group of delegates. I'm looking forward to it.