un-ubuntuing visudo: how to make visudo use vi instead of nano
At some point, Ubuntu decided that it was best to have “visudo” — which refers to the vi editor by name — use the nano editor by default. If, like me, you are trying to edit the sudoers file, and you don’t want to use nano, or if you want to change visudo “back” to using vi (as intended), then read on. Note that this also will change your default editor to vi, or change the default to whatever editor you choose. visudo takes its cue from the alternatives configuration system, which means it looks to /usr/bin/editor, which itself points to /etc/alternatives/editor. The Ubuntu way to change the default editor (which will be used by visudo) then is to run
That should go something like this:
Finally, here's what the filesystem structure looks like:
laptop:~$ sudo update-alternatives --config editor
[sudo] password for : There are 6 alternatives which provide `editor'. Selection Alternative Press enter to keep the default[*], or type selection number: 1 |
Fixing broken mysql / mysql-server under Ubuntu 9.04 (Jaunty) after a purge
I broke my server attempting to do some clean-up before making bigger changes. mysql would not restart, and the culprit was something like ‘apt-get purge mysql-server,’ which deleted the /etc/mysql directory . Various installs brought back /etc/mysql but without solving the problem: % sudo apt-get install mysql-server mysql-common
In any case, the only way I could get things back running was to copy over the /etc/mysql directory from a working server, doing % sudo apt-get remove –purge mysql-server and rebooting. Here’s what the /etc/mysql directory looked like after the copy:
So, the copy provided the conf.d directory and the my.cnf file that the re-install failed to (re)create. I’ve uploaded a copy of the default Ubuntu 9.04 /etc/mysql/my.cnf file here. And here’s just the active info from my.cnf file —–start my.cnf——
—–end my.cnf—— Recreating that file may help you get mysql back running, as it appears to have been essential for me. Incidentally, here is a handy search for printing which logfiles have info about your misbehaving program (in this case, mysql):
|
unix/linux redirection: empty files without typing /dev/null
redirecting standard error (stderr) and standard output (stdout) to a file
Capturing both errors and normal list output from ls, with “long” and recursive options set, to a file called /tmp/allout : ls -lR > /tmp/allout 2>&1 |
A simple output filter for “show cdp neighbors” using a compound regular expression (Cisco IOS)
Here is a simple filter I’ve used on ’show cdp’ output, which lets me get information quickly.
In practice, I generally cut the command down to: In any case, the output should come out something like this: |
upgrading an Ubuntu server from the command line
This is how I upgraded from 8.10 to 9.04 over the network: sudo apt-get install update-manager-core [reference : http://www.ubuntu.com/getubuntu/upgrading ] |
Cisco IOS CLI regular expressions, Part II — ‘AND’
In an earlier post, I talked about Cisco command line regular expressions, and held off on giving any good examples of using the CLI regexp tools to get ‘AND’ functionality. ( I pointed out there that the ‘|’ (pipe symbol) could be used as a simple ‘OR’ function.) Here’s a scenario: you’re auditing one of your routers, checking to make sure privilege levels are what they should be for individual users, and that commands that have been moved into non-default privilege levels that appear to be correctly defined. Here’s the output of ’show running-config’ with only lines that match ‘privi’ included (so as to catch lines that show privilege levels):
In this case, you can use the regular expression “.*” (dot-star) to match lines that contain both the word ‘privilege’ and ‘level 0′, thus eliminating other priv levels, as well as username definitions: The same thing works for an audit of ‘level 7′ commands:
If you want to show lines that match privilege levels other than zero, you could use this: You should note that the “.*” (dot-star) regular expression can be used as a synonym for AND, provided that you are aware that “.*” is not order agnostic.
It works! Notice that we caught both the description line and the privilege exec lines. Apparently I’m easily amused, but there it is. |
Cisco IOS CLI regular expressions (”Ceci n’est pas une pipe.”)
| [taken from a note originally written March 2007] Yesterday, I was trying to find a method to implement an ‘AND’ function within the Cisco IOS cisco command line. I was familiar with the ‘OR’ function available through the ‘|’ symbol (which is to say, the same symbol as the pipe). For example, if you wanted to show the running config, and filter out lines that contained either ‘foo’ or ‘bar’, you could type
The second “pipe,” in this case, isn’t a pipe, but the symbol for an ‘OR’ function. (”Ceci n’est pas une pipe.”) I wasn’t able to find a way to do an ‘AND’ in an analogous fashion, but I did find a decent Cisco webpage on CLI and regular expressions (regexp) that helped a bit. That page can be found here: http://www.cisco.com/univercd/cc/td/doc/product/software/ios120/120newft/120t/120t1/cliparse.htm It is possible to do ‘AND’ type functions implicitly by using a more complex set of matching rules based on regular expressions. Here’s a example that shows (from an interactive session on the Cisco CLI) if access-lists have been applied to interfaces using the “access-group” command:
Lines that start with ‘interface’ followed by an uppercase letter (the expression matches anything in the range A-Z) are supposed to match things like ‘interface Fastethernet,’ ‘interface Serial’ and so on. The second part of the expression matches access-groups that have three possible initial character ranges: a lowercase letter (a-z), an uppercase letter (A-Z), or a number (0-9) for the standard access lists. Interfaces that have no access-lists applied have on the interface name listed, but interfaces with an access-group command show the complete access-group statement under the relevant interface (which makes sense, given that this is only a filtered ’show run’). Output might look something like this:
If this kind of function is useful for you, it is even easier to use if you put it in an alias on your switch or router:
You should, of course, pick a name for the alias that you’ll remember. |
