Tuesday, December 11, 2007

Mail a Text File from the Shell

Would you like an easy way to send files to someone outside of your local network, or quickly test a mail server?

Well the old "mail" command is still available, and it comes in handy for sending config files, or using within a shell script.

This is all you need:

$ mail -s test me@company.com < /etc/hosts

That's the shortcut. If you want more details, you can read the rest of the post...

Using the mail command

1) Use Mail Interactively to read mail
a) type Mail
b) enter the number of the message to read, press enter
c) press space to page down, n for next message
d) ? for help
e) q to quit

2) Use mail Interactively to send mail
a) type mail command followed by email address
b) Enter subject, press enter
c) Enter text of message
d) press Ctrl-d on a line by itself when finished
e) Enter CC: if desired, or press Ctrl-d again

$ mail user@company.com
Subject: test
Here is my test message
<Ctrl-d>
Cc: <Ctrl-d>$

For a little less work, add the subject to the command prompt. Remember to use quotes if the subject it more than one word.

$ mail -s "mounting" user@company.com
Scott,

Can you help me troubleshoot my mount problem?

<Ctrl-d>
Cc: <Ctrl-d>$


3) Use mail to Send a Text File

Imagine that you just asked your friend to help you troubleshoot your partitions, and then he asked you to send a copy of your fstab file. Your first thought may be, "how can I copy and paste this into my mail program?", or "how can I get this file to my Windows machine where my mail program is running?" If you have synergy running, it's easy enough -- http://systemnotesorg.blogspot.com/2007/05/how-to-copy-and-paste-in-linux-and.html Then you think, I can use firefox, and attach the file to an email, or paste the text into the message, but that takes a few steps. And then what if X isn't running?

Sure you could copy the file to an nfs mounted partition, or scp the file to another machine that has X or Windows running. But I think one of the easiest ways to email a text file is to use a single mail command from a shell prompt:

$ mail -s "My fstab File" myfriend@mycompany.com < /etc/fstab

Remember to only send text files, unless you want to uuencode a binary file, but that is usually not the most practical way to move binaries. That sounds like a topic for another day...

Summary of the mail program

In summary, here are three common ways to use Mail / mail:

1) Interactively read: Mail
2) Interactively send: mail user@company.com <ctrl-d> to end
3) Automated send: mail -s "My fstab File" myfriend@mycompany.com < /etc/fstab

Note that option 3 may come in handy for testing a recently installed mail server, such as may be required on an RHCE exam. It is also good for mailing log output, which is what logwatch does.

A Little Background

You may be familiar with the Mail command (upper-case "M"), which is convenient for reading mail on the system when pine or mutt hasn't been installed. The the little mail command (lower-case "m") is very convenient for sending mail from the command prompt with a simple one-liner command.

On modern linux systems Mail and mail may be the same program but historically they were different programs. On your system you can check for the mail program:

[ /]$ which mail
/bin/mail
[ /]$ which Mail
/usr/bin/Mail
[ /]$ ll /usr/bin/Mail
lrwxrwxrwx 1 root root 14 Sep 20 2006 /usr/bin/Mail -> ../../bin/mail
[ /]$

Note that /usr/bin/Mail is a symlink to /bin/mail on this rhel4 system.

Saturday, December 1, 2007

Vim Tips -- Search and Replace


Did you ever wonder if there was an easy way to send an example file for someone to look at, but still keep your private information safe?

Sure you can use a sed, or perl one-liner, as I discussed: using-bash-and-sed-to-modify-text-file.html, but why not use search and replace in vi / vim before publishing your info? That way you can see exactly what you are changing. Remember, while vim is installed by default on most Linux distros, is also available for Windows, and it is free -- http://www.vim.org

Suppose you have part of a log file, or nmap output that contains real hostnames, a real domain name, and real IP addresses. You want someone to help you troubleshoot something, but you don't what to give the real info for everyone to see.

Start with the info in a text file, such as this:

Host realhost-1.realdomain.com (192.168.0.54) appears to be up.
Host realhost-2.realdomain.com (192.168.0.55) appears to be up.
Host realhost-3.realdomain.com (192.168.0.56) appears to be up.
Host realhost-4.realdomain.com (192.168.0.57) appears to be up.
Host realhost-5.realdomain.com (192.168.0.150) appears to be up.
Host realhost-6.realdomain.com (192.168.0.151) appears to be down.

With a few quick search commands, the output can be converted to this:

Host xyz-1.example.com (10.10.10.34) appears to be up.
Host xyz-2.example.com (10.10.10.35) appears to be up.
Host xyz-3.example.com (10.10.10.36) appears to be up.
Host xyz-4.example.com (10.10.10.37) appears to be up.
Host xyz-5.example.com (10.10.10.130) appears to be up.
Host xyz-6.example.com (10.10.10.131) appears to be down.


O.K., here are the commands.

The fastest way to replace "realhost" with "xyz" on every line in the file is to use the %s command:

To enter command mode, press <esc>
:%s/realhost/xyz/g

What this means is
% = every line in the file
s = search
/realhost/ = pattern to search for
/xyz/ = text to replace with
g = global

Suppose you want to do this on almost all lines, but would like to confirm each replacement. That's easy, just use a "c" for confirm.

:%s/realhost/xyz/gc

c = confirm

O.K., but what if you only want to replace a few lines in the file? Simply use the line numbers separated by a comma instead of the "%" symbol:

:7,12s/192.168.0/10.10.10/g

Use ".", or nothing to search and replace only on the current line:

:s/5/3/gc

The items between the slashes are called regular expressions, and work as expected. When searching for special characters, e.g. "$ / ^", etc. they must be escaped by using a backslash "\" (Use \\ to get a literal backslash).

That's it. You're done, so save the file, and quit
<esc>
:wq!

Here is a list that may come in handy:

Vi / Vim Substitution and Regular Expressions Cheat Sheet


Vi / Vim Substitution and Regular Expressions
----------------------------------------------
% = every line in the file
s = search
/ / = pattern to search for
/ / = text to replace with
g = global
c = confirm each substitution
p = Print the line after the change is made

Regular Expressions (regex)
---------------------------
. = Matches any single character (including spaces), except newline.
* = Matches zero or more of the preceding single character
^ = Match at the beginning of line, used at the beginning of a regex
$ = Match at the end of the line
\ = Escape special characters
[ ] = Match any one character, e.g. [a-z] = lowercase, [^a-z] = not lowercase
\( = Save pattern
\< = Match characters at the beginning of a word

POSIX character classes
------------------------
[:alpha:] = Alphabetic characters
[:digit:] = Numeric characters
[:alnum:] = Alphanumeric characters
[:space:] = Whitespace characters
[:blank:] = Space and tab characters
[:cntrl:] = Control characters
[:upper:] = Uppercase characters
[:lower:] = Lowercase characters
[:graph:] = Printable and visible nonspace characters
[:print:] = Printable characters including whitespace
[:punct:] = Punctuation characters
[:xdigit:] = Hexadecimal characters

Metacharacters Used in Replacement Strings
-------------------------------------------
\n = Replaces with text matched by the nth pattern -- \( \)
\ = Escape special character
& = Replaced with entire text matched by the search pattern
~ = String found replaced by text of previous search
\u, \l = Change next character to upper or lowercase

Ping Multiple Hosts Using Bash Nmap and Fping

I explained how to get a list of hosts using nmap -- using-nmap-to-generate-host-lists.html, but here is another look at the subject.

The question is, how do I ping multiple hosts to find out which ones are down? Sure this could be considered a topic of system monitoring, but maybe you just want to reboot a bunch of machines, and make sure they all come back online. This quick check will tell you whether there is a problem or not.

Here are three methods for pinging a list of hosts:

1.) for host in `cat all.txt `;do ping -c 1 $host; done
2.) nmap -sP -R -iL all.txt
3.) sudo fping -u < xyz/all.txt

