Posts Categorized: shell

Using Sed to convert Mac Address

I have output from a router (but I believe modem output may be similar) with mac addresses in the format: 0050.56AC.4022 Four digit blocks separated by dots but I needed it in the format of 2 digit blocks separated by colons. My router output was lines like this: INTERNET  123.111.123.111   8      0050.56AC.1765  ARPA  VLAN.1.16… Read more »

Web Screenshots with Xvfb and Khtml2Png2

To get that headless Linux server capturing screenshots of web pages we need: Xvfb e.g. apt-get install xvfb Khtml2png2 (and dependencies) After installation of the above the steps are below and I wrapped it up into a PHP script which also did some database tasks to keep records of the screenshots. 1.Check if the Xvfb… Read more »

Remove Line Breaks with tr

I had a text file with multiple lines of input that I was manipulating using awk and sed but I found the following ‘tr’ command easiest to remove the line breaks: cat input.txt | tr -d ‘\n’

Zero Filling a Disk in Linux

The simple way to wipe or zerofill a disk is: dd if=/dev/zero of=/dev/sd? bs=1M However I found an article describing how to zero-fill with a progress indicator using pipebench, installed on Debian/Ubuntu with: sudo apt-get install pipebench then use: tr ‘\000’ ‘\377’ < /dev/zero | pipebench | sudo dd of=/dev/sd? Substitute the question mark for… Read more »

Bash: Looping through Files with Spaces

I was trying to move some miscellaneous music files into directories by artist name. The files (and folders) have spaces in the file names. For my first attempt I tries a for loop e.g. for file in $(find /path/to/music -type f); do … done A for loop will not do this regardless of how much… Read more »

echo with new lines

For future reference: echo “This does not give \n a new line” does not work. I had used printf sometimes but the -e switch also works for echo: echo -e “This gives \n a new line”

nslookup mx records

$ nslookupDefault Server:  dnsserver.comAddress:  111.222.111.222 > set q=mx> mymailserver.domain.com

Killing Memory Hogs

On an old server I temporarily added the following script as a cron job to find and kill processes using too much memory. This is just a stop gap until we get to the root of the problem. #!/bin/bashfor i in `ps -efl | grep “httpd” | awk ‘{ if ($10 > 16000) {print $4″… Read more »

Crontab -e returns a number

On a solaris system I sometimes try to edit the crontab file with crontab -e and all I get in return is a number (signifying the number of characters by the ed editor I believe). # crontab -e4025^C?The crontab file was not changed. I need to Ctrl-D to exit.To get the ball rolling again: EDITOR=vi;export… Read more »