Monday, April 30, 2007

Define Two IPs on a Network Interface Card (NIC)

A friend and I were talking about creating a virtual network connection. In this case, we were thinking about defining two IPs on one physical Network Interface Card (NIC). I will use the FastEthernet interface, hme, as an example.

#vi /etc/hostname.hme0

For the virtual
#vi /etc/hostname.hme0:1

To activate virtual connection without rebooting
#ifconfig hme0:1 plumb
#ifconfig hme0:1 inet netmask broadcast
#ifconfig hme0:1 up
#ifconfig -a

Ensure that you populate the name service (files, nis, nis+, etc) with the virtual's IP address.

Friday, April 27, 2007

Create Virtual Screen Covering Two Monitors

A few days ago, a customer asked me how to make two monitors act as one. To make this happen, Solaris has an option called xinerama, which allows the mouse and windows to traverse both monitors. The framebuffers must be the same type. Here's the syntax.

#vi /etc/dt/config/Xservers
:0 Local local_uid@concole root /usr/openwin/bin/Xsun :0 +xinerama -dev /dev/fbs/jfb0a -dev /dev/fbs/jfb0b -nobanner

Thursday, April 26, 2007

Copy Contents of One Tape to Another

The dd command can also be used to copy the contents of one tape to another. Here's an example of the syntax. Obviously you will need two tape drives to accomplish this task.

#dd if=/dev/rmt/0 of=/dev/rmt/1

Create a Clone Disk Drive

You can use the dd (data dump) command to create a backup disk drive. It will create a mirror image, which includes the partition table, of your boot disk by copying it bit by bit. In the example below, I'm using slice 2 because it represents the entire disk. Here's the syntax.

Disk to Disk (Ensure the disks are the same size)
#dd if=/dev/rdsk/c0t10d0s2 of=/dev/rdsk/c0t11d0s2 (default blocksize 512)

Blocksize is configurable (For RAIDs, we use larger blocksizes, e.g. 4k)
#dd if=/dev/rdsk/c0t10d0s2 of=/dev/rdsk/c0t11d0s2 bs=128

Disk to Tape
#dd if=/dev/rdsk/c0t10d0s2 of=/dev/rdsk/c0t11d0s2

Blocksize is configurable
#dd if=/dev/rdsk/c0t10d0s2 of=/dev/rmt/0 bs=128

Tuesday, April 24, 2007

Change Filename Extensions with Inline Script

I want to quickly change the filename extensions for a directory with hundreds of *.dta files. The extension will be changed from *.dta to *.dat. I will use a simple inline script to accomplish the task. Also, I want to set the file to read all. Here's an example.

Change filename extension
# cd /directory_with_datafiles
# csh
# foreach filename ( *.dta )
?set base=`basename $filename .dta`
?mv $filename $base.dat
# chmod 444 *.dat

Here's an actual run
# csh
# touch
# foreach filename (*.data)
? set base=`basename $filename .data`
? mv $filename $base.dat
? end
# ls
t1.dat t2.dat t3.dat t4.dat t5.dat

Friday, April 20, 2007

Determine Why a Process is Hanging with truss

The truss utility may help you determine why a particular process is hanging. The truss command executes the specified UNIX command, and then truss provides a data profile (trace) of the specified command's execution. It's a very useful troubleshooting tool. Here's an example below.

#truss -d unix_command

Wednesday, April 18, 2007

Repeat the Previous UNIX Argument

Here's a handy shortcut. Instead of having to retype the argument of a previous command, I use this syntax. Below is an example of copying a SQL script directory to a backup directory on the RAID.

#ls -l /home/esofthub/scripts/user_sqlscript_dir
#cp -pr !$ /raid/mybackup/.

Saturday, April 14, 2007

Repeat the Previous UNIX Command

Here's a handy command to know, especially when the command line syntax is long. I've included an example for both c and ksh shell.

For C shell
#vi this_is_a_very_long_filename
:wq! (saves and quits vi)

Repeats the command

For ksh shell
#vi this_is_a_very_long_filename
:wq! (saves and quits vi)

Repeats the command (r is a built-in alias fc -e -)

Friday, April 13, 2007

Install a Solaris Boot Block

Here is a convenient procedure to know for Solaris 8 and below. Usually after a / partition recovery, I use it to install a server's or workstation's boot block. For most people, the second argument is a little difficult to remember. Here is an example.

ok boot cdrom -s
# /usr/sbin/installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/c1t1d0s0

Wednesday, April 11, 2007

Change Access and Modification Times on a File

If you ever needed to arbitrarily change the access and modification times on a file, here's how to do it. I can see this being useful when you are performing a find event. You can also use a reference file to set the times on a target file or directory.

Here's the time set to Apr 10, 2007 18:16 (6:16pm)
#touch -t 200704101816 filename

#settime -f reference_file target_filename

Tuesday, April 10, 2007

Conduct Interactive Communications Between Workstations

