Friday, December 29, 2006

Quick and Dirty Setup of the Internet

I had several Sun workstations that needed Internet access. But first I need to point to a nameserver and then properly configure the name service.

Here's what I did.

Modified the /etc/resolv.conf file. I put these entries into it.

#vi /etc/resolv.conf
nameserver 168.126.63.1
nameserver 168.126.63.2
:wq! (saves and quits vi)

Modified the /etc/nsswitch.conf file. I added the dns entry into it.

#vi /etc/nsswitch.conf
hosts: nis files dns [NOTFOUND=return]
:wq! (saves and quits vi)

Sunday, December 24, 2006

How to Check email via Command Line

Check your mail with mailx

Here's how to do that.

--If you type "?", you will get a list of help messages. For example, if you want to save all messages to a file, type the following:

#mailx
(Type "?" for help)
s * saveallmail (hit enter)
quit (hit enter to exit mail)

Troubleshooting with mailx -v (Sendmail and Mail)

On a number of occasions, I have used mailx -v to trouble shoot problems with Mail and Sendmail. Here's what I do.

#mailx -v supportATtopbloglists.com (hit enter)
Subject: Top Blog Lists (hit enter)
Top Blog Lists has hit 100 members in less than 3 weeks. Join other successful bloggers at http://www.topbloglists.com (hit enter)
. (hit enter)
EOT

--Watch the output scroll--

mailx coupled with -v are very useful because they provide the verbose output of Sendmail. It shows the connection, session and disconnect. It's very useful for troubleshooting purposes (e.g. viewing IPs, DNS, mail configurations, version numbers, etc).

Attach a File to Message via Command Line

I'm frequently asked how to attach a file(s) to an email message via the command line. Here's how I do it. By the way, the mail recipient will need to use uudecode.

Here's an example of an email attachment.

# uuencode my_binaryfile1 | mailx -s "Email binary as attachment" esofthub@esofthub.com

For multiple attachments, I use a mail client such as dtmail, Netscape or FireFox. But I've seen this done too.

# uuencode my_binaryfile1 my_binaryfile2 | mailx -s "Email binary as attachment" esofthub@esofthub.com

For NON-binary type files

Please note the ~r (tilde command followed by r)
# mailx esofthub@esofthub.com (hit enter)
Subject: End of Week Status Report (hit enter)
~rendofweekstatus.dat (hit enter)
~. (hit enter)
EOT

The above procedure (non-binary) works great for inline text files.

Also,

# cat endofweekstatus.dat | mailx -s "End of Week Status Report" esofthub@esofthub.com

Set up a Cron Job and Email the Results

Last week I setup a cron job to email a weekly status report to a group of logins. The group of logins was defined by an alias in the /etc/mail/aliases file. The crontab was modified to accomplish this task. Here's what I did.

# crontab -e (crontab editor)
45 06 * * 05 sort /home/esofthub/endofweeklystatus.dat | mailx -s "End of Week Status Report" aliasedgroup
:wq! (save results)

The minute is 45
The hour is 06
The day of the month is any (*)
The month of the year is any (*)
The day of the week (05) is Friday

Wednesday, December 13, 2006

Convert a ISO Standard to DOS and vice versa

Occasionally, there is a need to convert a UNIX formatted file (or files) to a DOS format and vice versa. As a unix system administrator, I’ve performed this task many times. In the examples below, I’ll demonstrate the task singly and then multiple using an inline loop.

Convert an ISO Standard formatted file to DOS standard formatted file

# csh
# unix2dos filenameUNIX > filenameDOS
# foreach i (*)
? unix2dos $i > $i.$$
? mv $i.$$ $i
?end

Convert a DOS formatted file to ISO standard formatted file

# dos2unix filenameDOS > filenameUNIX
# foreach i (*)
? dos2unix $i > $i.$$
? mv $i.$$ $i
?end

Saturday, December 09, 2006

How to Capture xterm/cmdtool Output

When you are performing an upgrade/installation via command line, you might want to capture the steps/procedures in real-time. There is a convenient way of doing this task.

#script -a /tmp/outputfilename (whatever is typed after this command execution is captured)

When you are done, enter control d to terminate the capture process.

How to Change the Values of the PROM (EEPROM)

For security purposes, you might want to password protect your Open Boot Prom (OBP). This will prevent unauthorized changes of your prom settings.

#eeprom (gives you a default listing)
e.g.
#eeprom security=command
enter new prom password (it prompts you for a new password)

To remove the OBP password
#eeprom security=noneopen

Sunday, December 03, 2006

Append an Entry to a File

There are many situations in which you may want to append an entry to a file. Here are two ways of doing it.

#echo "138.123.34.12 myhost" >> /etc/hosts
#cat >> /etc/hosts
"138.123.34.12 myhost" (hit enter)
then execute a control d

Display Only Unique Lines From a File

There are many situations in which you may only want to display unique lines. Here is an easy way of doing it.

#uniq filename

e.g. #uniq filename > outputfile (All of the duplicate lines are filtered out. outputfile only has unique lines in it.)