Posts

Find Subnet Mask with ipcalc

An easy way to convert a subnet mask from bit notation (e.g. /24) to dotted decimal notation is to use ipcalc from any linux box. The -m option displays the subnet mask. $ ipcalc -m 10.10.10.128/25 NETMASK=255.255.255.128 $ O.K., that's fine, you say, but how do I know how many hosts are on the subnet? That's easy enough -- just use the -b option to find the broadcast address. $ ipcalc -b 10.10.10.128/25 BROADCAST=10.10.10.255 The range of IP's will be from one more than the network address up to one less than the broadcast address. In the example above the IP address range is 129-254. Often the gateway is the first or last address in the range to avoid confusion. If you don't have access to a linux box, you can always do a google search for "subnet calc," where you can probably find an online subnet calculator. For the opposite calculation - find prefix from subnet mask, use the -p option. $ ipcalc -p 10.10.10.128 255.255.255.128 PREFIX=25 $ There y...

Convert a Text File to HTML

Image
While considering how to make my shell scripts look better on the web, I started looking at freshmeat.net for programs that would convert source code to html. Then I thought, vim already has syntax highlighting. I wonder if it has a way to convert to html. Sure enough, it can be done with a single command: :runtime! syntax/2html.vim Convert Text File to HTML :runtime! syntax/2html.vim : convert txt to html :h 2html : help about 2html :wq! : write the new file The current file is converted, and an .html extension is added. Once the file is saved, it can be opened in a browser. For more vi tips, check out: http://systemnotesorg.blogspot.com/search/label/vi And the official vim site: http://www.vim.org/tips , Here is a beautiful example of C source code that was quickly converted to HTML, while preserving all of vim's color coding: http://systemnotes.org/download/matrix/matrix.c.html

Backup Logs with a Shell Script

Image
Here is a very simple way to backup and compress subdirectories. Normally you would want to copy them to a remote location in case something happens to the original drive, but in this case the concern is that disk space is filling up. Suppose you have a program that is generating log files every day, let's say they are key performance indicators (kpi) for some system that you are testing. The log files are pure text, but after a while, they take up a lot of space. One way to compress text is to use gzip, but since tar has an option (-z) to tar and gzip all at once, it may be one of the easiest solutions. #!/bin/sh # compress logs in /opt/multicast_kpi/record # by ScottM, 20080613 # Set variables TODAY = " `date +%m%d%Y` " ARCHIVE_DIR =/opt/multicast_kpi/record # move to working directory cd $ARCHIVE_DIR # For each subdirectory, make a .tgz file of it's contents, and then delete the originals. for dir in `ls -1 $ARCHIVE_DIR | grep -v " .tgz " | gre...

How to Copy Directories Using Tar

To copy all files from /usr/local/source to /usr/local/destination, there are several options. Tar cd /usr/local/source tar -cvf - . | (cd /usr/local /destination ; tar -xvf -) This method uses tar, but rather than create a file, it writes to a stream "-" in std output. The stream is piped to another tar command, after changing to another directory. cp -a cp -a /usr/local/src/* /usr/local/destination Other options: cpio dd

How to install a module from CPAN

Image
perl -MCPAN -e shell I always seem to forget this simple syntax, so I thought it would be good to post it where I can find it. Where else, my blog -- by the way, this is another excellent use for blogs. Not only do we publish information for others to find, but occasionally a blog is the best place to put frequently accessed info that the author may need. At least I know the source is reliable. :-) How do I install a module from CPAN? The easiest way is to have a module also named CPAN do it for you. This module comes with perl version 5.004 and later. To get a cpan shell, try either cpan: Linux:   $ cpan Windows:  C:\>cpan or the more complete command: $perl -MCPAN -e shell Terminal does not support AddHistory. cpan shell -- CPAN exploration and modules installation (v1.7601) ReadLine support available (try 'install Bundle::CPAN') cpan> The first time the command runs, it will prompt for a series of configuration questions. Now, within the...

BCC Howto

Image
Get your Friends to use BCC Send this link, or the contents of this post, to all your contacts, ...using BCC, of course. When you receive a forwarded message, reply with a simple message, such as one or more of the following: "Please don't forward any email to me without using BCC. " "Please don't put my email address in the To or CC fields of messages being sent to people I don't know!" "Please protect email addresses as you would unlisted phone numbers." "Please don't forward any email to me with my email address in the To: or CC: fields." "This is how spam and viruses get spread. See this article for more details -- BCC HOWTO " What is BCC? BCC (Blind Carbon Copy), is the practice of sending an e-mail to multiple recipients without disclosing the complete list of recipients. Unlike addresses in the To: or CC: fields, addresses in the BCC: field cannot be seen by other recipients. Reasons to use B...

Sudo Make me a Sandwich

Image
You may have seen this artwork around the office where Unix / Linux geeks hang out. This is where you can find it: http://xkcd.com/149/ Powered by ScribeFire .