The talk utility is a no frills way of conducting interactive communications over the network. Prior to Zircon Chat/IRCD, I was a big user of the talk utility. Be forewarned, talk is a barebones built-in CLI chat tool. You may have to make some adjusts to your workstation's /etc/inet/inetd.conf file to make it work within your LAN.

#talk user@esofthub1_wkstn

Monday, April 09, 2007

Unlock Screenlock With a Group Account Named xlock

As UNIX system administrators, we constantly have to kill abandoned screen-locked sessions. Obviously, this can be a frustrating task when you're dealing with a headless server and/or all your workstations are being used at the same time. Here is a suggested workaround.

Create an xlock group in whatever name service (files, nis or nisplus) you are using, and then add your login to the group. You should be able to unlock user's screenlocks with your password.

This post is referring to the “lock” on the desktop panel.

Note: Your IT or security department may prohibit or restrict the use of an xlock group.

Sunday, April 08, 2007

Determine the Manual Page for a Given Command

Today I was searching for options associated with the UCB/SunOS's version of ps. I wanted the man page for /usr/ucb/ps, not /usr/bin/ps. Here's how I discerned between the two ps man pages.

#whatis ps
returns (1) /usr/bin/ps
(1b) /usr/ucb/ps

This is equivalent to the whatis command
#man -f command

Here's the man page for /usr/ucb/ps
#man -s1b ps

By the way, I was looking for /usr/ucb/ps -aux

Thursday, April 05, 2007

NEdit is a Multi-purpose Text Editor

For those of you who prefer an alternate to vi, NEdit is a multi-purpose text editor for the X Window System, which combines a standard, easy to use, graphical user interface with the thorough functionality and stability required by users who edit text eight hours a day.

It's a multi-platform application, too. NEdit was originally developed on a Unix system and is available on all major Unix and Linux systems, but it also runs on MacOS X, OS/2 and MS Windows.

Personally, I find it to be a very powerful tool, especially when it comes to manipulating columns.

Wednesday, April 04, 2007

Determine Processes Accessing a File System

I was trying to unmount the /opt filesystem today, but I was prompted with a "device busy" message. Frankly speaking, I thought the file system was already in an inactive state, so I was curious as to what processes were hanging it. These processes were identified and subsequently killed.

# cd /
# umount /opt (device busy)

After realizing that processes were still accessing the /opt filesystem, here's what was done to umount it.

Determine which processes were accessing /opt
# cd /
# fuser -cu /opt
# kill -9 PID1 PID2
umount /opt

Alternately, this could have been done, too.

# cd /
# fuser -ck /opt
# umount /opt

or simply force it

# cd /
# umount -f /opt

Tuesday, April 03, 2007

List User Login Information with listusers or logins

Here's a handy command to list user login information in a columnar format. The command is named listusers. How appropriate. This formatted information can easily be used for scripting purposes.


#listusers -l login

#listusers -g xlock

The other command that list user and system login information is named logins


Monday, April 02, 2007

Skip the Power On Self Test (POST)

Hold down the Stop key (top left of keyboard) while powering up the workstation. This should skip the POST process.

Reset NVRAM Parameters with set-defaults

To reset all the NVRAM parameters to their default values, you should use the set-defaults command. This command only affects parameters with assigned default values. Here's an example.

ok set-defaults

If you only want to reset one particular parameter, note the example below.

Note the absence of an "s"
ok set-default boot-device

Sunday, April 01, 2007

Interesting UNIX Commands

Here are some interesting UNIX commands. I use them all the time. ;)

ok slooflirpa

Here are some more interesting commands

ok slooflirpa

Remove Device Alias with nvunalias

This OpenBoot command is fairly self-explanatory. It removes the alias name from NVRAMRC. Here's an example of its use.

ok nvunalias backup

Create a Device Alias with nvedit

If you use nvedit, it's easier to make changes to a device alias or a device path. Having to retype a device path can be quite aggravating to do.

Make sure that use-nvramrc variable is set to true. nvedit edits the NVRAMRC.

Here's the setup
ok printenv (get the variable name and its syntax)
ok setenv use-nvramrc? true
ok nvedit
devalias disk0 /pci@9,600000/SUNW,qlc@2/fp@0,0
control ^c (to exit nvedit)
ok nvstore
ok reset
ok boot disk0

Create a Device Alias with nvalias

Creating device aliases is a routine task for sysads. Here's an example for creating an alias for a SunFire v490's backup disk. Obviously, the alias can be named anything, but I commonly see backup, mybackup, disk0, disk1, disk2, and soforth.

ok nvalias backup /pci@9,600000/SUNW,qlc@2/fp@1,0

By the way, aliases are stored in the NVRAMRC, which is part of the NVRAM.

To boot off the backup
ok boot backup

Display NVRAM Parameters

I often use the printenv command to list all of NVRAM's parameters. This command will display the variable names, values, and default values. Here's an example of its use.

If you have security enabled, you will be prompted for a password
ok printenv
Variable Name Value Default Value
boot-device disk disk net

Here's an example of changing the boot device.
ok setenv boot-device disk1

Show the change
ok printenv
Variable Name Value Default Value
boot-device disk1 disk net