First, we assume that you have a text file named all.txt that contains a list of hostnames, one per line. Obviously, the examples here contain fake hostnames, domain names and IPs, as described in another article about vi: vim-tips-search-and-replace.html.

--- all.txt ---
xyz-1
xyz-2
xyz-3
xyz-4
xyz-5
xyz-6
xyz-7
xyz-8
--- end all.txt ---

1.) Use a for loop in the shell

$ for host in `cat all.txt `;do ping -c 1 $host; done
PING xyz-1.example.com (10.10.10.34) 56(84) bytes of data.
64 bytes from xyz-1.example.com (10.10.10.34): icmp_seq=0 ttl=62 time=0.472 ms

--- xyz-1.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.472/0.472/0.472/0.000 ms, pipe 2
PING xyz-2.example.com (10.10.10.35) 56(84) bytes of data.
64 bytes from xyz-2.example.com (10.10.10.35): icmp_s eq=0 ttl=62 time=0.459 ms

--- xyz-2.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.459/0.459/0.459/0.000 ms, pipe 2
PING xyz-3.example.com (10.10.10.36) 56(84) bytes of data .
64 bytes from xyz-3.example.com (10.10.10.36): icmp_seq=0 ttl=62 time=0.390 ms

--- xyz-3.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.390/0.390/0.390/0.000 ms, pipe 2
PING xyz-4.example.com (10.10.10.37) 56(84) bytes of data.
64 bytes from xyz-4.example.com (10.10.10.37): icmp_s eq=0 ttl=62 time=0.382 ms

--- xyz-4.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.382/0.382/0.382/0.000 ms, pipe 2
PING xyz-5.example.com (10.10.10.130) 56(84) bytes of data .
64 bytes from xyz-5.example.com (10.10.10.130): icmp_seq=0 ttl=63 time=0.195 ms

--- xyz-5.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.195/0.195/0.195/0.000 ms, pipe 2
PING xyz-6.example.com (10.10.10.131) 56(84) bytes of data .

--- xyz-6.example.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

You can see that even for the six hosts we are checking for, there is quite a bit of extra info to look through to find out if a host is up or not.


$ for host in `cat xyz/all.txt `;do ping -c 1 $host; done | grep -v "\=" | grep -v PING
--- xyz-1.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms

--- xyz-2.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms

--- xyz-3.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms

Not as bad, but we can do better. The above example still takes three lines to show the results (hostname, %packet loss, and a blank line). Using a different tool give much better results, so why did I waste your time looking at this method? Well, it still may be easier to use ping, since it will most likely be installed by default, and you can do tricks with the input file that may not work with the other methods. For example, if your input file contains lines that start with a "#" you can use grep -v to skip those lines, but other tools may expect cleaner input.

2.) Use nmap

So let's try the same thing with nmap.

$ nmap -sP -R -iL all.txt
Reading target specifications from FILE: all.txt


Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
Host xyz-1.example.com (10.10.10.34) appears to be up.
Host xyz-2.example.com (10.10.10.35) appears to be up.
Host xyz-3.example.com (10.10.10.36) appears to be up.
Host xyz-4.example.com (10.10.10.37) appears to be up.
Host xyz-5.example.com (10.10.10.130) appears to be up.
Host xyz-6.example.com (10.10.10.131) appears to be down.

Much cleaner, isn't it?

For even less info to sift through, you can use grep to look for hosts that are up or down.

$ nmap -v -sP -R -iL all.txt | grep down
Host xyz-6.example.com (10.10.10.131) appears to be down.

Then, of course it can be cleaned up further with a simple awk print statement.

$ nmap -v -sP -R -iL all.txt | grep down | awk '{print $2}'
xyz-6.example.com

3.) Use fping

Another option is fping, but it has the disadvantage that it is probably not installed by default, and it has to be run as root (or sudo), unless additional configuration is performed. It does give very nice output, and is very fast.

Show me all hosts from my list that are down:
$ sudo fping -u < all.txt
xyz-6


Wednesday, November 28, 2007

Shell Console Reset

Did you ever cat a file that caused the terminal to display all kinds of strange characters? Pressing Ctrl-C and Enter, or typing clear doesn't get the console back to normal. The characters are there, but they are unreadable. A quick way to fix this is to use "reset" -- type:

$ reset

That should bring the console back to normal.

Of course, if you just want to clear the screen, you can type "clear" ("cls" in DOS, or a Windows command prompt).

Wednesday, September 5, 2007

Defeat Telemarketers for FREE!


While researching anti-spam techniques, I came across an anti-telemarketing technique that has proved quite useful. Within a few weeks, it noticeably reduced the amount of telemarketer calls I was getting.

Here is the original article, which I copied:
The original site seems to be down (http://home.comcast.net/~dakine_101798/spambeater.htm):
so I have a copy on my systemnotes.org site -- http://www.systemnotes.org/notes/security/Defeat_Telemarketers_for_FREE.html

Defeat Telemarketers for FREE!

Yes! You can stop Telemarketers COLD!

Now you can save that $40.00 you were thinking of spending on a TeleZapper. You can even save a couple bucks on the eBay Auctions for this sound file.

The TeleZapper is a device that plays the first tone in the three tones that precede the telephone company's historic "This number has been disconnected" message. Most telemarketing predictive dialers listen for that tone, and when it is present the dialer assumes the number is disconnected, The result is, the telemarketing dialer will immediately disconnect and delete your phone number from it's data bank.

This is incredibly easy to set up, if you have an answering machine and speakers for your computer you have everything you need.

If a computer Telemarketer calls, they
won't leave a message (because the dialer has hung up, removed your phone number from the database and moved on to the next number in it's database). If it's a friend, well; life is normal, no change. If you're not home, they can record a message for you. your friends will hear the 'DO-DA-DEE' and then your voice greeting, after which they can leave a message. (Or if you use the single tone they will hear just 'DO'.) If after hearing who's on the other end of the line and you want to take the call, simply pick up the handset and say "Hello"

Follow the instructions listed below and all of your calls will be screened AUTOMATICALLY!

Here's How it's Done:

