I was adding a few checks for oracle processes using check_snmp_runningproc and noticed a few problems. It seems that when the check returns a list of processes from a remote host it lowercases them all and attempts to strips out .e .ex and .exe extensions. The extensions used in the regular expression weren’t escaping the dot which resulted them in stripping out any character followed by an e, ex or exe.
In my case this meant it was matching against “orac” instead of oracle. I also noticed that the user input wasn’t undergoing the same translations as the returned processes (both the conversion to lower case and the stripping of extensions). I fixed this by cleaning up the regexp, and using an lc() function and the same regexp for user input. I submitted the patch which has been included in SVN. The most up to date version of this check is here:
http://svn.opsview.org/opsview/trunk/opsview-core/nagios-plugins/check_snmp_runningproc
If you miss the notification that used to be in the 8.10 notification area telling you new updates are available you can get it back by quite easily by issuing the following command.
gconftool -s --type bool /apps/update-notifier/auto_launch false
Then you just kill and restart update-notifier and you will have your icon for update-notifier back (to check it straight away, run: sudo apt-get update).
Note: This will also stop the update manager window from automatically popping up every time you run apt-get update which is reason enough to do it on its own.
This is just a quick look at cleaning up an Ubuntu system. This is all documented elsewhere by an abundance of people, some of whom I no doubt took this off in the past and have forgotten where now (If you’re that person, then thanks very much, this stff has been coming in handy for me for a few years now).
The first step is to remove all of the residual configs lying about your system. These are configs which, as the name suggests, have been left behind by removed programs. To do so the we need to open Synaptic. You can find that in the System menu:
System > Administration > Synaptic Package Manager
Once we are in Synaptic we can click on the status button down the bottom left. This will separate your packages into sections based on their status. The one we are looking for will have the words “residual config” in the name. Select all these packages and right click on them. In the menu that appears choose “Mark For Complete Removal“. You can then click “Apply” at the top of the screen.
That’s it. You have now removed all your residual configs.
You will need to open a terminal for this one. To do so hold down “Alt+F2“. A box should appear, into which you can type “gnome-terminal” to open a new terminal. In the terminal you simply need to type the following to remove these partial packages:
sudo apt-get autoclean
Once you’ve put in your password etc that’s it. All gone.
Theres a nice little app called localepurge that will get rid of all the locale data that you don’t need. This can amount to quite a substantial amount of space. The first step is to install localepurge. In your terminal type:
sudo apt-get install localepurge
After installing localepurge will require that you configure it with the locale’s you want to keep. It will present you with a list of abbreviations from which you can choose. Scroll down to the one that suits you best (i.e. for myself I kept en_IE.
That’s it. It will run automatically after each install and remove unnecessary locale data.
The app deborphan can grab all your orphaned packages and be used to remove them (be a bit careful with this one as sometimes it can remove something you need – it hasn’t happened to myself but I have heard of it happening). So to install the package, in your terminal type:
sudo apt-get install deborphan
To run the app you just need to type this at your terminal:
deborphan | xargs sudo apt-get -y remove --purge
This will remove all the orphaned packages on your system.
That’s it then, you should have free’d up a good bit of space on your system now and it should be a little tidyer than before!
“GNS3 is a graphical network simulator that allows simulation of complex networks.”
I was recently pointed in the direction of this app as a pretty nice graphical interface to the Dynamips / Dynagen router simulation. It still uses Dynamips / Dynagen underneath, along with Pemu (a Cisco PIX firewall emulator based on Qemu), but allows you to do graphically what you normally have to do using textual config files.
The interface is really nice and you can drag and drop in routers, create links between them, and start and stop them through the GUI. Theres no real difference from what I can see in performance etc, so many people would just turn a blind eye and figure, “Why bother, the config files are handy enough”, but it does mean you don’t have to bother with the configuration for the most part, and can just concentrate on the actual task at hand.
And the best news is it’s packaged for Ubuntu! I’m sure this is the case for other distro’s too but I haven’t checked. So all you need to do is:
sudo apt-get install gns3
You can check the documentation etc out at: http://www.gns3.net/
This is a slimmed down version of a combination of the Dynamips / Dynagen Tutorial and a few other Ubuntu specific sources. In fact, you could call it a quick and dirty guide to get you up and running. I reccommend using the Dynamips / Dynagen Tutorial once you have finished here picking up at the Running Sample Lab #1 section. I couldn’t write this better than it is there.
Dynamips and Dynagen are both in the Ubuntu repository so installation is as simple as an apt-get install. To this end run the following:
sudo apt-get install dynamips dynagen
Congratulations. That’s it for installation.
You’ll need to get yourself a Cisco IOS image for use with the emulator. Once you have one it’s generally a good idea to uncompress the image before using it as it will speed up the boot process. Use this command to do so:
unzip -p c7200-jk9s-mz.124-13b.bin > c7200-jk9s-mz.124-13b.image
Note that this will throw an error but you can safely ignore it.
Your telnet client should be correctly configured upon install. You can find the config file for this in /etc/dynagen.ini if your curious. You’ll find a line like the below uncommented which is your telnet configuration.
telnet = xterm -T %d -e telnet %h %p > /dev/null 2>&1 &
You will need a configuration file for your router(s). You can find an example one (we’ll use this example config for the rest of this guide) in /usr/share/doc/dynagen/examples/sample_labs/simple1/. We’ll use the sample1.net file from here for this guide so copy this file to wherever you have your “working directory”.
The .net file will look like this:
[localhost]
[[7200]]
image = /opt/7200-images/c7200-jk9o3s-mz.124-7a.image
npe = npe-400
ram = 160
[[ROUTER R1]]
s1/0 = R2 s1/0
[[router R2]]
# No need to specify an adapter here, it is taken care of
# by the interface specification under Router R1
So, according to the config we are running this router instance on localhost, and defines all the defaults that will be applied to any 7200 router instance we create. This makes things easy, by allowing us to specify common things like RAM size and IOS image only once.
Each of our router instances is going use an NPE-400, and be allocated 160 MB of RAM .
We are defining a virtual router instance with the ROUTER keyword. The string following this keyword is the name we are assigning to this router, in this case “R1”. This name is just the name that is used by Dynamips / Dynagen. It has nothing to do with the hostname that you assign in IOS to the router.
The s1/0 = R2 s1/0 line states that we are going to take R1’s Serial 1/0 interface, and connect it to R2’s Serial 1/0 interface (via virtual back-to-back serial cable). Dynagen automatically “installs” a PA-8T adapter in Port 1 to accommodate this connection on both R1 and R2.
We also create a 2nd router named R2. This is the same R2 that is referenced in the line above that connects R1 and R2’s serial interfaces. As the comment says we don’t need to specify an adapter here as it is taken care of by the interface specification under Router R1.
The only change we need to make to the .net file above is to change the value of “image=” to the path of your IOS image. For instance:
image = /home/$USER/ios/7200/c7200-jk9s-mz.124-13b.image
That’s all the configuration we’ll need for the moment.
Before you start the server cd into your working directory where you plan to store the information about your router(s). There are a lot of files created when starting both the server (dynamips) and console (dynagen) so best to be aware of this as they will be created in your working directory wherever you are.
To run the server (-H 7200 means on port 7200) in the background use:
dynamips –H 7200 &
You can now start your console with the command:
dynagen sample.net
At this point you are best of continuing from the Running Simple Lab #1 section of the Dynamips / Dynagen Tutorial. Good luck!
I’ve often found that I can’t delete items I’ve copied from a CD or DVD using the GUI Trash folder. In fact, this can happen with a variety of files from a variety of places but, to be honest, I have a habit of not correcting the permissions on these files before blindly hitting delete. Sometimes you just forget these things.
In any case this can be extremely infuriating, and inevitably results in looking around your /home directory running something like…
find /home/$USER/ -name ‘Trash’
…which will find what your looking for pretty quickly. But in case you’re feeling especially lazy here’s the directories you’re looking for. You’re going to need remove files from the two directories listed, just to keep it all clean.
/home/$USER/.local/share/Trash/files
/home/$USER/.local/share/Trash/info
Vim is what is known as a modal editor. While using it becomes very easy over time, learning it initially can be confusing and pretty irritating. This tutorial aims to give a basic run through of the most commonly used commands in Vim,
The first step in vim is to use it to open a file or create a new one. To do so you just do the following at your terminal:
$ vim test.txt
This will open a file for you to write to. When you open vim you are immediately placed in command mode, so if you want to insert some new text you will need to enter Insert Mode. To enter insert mode you just hit the letter i. After this if you at any point want to return to command mode just hit the escape key. There are several more modes available to you but we’ll stick with the basics here.
After entering command mode again you can enter replace mode by hitting the R key. You can also insert text after the cursor (as i inserts it at the cursor) by hitting a (append), or open a new line by hitting o.
The historical navigation keys in vim are h,l,j, and k. These are to move left, right, down and up respectively. Since Vi became Vim (Vi IMproved) however you can also just use the arrow keys. It is good to take note of these keys though as some default installs of Vim will actually be Vi (or at least use the old style navigation keys from Vi). Also, remember you need to be in command mode for navigation otherwise you will just be typing in the letters h,j,l and k!
You can move forward a word using w or back a work using b. You can use ^ to move to the start of a line and $ to move to the end of one. gg will bring you to the top of a document and G to the bottom of one.
I say delete but that is not entirely true. When you use the delete commands below the deleted text is actually kept in a register (the equivalent of a clipboard in Windows). This means you can paste the deleted text somewhere else once you haven’t deleted anything else since. So delete is closer to a cut than an actual delete.
Anyway, you can “delete” the character under the cursor by hitting the x key. dw will delete the word the cursor is currently over, d$ will delete text from the cursor to the end of the line, d^ to the start of the line, and dd will delete the whole line. You can also use :d$ to delete to the end of the document.
In all the above you can also add in a numerical argument to change how many letters/words/lines etc you want to delete. i.e. d2w would delete two words, and d2d would delete two lines
You can yank a piece of text to copy it from one place to another. The syntax is exactly the same as delete, with all the same options. So for example yw would yank a word, y5w would yank 5 words, yy would yank a whole line and so on.
I’m only going to cover the basic paste command here. While in command mode you can just hit the p key to paste. Of course you must have something to paste first, either through having deleted text or copied text.
To search the document you just use the good old unix search method /. That is to say, enter command mode, hit the / key and type what you are looking for. For example, if you we’re looking for the word Dublin in a document you would hit Esc (for command mode), then type /Dublin and vim will find the text for you. If you use a ? instead of a / vim will search in reverse.
You can also replace text in Vim. In fact you can do so using regular expressions but I won’t cover that here as it is far too large an area. If you are interested though look up “Mastering Regular Expressions” written by Jeffrey E. F. Friedl, and printed by O’Reilly. Regular expressions are a great thing to know.
Anyway, to replace text use the following in command mode:
:%s/find/replace/g
The : occurs quite often in Vim and is used to issue commands not covered by key shortcuts. You then type in the %s at the prompt followed by a / the phrase you are looking for, another /, what you want to replace the phrase with, and a g. The g makes the replacement global. As an example of this I’ll use the line:
John went to the shop this afternoon.
Now we try a string replacement
:%s/shop/park/g
Which will change all occurrences of the word shop to park.
John went to the park this afternoon.
Now we come to saving and exiting vim. To save a document we just use the :w command (think of it as write) in command mode. To quit without saving we will just use the :q command. If we have unsaved changes this will prompt us to save them before quitting. We can save and quit at the same time using :wq, or save discarding changes using :q! which will not prompt us to save before quitting.
For further knowledge of Vim I would recommend using the Vim tutor. This is installed with Vims common files and can be started using the vimtutor command in your terminal, as below:
$ vimtutor
This script uses the Unix mailx program to send a pre-scripted email to someone. It will take in an email address on the command line as an argument and send the mail to this address. Just copy and paste this into a file named mailerscript and change the file permissions to 755 and then your on your way! You can see how to change the permissions here if your unsure.
In order to run the script just use the command
$ ./mailerscript user@example.com
where user@example.com is the email address you wish the mail to go to.
#!/bin/sh # Usage: mailerscript <email address> if [ $1 ]; then FILE=/tmp/mailerscript-$UID.txt echo "Emailing $1..."; echo " Hi, This script will send an email to someone taking in a single argument. You can take in as many as you want though. Killian " >$FILE mail -s "Scripted mail sent" $1 -c user@example.com < $FILE rm $FILE else echo "Usage: mailerscript <email address>" fi
In Linux is extremely easy to change your MAC address. All you need is a couple of commands. To start off you will need to take down the interface to make the change. To do so just type the following into your terminal:
$ ifconfig eth0 down
Now we can get to changing the MAC address. To do this we use the ifconfig command again along with the hw switch, we then specify the interface name (in this case eth0). Finally we will use the hw switch to set the hardware type to ethernet and give the interface the new MAC address. All in all it should look something like this.
$ ifconfig eth0 hw eth 0a:1b:2c:3d:4e:5f
Finally we can bring up the interface and this time we will see the new MAC address.
$ ifconfig eth0 up
$ ifconfig
eth0 Link encap:Ethernet HWaddr 0a:1b:2c:3d:4e:5f
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::216:36ff:fef0:cf11/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:191682 errors:0 dropped:0 overruns:0 frame:0
TX packets:120012 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:28218459 (26.9 MB) TX bytes:13230519 (12.6 MB)
Interrupt:17 Base address:0xa000
Edit (Tue Jun 16 14:41:52 IST 2009): Please note this does not work with all network cards. In some cases the drivers for a card will not support changing of a MAC address. I myself have an Eeepc 901 which has this problem with a RaLink RT2860 wireless card. I’m sure in one of the driver updates it will be included but for now I’m stuck without!
The basis for this particular article (and most of the info) came from one of the guys I work with, Gavin McCullagh, who I’m pretty sure knows more stuff than is good for him. It’s all pretty handy stuff, but can be irritating to get working
If you want to forward an X session to another machine you can use the following command to do so.
ssh -X remotepc.example.com
Now if we want to we can just start an application in the terminal session opened by the above command, and the application will run on the remote computer, but be displayed on our local machine. i.e. if you were to run nautilus on the remote server sshtest we would just type the following at the command prompt:
remotepc$ nautilus
This is the same for most applications. You will need the application installed on both machines however. Also note that firefox requires additional switches in order to run in this fashion as you can see below.
remotepc$ firefox -noshm
It is possible to string multiple ssh sessions together in order to run an application on a machine in an otherwise unreachable location. For instance if you wanted to run firefox on a machine that was behind a firewall, to access a locally restricted site, but the firewall would only allow ssh from particular machines outside the network. In this instance you could ssh to the machine which is allowed past the firewall, and then set up a second ssh session to connect to the machine inside the firewall, and run firefox through the connection. See below:
ssh -CtX outsidepc.example.com ssh -X insidepc.example.com firefox -noshm
In the above command we are using a couple of switches. These are
-C This will compress the connection
-t The -t option will instruct ssh to open a new terminal upon connection.
This is required if you want to string ssh sessions together
-X This will pass the X aapplication through the connection
You can use ssh to forward ports from a remote machine to your own. The main application I would use this for myself if for retrieving my gmail in mutt while in work as we block the required ports. To do this I would issue something like the following command:
ssh -gL 192.168.1.1:993:imap.googlemail.com:993 -gL 587:smtp.googlemail.com:587 killian@example.com
In this example the server at.example.com should be a machine on which it is possible to access these ports. i.e. either a machine with access through the firewall or in your DMZ. Once you have used this command you can just open up your email client normally and the port on the remote pc will listen for connections and they will then be passed on to your own machine.