Dedicated to keeping Linux, Unix and scripting Languages Alive!
Ready To Unplug And Find Another Conduit For Your Passion? Click On Any Picture Below! Click On Any Picture Above To Enjoy A Good Read Of Varying Length!
Here's a little something to make you smile on the eve before you begin working all weekend :)
This video (which can be found in its original location on YouTube) is both awkward and hilarious. It took me a while to start to chuckle, but this guy's startup sound is one of the most subtly obtrusive things I've ever heard.
And it really goes over well in the library ;)
Enjoy!
, Mike
Discover the Free Ebook that shows you how to make 100% commissions on ClickBank!
Today I'm speeding around, working my arse off so that I can work all weekend (When does it end? ...oh yeah; with the worms ;) and I wrote this little shell script (in Solaris' /bin/sh) to lighten the mood a little.
It's another in a string of a thousand fake error messages, but it worked pretty well for my purposes. I made sure to install it up front in the /etc/rc2.d directory (from JumpStart) so that any admin watching a new installation come up for the first time (to verify its integrity) would be guaranteed to see it. Man, it was fun until I had to fix the problem and pretend I had no idea what happened ;)
Enjoy the video of the script output and, hopefully, you can have some fun with this shell script (or a variation of it) on your own!
Please note that the only fun thing other than the error message are the traps set on the interrupts. It's a reboot-a-thon in the making ;)
Here's something people don't gripe enough about ;) Actually the problem is only common if you work in a shop that runs the iPlanet Administration Server (Formerly, Netscape LDAP) and you have it set up to run securely using TLS or SSL, and you have it set up so that you need to enter a password to start it up. That's a lot of "and"s. Okay, only 2. I'm exaggerating ;)
Having a secure LDAP setup (which runs as the "slapd" process) is good enough without the extra authentication needed to start it up. It's good to know that this is only optional. Depending on your requirements, you may or may not want to make it necessary for someone to know a password in order to start the service, assuming they already have the proper credentials and system privilege. You'll still enjoy the benefits of secure network authentication (for users accessing the database) and encryption of the trasmitted data (for the LDAP requests and responses).
If it makes you feel more secure (or your site security requires it), setting up the TLS/SSL keys for LDAP easily allows you enter that additional password. In fact, it automatically prompts you and makes you go out of your way to type enter twice in order to have a "blank" password (which, in this case, is equivalent to no password at all).
The most common issue this causes (We're not going to go into key setup or port access issues here today) is a failure to boot non-interactively. For instance, if you have LDAP set to start up in an init script called S99ldapstart, with a line like this:
/opt/ldap/slapd-server1-636/start-slapd
and you issue:
/etc/rc2.d/S99ldapstart
while you're logged in, you'll be prompted to enter the security password to start the server. Once you enter the password, the server starts up as normal. This is all well and good if you're on the machine and running the script through an interactive shell, however it won't work at all when the "rc" program tries to run this script at boot time. That sort of situation is analagous to you entering the start command (as above) and then just sitting there and never entering the password you're being prompted for. The secure LDAP server will never start.
Fortunately, even though the answer doesn't seem to be widely available (although it is packed away in online manuals, etc), it is relatively easy to implement and works like a charm. The only downside is that you put yourself at odds with the extra security you've added to the process (by insisting on the startuppassword) by having to store the password in a plain-text file that (if compromised) will give anyone who can access it the password you don't want them to have!
Deriving our settings from the above information (LDAP Base directory is: /opt/ldap and Server base directory is: /opt/ldap/slapd-server1-636) and accepting, for the purposes of this demonstration, that our secure startuppassword is "Bingo" (All passwords are case sensitive. Capitalization counts :) we can do the following at the command line, and set ourselves up for hands-free secure LDAPstartups forever (or until we change the password):
And that's it :) The most important thing to remember, since you can do this for any SSL/TLS enabled LDAP server instance, is the format of both the "name" and the "contents" of the file that will hold that password.
1. The name of the file must be of the form:
$LDAP_ROOT/alias/$LDAP_SERVER-pin.txt
Where (for this example) LDAP_ROOT=/opt/ldap and the LDAP_SERVER=slapd-server1-636. If it's not named like that, iPlanet Directory Server will not recognize it.
2. The contents of the file must be compact. No spaces are allowed anywhere they're not explictily shown here, in this example, including at the end of the line. Any deviation from this rule-of-thumb may make it so that your secure LDAP server doesn't recognize the password and reverts back to the prompt, leaving you with a server hung at startup. The password must be of the form "Token:PASSWORD" with no spaces.
Once you've done this once or twice, it's a walk in the park. Every time you need to boot your server, you can be sure that your secure LDAP servers will start up properly. Since this setup is so exacting in its requirements, it's also pretty simple to troubleshoot if breaks :)
As we mentioned earlier, using Sed, Awk or command line Perl to edit your source startup files in /etc/init.d is a perfectly acceptable practice. However, because of Solaris' tendency to use hard links in their "run level" directories, this can cause problems, as using these utilities changes the "inode number" of the source file and separates it from the "run level" script.
The answer is to do the simplest thing. Edit all the source files using an editor, like vi. If you edit them in this way, after your changes have been made and you've saved your edits, the inode number will be the same. The reason this usually isn't considered an option is that, if you have to comment out a large number of scripts, using vi can be very time consuming and can put you in a position to make a single error, or multiple errors, in some of your source scripts, since you'd have to repeat the same editing actions over and over again.
Here's a little piece of script that can make it so you can use vi to comment out your scripts (preserving the inode number) and not have to worry about making a hard-to-find error somewhere along the way. This way, like with Sed, Awk or command line Perl, you'll either do everything right or make the same mistake in all files ;)
This example uses the "here document" (referred to in this blog, in a previous post here) and inserting actual control characters (referred to in a separate earlier post here). For our purposes, since this script doesn't translate well into simple text, we'll use a basic legend:
[ctl-v] will mean hit the "control" and "v" keys at the same time. [esc] will mean literally hitting the "escape" key. [cr] will mean literally hitting the "return," or "enter," key.
And here it is - The script takes the arguments of any number of files that you want to totally comment out; placing "#" characters in the first position on every line.
#!/bin/sh
for x in $@ do /usr/bin/vi $x <<-END [ctl-v][esc]:g/^/s//#/[ctl-v][cr]][ctl-v][esc]:wq![ctl-v][cr] END done
Now you can run "Yourscript filea fileb filen..." and you will actually be doing real editing with vi,completely hands-off :)
P.S. If you don't want to see the vi output, and you're satisfied that the script is working as expected, just change the following line
from: /usr/bin/vi $x <<- END to: /usr/bin/vi $x <<- END >/dev/null
As we mentioned yesterday, it's generally best practice to edit, or update, your init scripts by editing the source file in /etc/init.d, rather than the link to it in one of the "run level" directories, like /etc/rc2.d
Given a specific example (For instance: we need to comment out 8 or 9 scripts in /etc/init.d) that we want to do fast, we've decided that just adding "#" symbols to the beginning of every line of all 9 scripts in /etc/init.d would be the fastest way.
We have a few options, like using Sed, Awk or command-line Perl, to take care of the work for us lickety-split. However these solutions, and others like them, present a general problem. There's nothing wrong with using these methods, in general, except that Solaris, right out-of-the-box, uses a lot of "hard links" in its "run level" directories to point back to the source script in /etc/init.d.
Hard links differ from the symbolic links we discussed yesterday in that they are not just "pointers" to the source file; they are actually links to the inode that the source file uses. In essence, they are another version of the exact same file, or, in different terms, another reference to the same file.
To illustrate the difference another way: If you delete a source file, the symbolic link to it will still exist, but if you try to edit that symlink, you'll be editing an empty file, since it's just a pointer to something that doesn't exist anymore. If you delete the source file and go to edit the hard link, you will still be able to edit the original file since the hard link points to the inode (not the filename) and removing the source file has just decreased the reference count of the inode.
When a hard link to a file is created, in essence, two copies of the file now exist. This presents an issue if you use Sed, Awk or command line Perl, because when you edit the source file in /etc/init.d using these methods, you're copying the changes to another file and then writing that back over the original: Changing the inode number! Now your source file and your file in the "run level" directory both point to different inodes, and updating the source file won't change the contents of the "run level" file.
There is an easy way around this. You can edit each of the 9 files using an editor like vi. But how to do it as quickly and easily as with Sed, Awk or command line Perl?
Tomorrow, we'll create a script that will do just that. It will edit your files for you, hands-off, and not change the inode number; thus ensuring that all of your changes will remain consistent in the "run level" directories, no matter what kind of links (soft or hard) they harbour.
Today I thought I'd go on a little about editing startup scripts.
It's generally accepted that the correct form for creating an init (or rc) script on Solaris is to create that actionable script in /etc/init.d and then create links to it (soft or hard) in the proper "run level" directories (/etc/rc2.d for run level 2). These files are also standardly named beginning with a capital S (to instruct /sbin/rc to run the script with the "start" option) or K (to instruct /sbin/rc to run the script with the "stop" option).
A lot of times, folks will simply create scripts in the various "run level" directories (like /etc/rc3.d for run level 3), which works perfectly well, but might cause some confusion down the road. For instance; if you create /etc/rc2.d/S88sendmail and replace the linked version that pointed back to the /etc/init.d/sendmail script, any changes made to the the source version in /etc/init.d will never be reflected in your version (sitting in /etc/rc2.d) and - should you expect your changes to work - you'll find that they never seem to stick on reboot.
I suppose that the best argument for doing things the "standard" way is that it can save you a lot of time and probably more than a few headaches. Consider that, by doing things by-the-book, you need only edit one script to affect however many run levels its linked to. Also, confusion over "what is actually where" is removed.
When it comes to the back-links in the "run level" directories, I prefer to use symbolic links (created by "ln -s") rather than hard links (created using "ln" straight up). The reasons for this are threefold.
1. Symbolic links are easy to see. I don't consider myself simple or anything like that, but I do like to be able to run "ls -l" in /etc/rc3.d and see something like this (clipped output to keep the output line short enough to not word-wrap):
hostname.xyz.com[/etc/rc3.d] # ls -l lrwxrwxrwx 1 root other S90prog -> /etc/init.d/prog
Just seeing that, I know that this script is actually in /etc/init.d and, if I want to make changes to it, that's where the source is. Which brings me to point two.
2. Symbolic links are just as easy to use as hard links. Now that I'm feeling confident that I'm editing the correct file, I don't need to edit the /etc/init.d/prog file, because the symbolic link "/etc/rc3.d/S90prog" is just a pointer to it and, by editing it, I'm actually editing the script in /etc/init.d.
3. And thirdly, I like the fact that symbolic links are merely symbolic. The difference between a hard link and a symbolic link can be gigantic depending on what kind of change you're making!
And that, we'll talk about tomorrow, because it's a topic that will eat up some real estate, I've taken up enough space for today :)