Put your TELEPHONE ANSWERING MACHINE next to your computer speaker, (Or the other way around) and play the sound file. Record the sound file at the beginning of youre outgoing message, then simply complete your voice greeting. You've done it! Yep, that's all there is to it. It's that easy, It's that fast!

Now just sit back and let your answering machine screen the incoming calls.

After perhaps a month of letting your answering machine screen all of the evening and weekend incoming calls, you'll have the same results as a $40.00 TeleZapper.


This will work on any answering machine, digital or tape based and is compatible with Call Waiting & Caller ID. It will even work with the answering service provided by most telephone company's. (Except you don't get to screen your calls this way, because you would not be able to hear the callers message).

It's very satisfying to hear the phone ring, then find out there isn't anyone (or anything) there. Oops another Telemarketer bites the dust!. Hehehe!

What? You don't have the tones?

Download the sound file of the telephone company disconnect tones here. ((Single tone here) (Right click and select Save Target As.)) Or the Zip file for both sound files is here.

Please feel free to send your friends and family to this web page. Please feel free to duplicate this web page in whole or in part and put it on your own web site.

I don't want credit. I want computerized Telemarketers out of business! Also, I can't understand how the TeleZapper manufacturers can sleep at night, selling their product for $39.99.

I work for a major Telecommunications company. I'm just trying to help everyone save money and get rid of telemarketing calls.

Interesting development, The TeleZapper folks have replaced the older version of their device. The one they have now does not require an AC adapter, rather it uses a battery that must be replace periodically. It also has a switch to allow for "Advanced Mode" which actually causes all 3 tones to play. The newer device retails for $39.99, a $10.00 drop in price from just a few months ago. On eBay the new ones have an average price between $25 & $30, so it makes sense not to buy retail at the very least.

There isn't a down side to using the tones I'm providing. Not even 1. (Well there is a possibility that the Medical Systems Dialers may disconnect as well. This may mean that you would not receive appointment reminders. However, Kaiser Permanente in California does not disconnect. I suspect that at least some of these medical dialers do not detect the tones. If this concerns you, you can check with the medical facility IT (Information Technology) professional. Ask your doctor for his/her phone # Please note: This is a risk you take by using the TeleZapper as well).

Addendum:

I have had numerous e-mails asking if the single tone sound file is as effective as the 3 tone sound file. Also people want to know the difference between them.

The single tone file currently works just as well as the 3 tone file, most of the current Telemarketer dialers only hear the 1st tone. It will then immediately disconnect, delete your number from it's list, then it dials the next number in it's data base.

The phone company decided years ago that the 3 tone system would be implemented just in case additional tones were going to be required. To this date it has not been necessary to use the additional two tones. It was thought they may be useful for redirecting or emergency services, other options proved to be easier to implement.

These tones will work on any phone system in any country that recognizes 'Tones'.


The Federal Trade Commission is getting involved.

Click here to register online beginning on July 4, 2003

California Residents can pre-register with the CA Dept of Justice right now!

View FTC Telemarketer Rules here

***Serious Update Scammers at work!***

VTech answers the challenge! OK, this way you are buying a TeleZapper but you're getting a cordless 2.4 GHZ phone with CallerID too. All for $49.95, the cost of the original TeleZapper.

Thursday, July 5, 2007

Beginner's Guide to the Vi editor

The article linked below is a nice introduction to the Vi editor.

People often ask why they have to learn vi, or vim. One important reason is that it is the editor most likely available on any linux or unix system you may have to manage as a sysadmin. Less experienced sysadmins may say that they can just install joe, or pico, or something similar -- until I show them 1200 linux boxes that we have to manage! Anyway, once you have the basics, you can add more knowledge as you go.

First realize that there are two modes - command mode, and editing mode. "i" puts vi into editing mode, and [esc] goes back to command mode.

You can get by with just a few commands at first:
vi file.txt
i (insert -- go into editing mode)
[esc] (move around)
[esc]:wq (save)
[esc]:q! (quit without saving)


read more | digg story

Links:
http://www-acs.ucsd.edu/info/vi_tutorial.php
http://www.viemu.com/vi-vim-cheat-sheet.gif

Thursday, May 31, 2007

Use CheckInstall Instead of Make Install

Did you ever look for a binary, and as a last resort download the source to compile yourself?   Of course you were disappointed that the program would not be part of your package management system.

Usually you have to run something like this:

  ./configure
  make
  make install

An easy way to create an .rpm or .deb file from source is to run checkinstall instead of "make install" during the standard install from source.

http://freshmeat.net/projects/checkinstall -- CheckInstall Freshmeat Page

http://checkinstall.izto.org -- CheckInstall Home Page

CheckInstall keeps track of all files installed by a "make install" or equivalent, creates a Slackware, RPM, or Debian package with those files, and adds it to the installed packages database, allowing for easy package removal or distribution.


Wednesday, May 30, 2007

Don't Torrent That iTunes Plus Song...

Sure, you can now download music from the iTunes store without DRM but that doesn't mean you should just willy nilly start sharing that music with your friends. For one thing, it's illegal. For another, your account information is embedded into that m4a music file. Don't believe me? Try this yourself.


The site is mostly for Mac users, but the strings command works in linux, and cygwin for Windows. This link has interesting comments as well.



read more | digg story

Tuesday, May 22, 2007

Blogger Digest: Using VNC And Redhat Linux

VNC is an excellent way to remote control linux and Windows machines. Here is a description, and links to the programs.

Blogger Digest: Using VNC And Redhat Linux

Monday, May 21, 2007

Did you know these basic Firefox Tips?


You May know those BIG things But Did you know these? Excellent list of easy firefox tips to implement -- e.g., press Esc to stop animated gifs from moving...


# To quickly find any word in a web page type /word it will highlight the word and press Ctrl+G to “Find Again” that same word again

# If you wish to remove an item from your Address Bar Drop down menu,Highlight it without clicking and use Shift+Delete.

# To stop animated gifs from moving, press the ESC key.



read more | digg story

Wednesday, May 16, 2007

RHCE Study Notes - HTTP

These RCHE study notes were designed to be brief reminders of what you should already be familiar with. This topic covers HTTP server configuration.

One thing to be aware of when working with Apache and the 2.6 kernel is SELinux.

Overview of SELinux

SELinux, is a Mandatory Access Control (MAC) security system for Linux based on the domain-type model. It was written by the NSA (http://www.nsa.gov/selinux/ ) and is comprised of a kernel module (included in all 2.6 kernels), patches to certain security related applications, and a security policy.

More info: http://www.redhat.com/magazine/001nov04/features/selinux/

Study Notes

Here are the brief steps from my RHCE study guide to help you remember the steps to configure a virtual host, and configure permissions.

* HTTP/HTTPS
install httpd, check context with ls -Z
  Q: Create a virtual host www1.example.com w/ subdirectory /var/www/html/www1
  A:
   1) install httpd, modify /etc/httpd/conf/httpd.conf file
    <VirtualHost 192.168.0.1:80="">
    ServerName www1.example.com
    DocumentRoot /var/www/html/www1
    </VirtualHost>
   2) chcon -R --reference /var/www/html /var/www/html/www1
   3) service httpd restart
   4) chkconfig httpd on
  Testing
   service httpd configtest
   ls -Z /var/www/html/www1

