Category Archives: Code Samples

All Code Samples go here.

Command Line Packet Sniff Existing Running Process in Linux Comments Off

Have you ever come across a server that is doing a lot of traffic? Maybe you have logged in to see a process running at 100% CPU, so you know the culprit, but instead of kill -9ing it, wouldn’t it be great to see what exactly it is up to? Or even if you see a process and don’t know exactly what it is doing, and you are just curious what it is up to? As with most issues there are several ways to skin this cat. You can use tcpdump or wireshark to sniff the all of the network traffic on the device. If you know the port the program is running on (you can use lsof for that), you can restrict traffic to that port. But what if the program is jumping ports, or even uses a side-port for some sort of data transmission (UDP?). The main problem….

Error While Mounting an ISO Image in Linux: ioctl: LOOP_SET_FD: Invalid argument 3

I recently received this error while mounting an iso image in a CentOS 5.3 install: 12[root@host ~]# mount -t iso9660 -o loop /mnt/glusterfs/ecp-spe-4867.iso /mnt/iso/ ioctl: LOOP_SET_FD: Invalid argument For more detail: 1234[root@host ~]# mount -v -t iso9660 -o loop /mnt/glusterfs/ecp-spe-4867.iso /mnt/iso/ mount: going to use the loop device /dev/loop0 ioctl: LOOP_SET_FD: Invalid argument mount: failed setting up loop device So what could this mean? The confusing error message “ioctl: LOOP_SET_FD: Invalid argument” means that your ISO image is on a filesystem that is not supported for the loopback device on your system. In my case, that was a GlusterFS mount that was hosting the image. I copied it into another directory on my root ext3 filesystem and it mounted just fine!

A Twitter Search WordPress Plugin 12

Ok, this is not really a plugin per se, but WordPress already has the capability of displaying a Twitter search stream via it’s RSS feed widget. It is dirt simple to set up. Go into Appearance -> Widgets and select the widget area you wish to add the twitter search stream to; Add “RSS” and position the widget accordingly. Click “Edit” and “Enter the RSS feed URL here:”. This is the link from search.twitter.com where it says “Feed for this query”. Enter a title, if appropriate. Thats it! You will see an area on the site such as the one below: To summarize: There is no Twitter Search Plugin but WordPress’s RSS feature works just fine!

Ubuntu Server in Place Network Upgrade From 8.10 to 9.04 1

It is easy to do an in-place upgrade of Ubuntu Server from 8.10 ‘Intrepid Ibex‘ to 9.04 ‘Jaunty Jackalope‘. You can do this remotely over ssh or whatever you use to control your server. Best practices say to make sure to backup your server before doing the upgrade. I’ve done several servers this way with no issues! Issue the command: 1sudo apt-get update; sudo apt-get upgrade; sudo apt-get install update-manager-core; sudo do-release-upgrade Follow any prompts to first upgrade the current distribution with the newest packages, then do the release upgrade.

Easy Search and Replace in Multiple Files on Linux Command Line 15

I recently came across a typo that existed in a bunch of html files on my web server. I thought it should be easy enough to change, but since it was in a number of files, editing it by hand would be time consuming. Fortunately, there is an easy, one liner command to replace the text in multiple files in a sub directory using recursion. grep -lr -e ‘<oldword>’ * | xargs sed -i ‘s/<oldword>/<newword>/g’ This command broken down: grep for the word in a files, use recursion (to find files in sub directories), and list only file matches | xargs passes the results from the grep command to sed sed -i uses a regular expression (regex) to evaluate the change: s (search) / search word / target word / g (global replace) For more information, see man pages for grep, sed, and xarg. Also it is very handy to….

Password Protected Folder Gives 404 Not Found in WordPress Installation Sub-folder. 32

Came across this little maddening issue again today after fixing it a few months back. I created a directory that is password protected using a .htaccess file. However, when trying to access this folder or anything under this directory, a File Not Found 404 error from WordPress is displayed before it even prompts you for the password. The problem here lays within the main WordPress .htaccess file The default .htaccess file for WordPress is: 123456789# BEGIN wordpress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END wordpress This means that if a file is requested from the server, if it is not a file that exists in the server’s folder directory (!-f) and if it is not a directory that exists in the server’s folder directories (!-d) then pass the request onto index.php. This way, WordPress will handle both customized….

Installing And Compiling Zabbix Client / Agent 1

Zabbix is an excellent system monitoring package. It does everything from basic availability checking to detailed system resource analysis. It is capable of graphing the variables pulled from the system, and alerting admins if there is a problem or something needed for attention. Once you have the Zabbix server set up, you need to install the client on any systems you want to monitor. Windows systems have a precompiled binary to install. On linux, unix or freebsd systems you’ll need to compile binaries. If you have a range of systems that are homogeneous, you can port the binary to those or also compile it with static dependencies. Below are steps to compile, configure and install the zabbix client: Steps to install a Zabbix Client Download zabbix source code from www.zabbix.com; decompress with ‘tar zxvf’ and cd to directory Configure the make program: ./configure –enable-agent Compile and install the program: make….