Posts

Showing posts from December, 2007

Mail a Text File from the Shell

Image
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 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. ...

Vim Tips -- Search and Replace

Image
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...

Ping Multiple Hosts Using Bash Nmap and Fping

Image
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 ...