The important things to remember are "chcon" to change the context, and "ls -Z" to check it.

Tuesday, May 15, 2007

How to Use Peer to Peer Safely

About P2P

P2P software is free, and legal to install and use, but it does make sharing of copyrighted material easy to do, and that is not legal. Are people still using P2P software after Napster got shut down? Yes, they certainly are. Free music downloads? Free software? -- well be careful about copyrighted materials, but the technology is interesting nonetheless. One of the best ways to get a large file, such as a linux iso file, is to use bit torrent.

Dangers

What are the dangers, and inconveniences of using peer to peer file sharing software such as Limewire, eDonkey, Azureus, or Bittorrent?

1.) The content quality is only as good as how trustworthy the peers are
2.) Some content is copyrighted, and may be illegal to share or download on this type of network
3.) Content may contain viruses, trojans, and decoys
4.) Excessive traffic may cause your ISP to limit your bandwidth usage
5.) Some downloads may take days to complete
6.) There may be pornography disguised as something else
7.) Some software may take up resources on your computer

Protocols

If you must use Peer to Peer file sharing software, try the File Donkey or Bit Torrent protocols. The products listed have legitimate uses, and are available on different platforms -- e.g. Linux, Mac, and Windows, but not all programs are listed here.

File Donkey

Has the advantage that things are easy to find, but downloads may take a few days.

http://sourceforge.net/projects/emule - eMule

Bit Torrent

Has the advantage of the fastest possible download, but finding torrent sites may be a challenge. Often used for large files, and recent releases.

http://www.bittorrent.com/ - Bittorrent

http://azureus.sourceforge.net/ -- Azureus

Azureus implements the BitTorrent protocol using java language and comes bundled with many invaluable features for both beginners and advanced users

http://aresgalaxy.sourceforge.net/ - Ares

Ares is a free open source file sharing program that enables users to share any digital file including images, audio, video, software, documents, etc.

Ares also has a good list of p2p risks:
http://aresgalaxy.sourceforge.net/p2prisks.htm

One of the most popular Bit Torrent sites has been http://www.suprnova.org -- Supernova, but now they started charging, so you'll have to decide if it's worth it. There are plenty of torrent sites you can find with a Google search.

Gnutella

Older, popular network, but there may be lot's of junk files, and downloads can be very slow. Also, some clients such as limewire are often considered to be resource hogs.

If you want use a gnutella client, such as limewire, consider using Creedence to identify junk files.

http://www.limewire.com/ -- Limewire

http://sourceforge.net/projects/credence/ -- Creedence

Credence is a decentralized system for identifying spam and decoy files in peer-to-peer networks. Credence is a complete Gnutella client, built on LimeWire, that lets you vote on objects and filters junk files from your search results.

Older gnutella client software either had spyware and adware built-in, e.g. Bearshare, Kazaa, or the network got flooded with spyware and adware, which caused the software to be blamed.

Privacy Protection

If you are afraid of being tracked for using a P2P network, you can block sites by using software such as PeerGuardian -

http://phoenixlabs.org/pg2/ -- Peer Guardian

PeerGuardian 2 is Phoenix Labs’ premier IP blocker for Windows. PeerGuardian 2 integrates support for multiple lists, list editing, automatic updates, and blocking all of IPv4 (TCP, UDP, ICMP, etc), making it the safest and easiest way to protect your privacy on P2P.

Also, make sure you have antivirus and anti-spyware utilites installed, if you are running Windows connected to the internet.

Monday, May 14, 2007

Fresh release: Vim 7.1

After one year and five days of waiting: a brand new Vim release! This is a stable version. There are many bug fixes and updated runtime files. No amazing new features. Upgrading from a previous version is highly recommended...

Note that Vim works on Linux, Windows, Macintosh, and other systems. This is an excellent free editor with syntax highlighting that is great for programming, text manipulation, and HTML editing.

If you plan to be a sysadmin, you have to learn vi. I use it for scripting, text editing, and blog posting, among other things.


read more | digg story

Saturday, May 12, 2007

How to Hide Files and Directories in Linux

In Linux, directories are not accessible until the device is mounted. This is usually done at startup by the mount command which uses the /etc/fstab file.

Files that start with a dot "." are hidden, but not completely (you can do ls -a to see the files). An example is the ~/.bashrc file. You can also hide files in a directory name that starts with a dot, e.g. ~/.ssh

Now for the real trick

Entire directories can be hidden, simply by mounting another device on top of the directory. The original files will still be in tact, but not visible until the device is remounted.

First, find a device that is available to mount (boot is nice, because it is usually small).

$ mount
/dev/hda1 on /boot type ext3 (rw)
...
etc...


Then make your stealth directory, copy files to it, and mount a directory over it.


$ cd /mnt
$ mkdir stealth
$ touch /mnt/stealth/somefile.txt
$ ls /mnt/stealth/
somefile.txt
$ mount -t ext3 /dev/hda1 /mnt/stealth
ls /mnt/stealth/
config-2.6.9-5.EL initrd-2.6.9-5.EL.img message System.map-2.6.9-5.ELsmp
config-2.6.9-5.ELsmp initrd-2.6.9-5.ELsmp.img message.ja vmlinuz-2.6.9-5.EL
grub lost+found System.map-2.6.9-5.EL vmlinuz-2.6.9-5.ELsmp


Then simply unmount when you want to access your original files


$ umount /mnt/stealth/
$ ls /mnt/stealth/
somefile.txt


Enhance your Website with Google Gadgets

Google has some excellent webmaster resources, and some fun and useful gadgets that can be quickly added to a website or blog. Just as with any good design, remember not to over do it.

http://www.google.com/webmasters/gadgets/

Here is what Google says about their gadgets:

------------------------------------------------------------------------------
Enhance Your Own Website

Add Google Gadgets to your webpage

You can now use Google Gadgets to make your webpages even more interesting and useful to your visitors. For instance, you can add your city's current temperature or a quote of the day to your own page. Just pick the gadget you want from our directory of "Google Gadgets for your webpage," customize that gadget, and copy-and-paste the HTML into your page's source code. Then, reload to see the gadget on your page.

Find gadgets for your webpage.

------------------------------------------------------------------------------

If you want to find something about cooking, recipes, or healthy foods, you can browse through the lifestyle category.

http://www.google.com/ig/directory?source=gghp&cat=lifestyle

Of course readers of http://systemnotes.org would probably be more interested in technology, or tools.

Check it out; it's a lot of fun, and you may find some useful gadgets for your readers.

Wednesday, May 9, 2007

Top Free Web Site Analysis Programs

There are two basic categories for web site tracking.

1. Online (Embeded Tracking Code)
2. Log Analysis (Software)

Onine

This type of analysis has the advantage that nothing needs to be installed on the web server. The disadvantage is that every page requires modification. That is not much of a problem for blogs, or generated content, but it can be tedious to modify a large number of pages by hand.

Google analytics is free, very simple to use, and produces excellent reports. Here are the instructions from their site:

https://www.google.com/support/analytics/bin/answer.py?answer=27323&hl=en_US

How do I track a new website?

There are two simple steps required to start tracking a new website: the creation of a new website profile, and the addition of Analytics tracking code to all of the pages you wish to track.

Create a new profile

1. From the Analytics Settings page, click Add Website Profile
2. Select Add a Profile for a new domain
3. Enter the URL of the site you will be tracking, making sure to select either http:// (most common) or https:// (secure site) from the drop-down list
4. Click Finish. The Tracking Status page appears, containing the tracking code necessary for the next steps

Add the tracking code to your pages

The code contained in the text box on the Tracking Status page must be copied and pasted into all of the web pages you will be tracking. It should be added immediately before the </body> tag, and can be added by hand or through the use of templates or includes, if available.

Log Analysis

Log analysis is a method of generating reports based on the logs that are produced by a web server, such as Apache, or IIS. This usually requires that sofware be installed on your web server. You web hosting company may or may not offer access to such a tool. If you manage the server yourself, it is not very difficult to set one of these up. Once the program is in place the reports are automatically generated.


I have had good success with Analog on both Apache and IIS.
http://www.analog.cx

It took a little bit of study to figure out what it does, but once you understand the format, and get it configured, your work is done. It generates nice reports on traffic, where visits came from, etc.

Some newly popular programs can be found on Freshmeat.net. e.g.

http://awstats.sourceforge.net

http://www.mrunix.net/webalizer

A freshmeat browse on the catetory Internet::Log Analysis, produces results of some of the more popular free web server log analysis programs.

http://freshmeat.net/browse/245/

Use Text Instead of Graphics

Sure we all want a nice looking website, but that doesn't mean you have to use lots of graphics and flash animation. It turns out, you'd be much better off using text instead of graphics. Here's the proof...

Use text instead of graphics on your website

Nowadays, it seems that every site owners knows how his site should look like: visually appealing, with a large amount of graphics (or even Flash) and, of course, with plenty of images of people, preferably women, preferably barely clothed (or naked).

But reality is that what works isn't what people, who barely know anything about web design, think to work.

read more | digg story

How to Copy and Paste in Linux and Windows

This is a very simple topic, but sometimes little tips can save you a lot of time.

Windows & Linux

First select the text, or item, or location to paste to:
Copy = Ctrl-c, or From the "Edit" menu, select "Copy"
Cut = Ctrl-x, or From the "Edit" menu, select "Cut"
Paste = Ctrl-v, or From the "Edit" menu, select "Paste"

You can copy and paste text, graphics, files, etc. In Windows, you can copy and paste files within Windows Explorer, or you can drag and drop them.

Linux

All of the above, plus:

Copy = Select text with the mouse
Paste = Click the middle mouse button

vi

If you want to copy and paste in vi, that's another topic. To copy a line in vi, type yy (yank line), and then p (paste after), or P (paste before). To copy a word, use yw (yank word). To copy five lines -- 5 yy, or five words -- 5 yw, or to paste something five times 5p.
Here are some good tips on vi http://www.vim.org/tips/tip.php?tip_id=312 .

By the way, vi is available for Windows, and is free to download and use -- http://www.vim.org. Vim is excellent for looking at and editing HTML or other code, because it has color coding and syntax highlighting.

Copy and Paste Between Linux and Windows

If you want two have monitors on your desk, you can share the keybord and mouse using an open source program called synergy. http://synergy2.sourceforge.net

Synergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems without special hardware. It's intended for users with multiple computers on their desk since each system uses its own monitor(s). Just move the mouse off the edge of a screen to move to another screen; keyboard and mouse input is then redirected to the other screen. Synergy also lets you cut and paste between systems and it makes screen savers activate/deactivate in concert.

Cygwin and Windows Command Prompts (topic added Dec, 2007)

Another question people may have is how to copy text from a cygwin window, Windows command prompt, and ssh session such as putty. The typical Windows method of copy / paste is to either use ctrl-ins (copy) and shift-ins (paste), or ctrl-c (copy), ctrl-v (paste), but in command prompts it is different. Here is the trick:

1) Select the upper left corner of the command prompt window (left or right-click)
2) From the menu, select Edit
3) From the submenu, select Mark
4) Then use the mouse to highlight the area to be copied from the command prompt window
5) Press Enter to copy it to the clipboard
6) Now go to another application and paste it.
Note: to paste text into a command prompt, use the same upper left menu, and select Edit, Paste

Monday, May 7, 2007

11 Things I can do in Linux that I can't do on Windows

1. Update every single piece of software on my system with a single action. This is one of the main reasons I run Linux. Sure, Windows has Windows Update, but that only updates the operating system, Office, and a few other things. For every Linux distribution I've used (Gentoo, Red Hat, Suse, Ubuntu), updating is simple.



read more | digg story

Saturday, May 5, 2007

"Web 2.0" in just under 5 minutes. - video

"Web 2.0" in just under 5 minutes.

This is a slightly revised and cleaned up version of the video that was featured on YouTube in February 2007.


Link: http://youtube.com/watch?v=NLlGopyXT_g

Top 7 Things System Administrators Forget to Do

Out of the plethora of chores that we do each day, which ones make up the top seven activities of forgetful system administrators? To begin, you might ask yourselves if the answer is quantitative or qualitative. Let's think about it for a minute.

  1. Forgetting to Delete a Former User's Account

  2. Forgetting to Regularly Search for Rootkits

  3. Forgetting to Use a Trouble Ticket Tracking System

  4. Forgetting to Set Up Technical Documentation and Creating a Knowledge Base

  5. Forgetting the Risks of Flash Memory Drives

  6. Forgetting to Manage Partial Root Access

  7. Forgetting Courtesy




read more | digg story

CSS Reset Reloaded

Eric Meyer, CSS Guru gives us a run down on some extreme CSS Reset. Think of these as a starting point for creating your own defaults, in addition to being a way to illuminate the nature of browser defaults. Simply the act of taking those defaults into consideration and thinking about them closely puts you ahead of 99% of your peers.



read more | digg story

Absolutely HUGE List of Color Related Sites!

Someone put together a list of just about every color related resource (worth mentioning) in the known universe. Designers rejoice!

http://www.colorschemes.org



read more | digg story

10 Reasons Why It Doesn’t Pay To Be “The Computer Guy”

Scroll down for the top 10 list.



From http://www.lifereboot.com


read more | digg story

Thursday, May 3, 2007

Using the Bash History

The command history is stored in ~/.bash_history. The history typically contains the last 500 commands typed at the shell prompt.

You can view the history by using the history command.

history | less

Then you can search for a command.

e.g. what was the name of that directory I created yesterday? Oh, yeah, I can search history for the mkdir command by using the slash.

/mkdir

You could also use grep, but with less, you can see the surrounding commands, as you often want to see the sequence of what was done.

History Shortcuts

  • !! - Executes the last command

  • !902 - Executes command number 902 (from the history list)

  • !service - Executes the command whose string matches the most recent history entry

  • Up / Down - The most common shortcut is to simply use the up and down arrows to scroll through the bash history.


Example
If you recently restarted the network service, and then wanted to restart it again, you might do something like this;

service network restart
ping somehost.example.com

You see that the network is unreachable.

Then you remember that you misconfigured something, such as gateway so you modify it:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

Now, rather than typing the entire command again "service network restart", you can simply type:

!serv

A similar shortcut can be used when you forget to type sudo.
e.g.

$ mkdir /root/test
mkdir: cannot create directory `/root/test': Permission denied
$ sudo !!
sudo mkdir /root/test
$

Or, to change the previous command, while keeping the parameter, use "!$"

e.g., change cat to vi, but keep the rest of the line
$ cat /etc/resolv.conf
search example.com
nameserver 192.xxx.xxx.xxx
$ vi !$
vi /etc/resolv.conf


see also http://systemnotesorg.blogspot.com/2007/03/unix-linux-command-tips.html

Wednesday, May 2, 2007

How to Turn on IP Forwardarding

IP Forwarding
  • Effectively makes a Linux box act as a router

  • Is usually used with two network interfaces (one internal, and one external)

  • Can be used with firewall services and is often used for NAT


Steps to Turn on IP Forwarding


 1) Modify /etc/sysctl.conf
     vi /etc/sysctl.conf
     add this line:
     inet.ipv4.ip_forward=1
 2) Make the Change Active
     sysctl -p
 3) To View Current Settings:
     sysctl -a | grep ipv4


More info can be found on the redhat site:
https://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/security-guide/s1-firewall-ipt-fwd.html


We'll leave firewall rules for another topic...

Saturday, April 28, 2007

How to Change the Root Password to Get Into a Linux Box

This procedure assumes you have console access, and are authorized to make changes to accounts on the machine, including root.

If you own the machine, you can boot into single user mode, and change the password, or create an account.

If using grub (you should see a blue bootup screen), press "a", "space", "1", "enter"
a 1
That will boot to single user mode.

Then you can change the root password
passwd

Then reboot Ctrl-Alt-Del

You should create user accounts other than root. Use the useradd command.
useradd someone
passwd someone

Friday, April 27, 2007

RHCE Study Notes - SMTP

Study notes for any exam are difficult enough to find, but RHCE material seems even more scarce. This article tells how to prepare for one of the objectives, which is configuration of an SMTP server.

RHCE Study Notes
I wrote up some study notes as I was preparing for the RCHE exam. Here are some quick notes based on the official RedHat objectives, labs, and possible questions I thought might be reasonable requests.

SMTP Related Questions
install sendmail, sendmail-cf, sendmail-doc (optional)

Q: Configure mail server to accept internet email
A: modify /etc/mail/sendmail.mc
1) cd /etc/mail
2) vi /etc/mail/sendmail.mc
search for 127.0, put dnl at the front of the line
3) make
or m4 sendmail.mc > sendmail.cf
service sendmail restart
Q: Mail alias
A: modify /etc/aliases, run newaliases
Q: Receive mail for DomainX.example.com
A: modify sendmail mc as above, and add domain to /etc/mail/local-host-names
domainx.example.com
Debugging:
mail -v root
mailq, mailq -Ac
sendmail -q
tail -f /var/log/maillog

Configure Sendmail as a Server for Other Clients

A little more detail...
    as root, or sudo
  1. backup your /etc/mail/sendmail.mc and sendmail.cf files
  2. vi /etc/mail/sendmail.mc

  3. Search for a line with 127, and comment the line by placing "dnl #" at the beginning
    Change this line
    DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
    to this
    dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
  4. m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

  5. /sbin/service sendmail restart

  6. /sbin/chkconfig sendmail on

Debugging:
mail -v root
mailq, mailq -Ac
sendmail -q
tail -f /var/log/maillog

Links
For more details, see the Red Hat Reference Guide
https://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/ref-guide/s1-email-mta.html

And LinuxSelfHelp
http://www.linuxselfhelp.com/quick/sendmail.html

How to Run a Bash Command on All Items in a List

For Linux / Unix
Follow as instructed

For Windows
Download cygwin from http://cygwin.com
For instructions, see this article: http://systemnotesorg.blogspot.com/2007/04/use-cygwin-to-run-linux-on-windows.html

Two Easy Steps for One-Liners

e.g., you have a list of servers, and would like to do something, such as ping each one, or check their IP address. Here is a quick two-step process, with a one-line shell script that can be run from the command line.

1) Create a Text file, with one hostname per line
2) Run a for loop on the file

$ cat servers.txt
server01
server02
server03

$ for host in `cat servers.txt`;do host $host;done
server01.example.com has address 10.10.10.10
server02.example.com has address 10.10.10.11
server03.example.com has address 10.10.10.12
$

If you want different output, you can use awk, but that's another topic.

Notice a few things about this one line script.
1) Each command is separated by a semicolon ";"
2) The back ticks around a command and parameter causes the results to be returned
3) The variable host is assigned in the first part, and called just before done

Note: if you want to use ping, try "ping -c 1 $host", or it will never finish.

Use Cygwin to Run Linux on Windows

Yes, not only can you run Linux from a CD --
http://systemnotesorg.blogspot.com/2007/04/how-to-get-started-with-linux.html, but you can also install it in Windows, and run it as a Windows
program. You get a standard linux bash shell, and even X, with a little
configuration.

What Is Cygwin? (from http://cygwin.com)


  • Cygwin is a Linux-like environment for Windows. It consists of two
    parts: A DLL (cygwin1.dll) which acts as a Linux API emulation layer
    providing substantial Linux API functionality.

  • A collection of tools which provide Linux look and feel.
The Cygwin DLL currently works with all recent, commercially released

x86 32 bit and 64 bit versions of Windows, with the exception of Windows CE.

Note that the official support for Windows 95, Windows 98, and Windows Me will be discontinued with the next major version (1.7.0) of Cygwin.

What Isn't Cygwin?
  • Cygwin is not a way to run native linux apps on Windows. You have to
    rebuild your application from source if you want it to run on Windows.

  • Cygwin is not a way to magically make native Windows apps aware of
    UNIX (r) functionality, like signals, ptys, etc. Again, you need to
    build your apps from source if you want to take advantage of Cygwin
    functionality.

Where to Get Cygwin
http://cygwin.com/
http://freshmeat.net/projects/cygwin/
http://sources.redhat.com/cygwin/

How to Install Cygwin
1) Download the installer
2) Run the installer
3) Select some mirrors near you
4) Select applications to install, or just leave the default
5) Finish
6) Run cygwin (double-click on the icon)
7) Enjoy!


Support for Cygwin
RedHat -- for Cygwin licensing or commercial support http://www.redhat.com/software/cygwin/
Cygwin FAQ -- http://cygwin.com/faq/
Cygwin Users Guide -- http://sources.redhat.com/cygwin/cygwin-ug-net/

Wednesday, April 25, 2007

Which Certifications are Important?

CNE
Not as popular as it once was.

MCSE
One of the most popular has been the MCSE.

CCNA
It is always good to have some network knowledge.

RHCE
One of the most challenging exams in the industry. All hands-on lab
exam.

A+
Not very difficult, but shows some knowledge of hardware, and is a
prerequsite for HP exams

HP APS
HP Acredited Platform Specialist. Requires CNE, or MCSE and A+ as
prerequsites, but is a fairly easy exam that deals mainly with hardware.

Other Specialties
Oracle, Citrix, etc.

There is plenty of demand for MCSE's, but experience counts as well.
RHCE is another important one, as is the CCNA. Other certs are useful,
but more so in smaller companies, or as a consultant. You will need
more experience to get into a big company, but jobs tend to be more
specialized. You would either be a server admin, network admin, or dba,
whereas in a smaller company you might be all three.

Another important thing to help get interviews is a college degree. You
can use some of your certifications for college credit.
http://systemnotesorg.blogspot.com/2007/03/college-credit-for-it-certifications.html

How to Get Started with Linux

Have you always wanted to find out more about linux, but were not sure where to start? Here is a little information on where to find, and how to run and / or install a linux distribution.

What is Linux?

Linux is the kernel, or core part of an operating system that is free from any software licenses. Free to download, and install on as many machines as you like.

Here's an explanation from http://www.gnu.org/

The GNU Operating System - Free as in Freedom
What is the GNU project?

The GNU Project was launched in 1984 to develop a complete Unix-like operating system which is free software: the GNU system. Variants of the GNU operating system, which use the kernel called Linux, are now widely used; though these systems are often referred to as "Linux", they are more accurately called GNU/Linux systems.

GNU is a recursive acronym for "GNU's Not Unix"; it is pronounced guh-noo, approximately like canoe.

Trying Linux

First, you may not have known that you don't have to install linux to try it out. Just look for a live cd distro, download the .iso file, burn it to a DVD, or CD, and then boot from the DVD. When you are finished playing around, just pop the DVD out, reboot, and your old OS will come up as before. Of course the computer will run slower from DVD, but it is a good way to get a feel for which distro you like. Some of the more popular live distros are ubuntu http://www.ubuntu.com, and knoppix http://www.knoppix.org (click on the flag for English, or whatever language you prefer). Once you've had a taste, you may want to install it by itself, or as a dual-boot configuration. There are some good howtos, but some of them are outdated. These look pretty good.
http://www.howtoforge.com/windows_linux_dual_boot
http://highlandsun.com/hyc/linuxboot.html
http://www.linuxdevcenter.com/pub/a/linux/2006/05/08/dual-boot-laptop.html

Finding a Linux Distribution

If you want to work as a sysadmin, you really should learn RedHat linux -- https://www.redhat.com/, but you don't have to pay for it unless you want support. You can start by downloading Fedora Core -- http://fedoraproject.org/wiki/. Another popular business distro is SUSE which is now owned by Novell -- http://download.novell.com

Live CD List
http://www.frozentech.com/content/livecd.php

Top Ten Distributions
http://distrowatch.com/dwres.php?resource=major

Choosing a desktop Linux distro
http://www.desktoplinux.com/articles/AT3269115798.html

If you have trouble downloading, you can always buy CDs or DVDs for a very small fee.
http://www.frozentech.com

Finding More Linux Information

RedHat has some very good documentation on their website -- https://www.redhat.com/docs. For example, The Red Hat Enterprise Linux 4 - System Administration Guide is available in HTML and PDF formats: https://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/sysadmin-guide/

Another good source of information is the Linux Documentation Project -- http://en.tldp.org

If you want more interactive help try http://www.linuxquestions.org or a local Linux User Group, known as a LUG, such as KPLUG -- Kernel Panic Linux User Group http://www.kernel-panic.org You can sign up for the mailing list of most LUGs. Some have more traffic than others. This particular LUG happens to have a linux-newbie list for beginners, and they are quite friendly, and very good at answering questions.

And don't forget the ever important google search, using http://www.google.com/linux -- http://systemnotesorg.blogspot.com/2007/03/topic-specific-searches-in-google.html


Tuesday, April 24, 2007

How to Start a Blog

...and maybe make some money.
An article I posted on http://systemnotesorg.blogspot.com discusses how to get more traffic to your site.

http://systemnotesorg.blogspot.com/2007/04/search-engine-optimization.html

Now let's concentrate on how to set up a blog. With blogger, you don't have to know any html, but if you do, it helps.


Getting Started
First go to http://www.blogger.com and create a blog. If you already have a gmail account, you have completed the first step. It is really simple, and they walk you through it. Think of a name, and what you would like to write about.


O.K., so you have a blog, now what?
There is a book title that should help you keep on topic -- "No One Cares What You Had for Lunch" Then start posting. You can set up your blog to receive email, so posting is very easy. Just send an email to the address you set up under settings / email.


Making money
Well, keep posting something useful, but If you want to make money, don't waste any time. Get an adsense account, and start placing some ads on your site.



http://www.google.com/adsense/

Go to the AdSense Setup tab, and select the ads you would like to display. Then just copy and paste the code into your site (use the Template tab in blogger).


For more tips, see some articles on problogger.net -- http://www.problogger.net/how-to-make-money-blogging/
--http://www.problogger.net/archives/2005/12/06/how-bloggers-make-money-from-blogs/, or do a google search on "monetize blog." Here is another link: http://www.stevepavlina.com/blog/2006/05/how-to-make-money-from-your-blog/


Checking Traffic
It is also a good idea to check on your traffic. That can be done easiy by getting a google analytics account. Just copy and paste the code into your site.
http://www.google.com/analytics


For more information about blogs, check out this page.

http://systemnotes.org/blog/

Tuesday, April 17, 2007

Search Engine Optimization

Sure this blog is more about systems and programming than it is about marketing, but if you're building a website or blog, you probably have at least some interest in SEO (Search Engine Optimization). Basically, that means having other quality sites link back to your site, which is what makes it appear higher in search engines such as google

Here are some things to check out:
Try a google search on seo, if you want to learn more.

And don't forget about the excellent webmaster tools at google. http://www.google.com/support/webmasters
and specifically, How can I improve my site's ranking? -- http://www.google.com/support/webmasters/bin/answer.py?answer=34432&hl=en

Thursday, April 12, 2007

Using bash and sed to Modify a Text File

This shell script demonstrates how to write to a text file, and then modify the contents.
#!/bin/sh
# modfile.sh
# by ScottM, 04/12/2007
# demonstrates writing text to a file, and then using sed to modify it.

TESTFILE=test.txt
FRUIT=banana

# add some content to the file (note: file will be overwritten)
echo "apple" > $TESTFILE

# modify the content
sed -e "s/apple/& $FRUIT/g" -i $TESTFILE

# sed uses the "s" option, which uses regular expressions to search and replace text
# "s/apple/" means search for any lines that contain the characters "apple"
# "& " means use the results of whatever was found
# "/& $FRUIT/g"  -- replace "apple" with "apple banana",
# the g is for global, or all lines containing the pattern

# output:
# $ cat test.txt
# apple banana
# $
Sed One Liner

This is really only a one line script, commonly referred to as a on-liner, so we don't really need a bash script, as long as we understand the regular expressions we are trying to use.

From the command line, we can insert a word:

$ sed -e 's/apple/& pear/g' test.txt
apple pear banana

Notice how the ampersand "&" character prints the text that was found.  Note that we left out the -i, so we can test the output before modifying the original.
Look at the difference here.  The word "pear" is either inserted or appended:

$ sed -e 's/\(apple\)/& pear/g' test.txt
apple pear banana

$ sed -e 's/\(apple.*\)/& pear/g' test.txt
apple banana pear

The parenthesis contain the search parameter that is printed by ampersand, but when we include ".*", we get apple followed by all characters up to the end of the line, and then we add a space and out new text:  " pear".

If we want to replace the entire line with the search string, plus some added text we could use the "^" to indicate start of line and $ to indicate end of line. In this case it would use whatever matches the search pattern, and ignore whatever else is on the line.

sed -e 's/^\(apple\).*$/\1 pear/g' test.txt
apple pear

So what happened to banana? We did a search for apple, and surrounded it with parenthesis. Then we asked to print \1 which is the first set of parenthesis (in this case the only set). That effectively erased everything else on the line except whatever matches apple.

Notice how you can print multiple search groups:

$ sed -e 's/^\(apple\)\(.*\)$/\1 pear \1\2/g' test.txt
apple pear apple banana

Exercises
Exercise to try: -- Where this might be useful is when replacing a URL in an html file. Search for href="something", and replace it with href="something-else"

Exercise 2 Try adding other words that match apple (e.g. apples, apple-pie,), and see what happens.

For more Regular Expression examples see our regex articles.

Wednesday, April 11, 2007

HowTo Install Multi Gnome Terminal using Yum

Multi Gnome Terminal Install

Note: This procedure is for non-standard, unsupported software. The dag repository is outside of Redhat's control, but has some very useful software.

Since multi-gnome-terminal has several dependencies, it is easier to install using yum.


First, Install Yum


* Install yum from your distribution
$ rpm -Uvh
/RPMS/rhel-3-i386-as/yum-2.2.0-1.noarch.rpm
* Modify /etc/yum.conf
Standard yum.conf for rhel-3-U6 (change as required):

[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=0

[rhel-3-U6-i386-as]
name=Red Hat Enterprise Linux 3 Update 6 i386 AS
baseurl=http://yum.mydomain.com/rhel-3-U6-i386-as/

* Then, add the dag repository to /etc/yum.conf

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el3/en/i386/dag


Now, Install and Configure multi-gnome-terminal


1. Install multi-gnome-terminal
1. yum install multi-gnome-terminal
2. Add launcher to task bar
1. Name: multi-gnome-terminal
2. Command: /usr/bin/multi-gnome-terminal
3. Icon:
/usr/share/pixmaps/multi-gnome-terminal.png
3. Launch multi-gnome-terminal
1. multi-gnome-terminal &
2. or click on launcher icon
4. Configure Console Colors
1. On the "Settings" menu, select "Tab Preferences"
2. Select the "Colors" tab
3. On the Forground/background color drop-down, select "black on white"
4. Select the "Image" tab
5. Check "Shaded Background", and make it less than -50%, so it is almost white
6. Select a background pixmap, if desired
5. Configure keybindings
1. On the "Settings" menu, select "Keybindings"
2. Under the Action Dropdown box, select
1. "Shell->New Tab"
2. Press the keys, "Ctrl-Shift-t"
3. Click on the add button
4. Click on the clear button under the Keybinding label
5. "Shell->HSplit"
6. Press the keys, "Ctrl-Shift-h"
7. Click on the add button
8. Click on the clear button under the Keybinding label
9. "Go Right"
10. Press the keys, "Ctrl-Page Down"
11. Click on the add button
12. Click on the clear button under the Keybinding label
13. "Go Left"
14. Press the keys, "Ctrl-Page Up"
15. Click on the add button
16. Click on the clear button under the Keybinding label
17. "All bonded"
18. Press the keys, "Ctrl-Alt-b"
19. Click on the add button
20. Click on the clear button under the Keybinding label
21. "All unbonded"
22. Press the keys, "Ctrl-Alt-u"
23. Click on the add button
24. Click on the clear button under the Keybinding label
3. Click on the OK button


Why so much configuration?


It is really optional, but the steps listed make the program function like a normal gnome-termial window, so the appearance and keystrokes will be similar. Of course, you are welcome to configure it however you want.

Monday, April 2, 2007

Using nmap to Generate Host Lists

An easy way to get a list of hosts from a single domain that you are a part of, is to query DNS

host -l mydomain.com

But that is not always practical. Sometimes you have machines that are in different domains, but they all are part of a network you manage. Rather than trying write a script that pings hosts and reports the output, just use nmap for a very fast scan.

To scan all hosts in a list of subnets

1) Create a subnets.dat file with one subnet on each line:

$ cat subnets.dat
192.168.0.*
192.168.1.*

2) Run nmap with the subnets.dat file as input

$ nmap -sP -R -iL subnets.dat
Reading target specifications from FILE: subnets.dat

Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
Host (192.168.0.0) appears to be down.
Host box1.mydomain.com (192.168.0.1) appears to be up.
Host box2.mydomain.com (192.168.0.2) appears to be down.
Host box3.mydomain.com (192.168.0.3) appears to be up.
Host (192.168.0.4) appears to be up.
...

Notice how names are resolved for existing hosts, but only an IP is returned, if there is no DNS record (e.g. 192.168.0.0).

3) Write a script to report on the output you want
e.g. for a list of all hosts that respond to ping

$ cat nmap_servers.sh
#!/bin/sh
OUTFILE=hosts_scanned.dat

# clean up old file
[ -f hosts_scanned.dat ] && rm hosts_scanned.dat
echo "nmap -sP -R -iL subnets.dat | grep "to be up" | awk '{print \$2}' "
echo ""

# write all hosts to file, but print only hosts that appear to be up.
nmap -sP -R -iL subnets.dat -oN $OUTFILE | grep "to be up" | awk '{print $2}'

Of course this output can always be redirected to a file, if desired. The output file "hosts_scanned.dat" will contain any host nmap found in DNS, and whether it was up or down.

----------
Sample output after grep and awk:
box1.mydomain.com
box3.mydomain.com
(192.168.0.4)

Notice that I use awk to print the second field. That's because some entries might have an IP address, but not a DNS entry. So the second field is whatever comes after Host, which is either an IP address, or a hostname. In this case, I want to find any IP's without hostnames, so I can fix DNS, but you may want to just keep the ip in the list,so you can ssh to it later.

To get rid of the parenthesis, I redirected the output to hosts_up.dat, and piped the output to grep and awk to illustrate:

cat hosts_up.dat | grep \( | awk -F[\(\)] '{print $2}

More detail on these commands will be posted on http://www.systemnotes.org/linux