Wednesday, February 28, 2007

Check the Status of a File or Directory on Tape

Here's another useful task that you can do with the tar command. Check the status of a file on tape.

Archive files and directories into a tarball.
#tar cvfp esofthub.tar cgi-bin ircd zircon popper

Archive file (tarball) onto tape
#tar cvfp /dev/rmt/0 esofthub.tar

Check for status of file (esofthub.tar)
(Default)
#tar tvf /dev/rmt/0

For the second tape device with a tape in it
#tar tvf /dev/rmt/1

How to Rewind and Eject a Tape

This is a fairly common task. However, I'm often asked how to rewind and then eject a 4mm tape. It's easy--Of course, it's always easy once you know.

To rewind a tape (default)
#mt /dev/rmt/0 rewind

To rewind and eject a tape
#mt /dev/rmt/0 offline

For the second tape drive
#mt -f /dev/rmt/1 rewind
#mt -f /dev/rmt/1 offline

Tuesday, February 27, 2007

Check the Local Tape Device

Checking the status of a tape device is a fairly simple procedure. Here's an example.

Default status (don't need the "-f" option)
#mt /dev/rmt/0 stat

For second tape device
#mt -f /dev/rmt/1 stat

For third tape device
#mt -f /dev/rmt/2 stat

Monday, February 26, 2007

Recover a File with vi After System Crash

A few years ago, I was creating a maintenance script file for a database and experienced a system crash. As I recollect, the file had several hundred lines that were unsaved/modified, and the last thing I wanted to do was recover from an older copy. What did I do? Fortunately, I was able to use the "-r" option to recover the file.

# vi -r filename

Display the Status of Print Jobs Or Cancel a Job

Often we are asked to check the status of a print job. We use the ubiquitous lpstat command to ascertain this information. Here are some examples.

Gives the status of all print jobs started with the lp command
#lpstat
myprinter_1-250 esofthub 9876 Feb 24 10:16
myprinter_1-251 esofthub 6754 Feb 24 10:45
myprinter_1-252 esofthub 5646 Feb 24 10:56

Cancel a print job started with lp
#cancel myprinter_1-250

Determine Computer Uptimes for Remote and Local

Here are a couple of handy commands that can be used to determine the uptimes of local and remote computers. The ruptime command shows the status of computers attached to a network. If used with the "-a" option, the ruptime shows the number of users currently logged on. The uptime command shows the local information of the aforementioned.

Run this command provided that security hasn't disabled it
#ruptime -a

For local uptime
#uptime

Here's an example of the output.
12:19pm up 65 day(s), 42 mins, 13 users, load average: 0.39, 0.56, 0.10

Sunday, February 25, 2007

Unix System Administration Task: Delete Log Files

We routinely delete old log files. Why? Some of them are very large and take up valuable space on the hard drive. These old logs were generated by workstations/servers, web servers, databases, and many other ubiquitous applications.

Note: When I stated old log files, I meant terminated files--not ones with open file handles.

# cd /where_your_logs_are
# find . -name '*.deadlog' -exec rm {} \;

Create a Command Alias in .cshrc

I like to create shortcuts. One of my favorite commands is using ls accompanied with the -ltr options. These options display a long list, time sorted, and in reverse order. It’s a good idea to alias the rm for interactive mode, too.

# csh
# vi $HOME/.cshrc
...
alias ls 'ls -ltr'
alias lp 'lp -d not_primary_printer'
alias rm 'rm -i'
...
:wq! (saves and quits vi)

# ls
-rwxrw--r-- 1 esofthub mygroup 2345 Feb 21 01:34 esofthub
-rw-rw--r-- 1 esofthub mygroup 8078 Feb 21 01:35 esofthub1
# lp esofthub1

Note: You can unalias the command, too.
# unalias ls
# unalias rm

Add Third Monitor and Restart dtlogin (XVR-1000/XVR-1200)

Per the customer's request, we added a third monitor. To accommodate the third frame buffer (XVR-1000) request, it involved modifying the /etc/dt/config/Xservers configuration file and then restarting dtlogin.

If the /etc/dt directory does not exist, you may want to copy it to /etc.
#cp -pr /usr/dt /etc
#vi /etc/dt/config/Xservers
:0 local /usr/openwin/bin/X -dev /dev/fbs/jfb0a defclass TrueColor defdepth 24 -dev /dev/fbs/jfb0b defclass Truecolor defdepth 24 -dev /dev/fbs/gfb0 defclass TrueColor defdepth 24 right
:wq! (saves and quits vi)

Here's the restart. By the way, I executed these commands from a remote machine.

#cd /etc/init.d
#./dtlogin start

OR

#cd /etc/rc2.d
#./S99dtlogin start

The S99 script is linked to dtlogin.

OR

#reboot

Saturday, February 24, 2007

Create Large Files to Test Throughput Rates

There may be occasions when you want to test the throughput rates for a large file. In our case, we wanted to use files of certain sizes to accomplish these tests. I suggested using the mkfile command to create the predetermined file sizes.

Here's what was done.

Create a 1MB file
# mkfile 1m 1MB

Create a 5MB file
# mkfile 5m 5MB

Create 10MB file
# mkfile 10m 10MB

Create 100MB file
# mkfile 100m 100MB

Create 1GB file
# mkfile 1000m 1GB

Extra: Use Z Shell brace expansion to create multiple test files

Create Named Pipes for Interprocess Communications

Yesterday, we were having problems with one of applications not displaying images. After further examination (reading the console output), it was determined that a named pipe file was missing. A named pipe allows two unrelated processes to communicate with each other. Here's what was done to recreate this special FIFO file.

This action creates a named pipe called mypipe.
# mknod mypipe p

In our case, the named pipe needed to be read and writable by everyone
# chmod 666 mypipe

An alternate way of creating the named pipe - suggested by ux-admin:
# mkfifo mypipe
# chmod 666 mypipe

Thursday, February 22, 2007

Change the Hostname of a Workstation

Last week, I was asked how to change the hostname of a workstation. There were a few modifications to some of the files in the /etc directory. In this example, I used the common vi editor or nedit to make the changes.

Here are the events that took place. I assumed the old workstation's hostname was esofthub

# vi /etc/nodename
# vi /etc/hostname.hme0
# vi /etc/inet/hosts
# vi /etc/inet/ipnodes
# mv /var/crash/esofthub /var/crash/newesofthub
# init 6

Remove NIS+ From a Workstation

I've had to remove NIS+ from workstations on several occasions. Most of the time, the system is recovered to files. It is a fairly simple process.

Workstation or Server
# cp -p /etc/nsswitch.files /etc/nsswitch.conf
# /etc/init.d/rpc stop
# /etc/init.d/nscd stop
# rm -f /etc/.rootkey
# cd /var/nis
# rm -rf .*; rm -rf *
# /etc/init.d/rpc start OR perform a reboot

Alternate for workstation only:
# setenv PATH ${PATH}:/usr/lib/nis
# nisclient -r

Alternately, here is a link to Setup NIS+ server and populate its tables

Determine What a File Contains

It's not uncommon to view the contents of a file with the vi editor or the cat/more commands. However, I would suggest you determine its file type first. This can be done with the file command. It will examine the file and report its file type.

Binary files can be quite annoying if opened with the incorrect application.

#file filename

Add Security Banners for Login Screen, Telnet, and FTP

Some organizations require their workstations to have security banners on their login screens and ftp/telnet login sessions. You'll have to ask your security personnel for their consent and monitoring verbiage.

Here's the example for the login screen.
#vi /etc/issue
YOUR NOTICE AND CONSENT BANNER GOES HERE
...
...
...
:wq! (saves and quits)

Here's the example for ftp
#vi /etc/default/ftpd
BANNER="YOUR NOTICE AND CONSENT BANNER GOES HERE"
:wq!

Here's the example for telnet
#vi /etc/default/telnetd
BANNER="YOUR NOTICE AND CONSENT BANNER GOES HERE"
:wq!

Wednesday, February 21, 2007

Display Non-printable Characters in Binary Files

You can use the octal dump, od, utility to display non-printable characters. Amongst other things, we have used it to detect the header bytes in a stream of binary packets.

Here's are some examples.

Displays in character format
# od -c a.out

Capture a serial stream and display in character format
# tip -9600 /dev/term/a | od -c

Capture a serial stream and display in hexadecimal format
# tip -9600 /dev/term/a | od -x

Related post

Display Printable Characters in a Binary File

We often use the strings command to display the printable characters in our binary output files. The strings utility will display strings that are at least 4 characters long and terminated by a newline or a NUL character. Here's an example of its use.

#strings output_binary_file | more

Tuesday, February 20, 2007

Display Diagnostic Information to Sceen

One of the more useful diagnostic utilities is dmesg. We use it frequently to troubleshoot our servers and workstations. It displays recently printed diagnostic messages to STDOUT.

#dmesg

Get Firmware, H/W Platform, RAM, Ethernet Address and Host ID

You can obtain the PROM revision level, hardware platform, RAM installed, serial number, Ethernet address, logo, and the host id by using the following command in the Open Boot Prom (OBP) mode: banner. The firmware information can be very useful, especially if you are upgrading processors. I used it to determine if a firmware update was required for new processors--That was the case.

Here's an example.

OBP mode
ok banner

Note: If you looking for the UNIX banner command, which outputs string information, here’s its post: Using UNIX banner to print to STDOUT

Display the PROM Versions for All Boards

For our Sun Enterprise 4X00 servers, we can use the .version command to display the PROM versions for all of our boards. Here's an example.

OBP mode
ok .version

Display the NVRAM Configuration

We frequently use the printenv command to display the NVRAM's variables, its user defined values and its default values. Here's an example of changing the boot device.

Open Boot Prom (OBP) mode
ok printenv
(You might have a PROM password set. If so, you will have to enter it.)
setenv boot-device disk1

By the way, the eeprom command can do the same (set boot device) thing in the init 3 level.

Monday, February 19, 2007

Make a Filesystem Read Only

For security reasons, you may want to make a filesystem read only. You will have to modify the /etc/vfstab file. The "ro" option is inserted into it. Here is an example using the /usr filesystem.

# vi /etc/vfstab
#
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot options
#
...(other entries go here)
/dev/dsk/c0t0d0s6 /dev/rdsk/c0t0d0s6 /usr ufs 1 no logging,ro
...(other entries go here)
:wq! (saves and quits vi)

To write to the filesystem
remove the "ro" option from the /etc/vfstab and reboot

OR to make it temporary ("ro" restored after reboot)
# mount -F ufs -o rw,remount /usr

Delete or Filter Lines in a File

SysAds are frequently filtering lines in a file. The stream editor command, sed, is a great tool for accomplishing this task. In our /etc/host file, it has blank lines and most of its entries have comments. We want to omit them from view. Here's a way of filtering them.

Display the filtered output to the screen
# sed -e '/^#/d' -e '/^$/d' /etc/hosts | more

Write the filtered output to a file
# sed -e '/^#/d' -e '/^$/d' /etc/hosts > /tmp/hosts.filtered

Just blank lines
# sed -e '/^$/d' /etc/hosts > /tmp/hosts.filtered

Find Day of the Month for Years Past and Forward

What day were you born or what day were you married? The cal command allows quick access to this information. Here's an example of its use.

#cal 10 1982

Sunday, February 18, 2007

Using the Banner Command to Print to STDOUT

This is the 100th post. Here's something for standard output.

One word per line
# banner Thank you for visiting and contributing to My SysAd Blog

On one line
# banner "My SysAd Blog"

If you trying to use the banner command to output something to the printer, then you can use this syntax.
# banner This message is outputting to the printer - My SysAd Blog – UNIX | lp

Note:
If you are trying to use the Open Boot Prom's banner command, that's a different command altogether and here's the post: Get hardware, Platform, RAM and Ethernet Information

Delete a Filename with an Invalid Character

Once in awhile, you will have to delete a file name that was created with an invalid character. Frankly speaking, this can be a little tricky to deal with.

Here is an example. This is a filename with an invalid character, "-", in front of it.

# cd /tmp
# ls
-esofthub
# rm /-esofthub
or
# rm -- -esofthub

or by inode
# ls -i
# find . -inum 968746 -exec rm -i {} \;

Rebuild the /etc/path_to_inst File

Yesterday we had to recover the /etc/path_to_inst file. Unfortunately, the /etc/path_to_inst.old was a problematic, too, and the 4mm tape was not cooperating. We took the system down to init 0 level an then booted the system using the interactive mode. The file was successfully rebuilt.

#init 0
ok boot -rav

Just answer the questions during the bootup sequence.

Boot to Single User Mode

Here are a few ways to boot a workstation to single user mode. This mode is primarily used to perform maintenance or troubleshooting activities. Occasionally, you may encounter an emergency and will have to use a CDROM to boot to single user mode.

From Open Boot Prom (OBP)
You will be prompt for a password if security-mode is set to command
ok boot -s
ok boot cdrom -s

From the init 3 level
This will automatically execute a boot -s at the OBP level
#reboot -- -s

Thursday, February 15, 2007

XVR-1200 Card with a Second Monitor Setup

After installing the XVR-1200 driver, you will probably need to modify the Xservers file in order to support a two monitor configuration. Here's an example of the modification.

If the /etc/dt directory does not exist, you may want to copy it to /etc.
#cp -pr /usr/dt /etc
#vi /etc/dt/config/Xservers
:0 local /usr/openwin/bin/X -dev /dev/fbs/jfb0a defclass TrueColor defdepth 24 -dev /dev/fbs/jfb0b defclass Truecolor defdepth 24 right
:wq! (saves and quits vi)

Mount the Backup Disk to Recover a File or Directory

Here's an example of mounting and umounting a slice on the backup hard drive. In this example, a configuration file and a home directory will be recovered. I'm copying both items to /tmp on the active disk to review.

Assume active disk is /dev/dsk/c0t0d0s0
#cd /
#mount /dev/dsk/c0t1d0s0 /mnt
#cp -p /mnt/etc/someconfig.cfg /tmp
#mkdir /a
#mount /dev/dsk/c0t1d0s6 /a
#cp -pr /a/USERS/esofthub /tmp
#umount /mnt
#umount /a
#rmdir /a
#cd /tmp

Copy Time of Day to IO Board(s)

On our Sun Enterprise 4X00 server, we finally got tired of seeing the following message: "Clock board TOD does not match TOD on any board." When you see this message, it means the information on the clock board and IO boards is not syncronized.

Here's what we did at the Open Boot Prom level.

ok copy-clock-tod-to-io-boards
ok boot

Wednesday, February 14, 2007

Display Line Numbers for a File to STDOUT

The UNIX nl utility displays the line numbers for a file to standard output. It can useful during a debugging session. If you use the nl command without options, it does not show line numbers for the blank lines.

Without options
# nl sysad.txt
1 This blog's
2 content
3 is primarily
4 a HOWTO for UNIX
5 system administration.
6 Its articles consist of Solaris,
7 Sybase, Oracle, and miscellaneous
8 tips and operating system information.

9 This blog's content
10 is primarily
11 a HOWTO for UNIX
12 system administration.
13 Its articles consist of Solaris,
14 Sybase, Oracle, and miscellaneous
15 tips and operating system information.

Show the blank line with a line number
# nl -ba sysad.txt
1 This blog's
2 content
3 is primarily
4 a HOWTO for UNIX
5 system administration.
6 Its articles consist of Solaris,
7 Sybase, Oracle, and miscellaneous
8 tips and operating system information.
9
10 This blog's content
11 is primarily
12 a HOWTO for UNIX
13 system administration.
14 Its articles consist of Solaris,
15 Sybase, Oracle, and miscellaneous
16 tips and operating system information.

Print the numbered output
# nl
-ba sysad.txt | lp

Determine System Routing Tables

Here's another handy utility for troubleshooting the network. It's the ubiquitous netstat, which is short for network statistics.

#netstat -rn

This shows the system routing tables and displays the IPs.

#netstat -i

This shows the statistics per interface, e.g. hme0, lo0, ce0, ge1, etc.

Tuesday, February 13, 2007

Creating a Symbolic Link or Removing a Symbolic Link

On occasion, it may be prudent to create a generic symbolic link to an application directory whose name frequently changes (e.g. version numbers appended to the directory name). Why? The site may have a number of scripts or other types of programs that reference the generic name. In this example, I want myexample to be listed in the /opt directory.

#cd /opt
#ln -s /raid/myexample_18 myexample
#ls
myexample (checking for the listing)

Start my shell script in the background.
#/opt/myexample/bin/start_program.sh &

To remove a symbolic link
#rm myexample

Prevent Remote Logins by root

It can be fairly difficult to track system administrators who remotely login as root. Here's a way to prevent that particular activity, especially in an environment that requires stringent auditing.

vi /etc/default/login
#/dev/console
/dev/console
:wq! (saves and quits)

As you can see, the comment prefacing /dev/console has been removed. A user should not be able to remotely login as root.

Monitor CPU Usage for Each Process

When I'm looking for CPU hogs (processes), I like to use an alternate ps command. This command shows the percentage of CPU usage in ascending order.

# /usr/ucb/ps -aux | head -20
USER PID %CPU %MEM SZ RSS TT S START TIME COMMAND
root 2412 1.5 2.1 2840 2512 pts/2 O 23:25:35 0:00 /usr/ucb/ps -aux
root 2411 0.1 0.6 952 664 pts/2 S 23:25:35 0:00 head -20
root 353 0.0 1.6 2384 1952 ? S Nov 06 3:31 mibiisa -r -p 3280
root 0 0.0 0.0 0 0 ? T Nov 06 0:17 sched
root 1 0.0 0.3 792 376 ? S Nov 06 0:00 /etc/init -
root 2 0.0 0.0 0 0 ? S Nov 06 0:00 pageout
root 3 0.0 0.0 0 0 ? S Nov 06 1:45 fsflush
root 56 0.0 1.0 1544 1144 ? S Nov 06 0:00 /usr/lib/sysevent/

# while true
do
/usr/ucb/ps -aux | head -20
sleep 5
done

In terms of CPU percentage, the aforementioned loop shows the top 20 processes every 5 seconds.

You might want look at prstat, too, to check out the active stats

# prstat
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
2413 root 1536K 1280K cpu0 58 0 0:00.00 0.1% prstat/1
207 root 3688K 3112K sleep 58 0 0:00.00 0.0% nscd/8
353 root 2384K 1952K sleep 48 0 0:00.00 0.0% mibiisa/12
240 root 3240K 1608K sleep 59 0 0:00.00 0.0% sendmail/1
228 root 1408K 944K sleep 53 0 0:00.00 0.0% powerd/5
326 root 3088K 2016K sleep 22 0 0:00.00 0.0% dmispd/5
193 root 2000K 1376K sleep 33 0 0:00.00 0.0% cron/1
187 root 3472K 2016K sleep 52 0 0:00.00 0.0% syslogd/9
167 root 1984K 1416K sleep 12 0 0:00.00 0.0% lockd/1
215 root 3072K 976K sleep 43 0 0:00.00 0.0% lpsched/1

Invoke a Remote Terminal via CDE's Main Panel

On Common Desktop Environment's Main Panel, there is a small globe located near the workspace switch. Click on the globe and a gui should appear. Type in a trusted (remote) workstation's hostname and then hit enter. The remote's terminal window should pop up.

What's handy about this? You didn't have to rlogin, invoke xhost, or manually set DISPLAY. That was done automatically.

Here's what you need to put into the gui's field.

@remote_hostname

Setting the Terminal to Reasonable Values

When I use DTTERM, my terminal settings are off. To get around this problem, I have been using cmdtool or manually resetting the terminal's values. I can understand having to reset the values after viewing a binary file.

At any rate, here's the reset command.

#stty sane

Check terminal values
#stty -a

Monday, February 12, 2007

Add a Net With a Static Route

I have several static routes setup on my workstation. These routes are started at boot time. They are reliable because my network topology doesn't change often. If it does change, I know that I need to make modifications in the script.

Here's an example.

#vi /etc/rc3.d/S97static_routes
#!/usr/bin/sh
route add net 192.168.100.0 192.168.105.1 1
:wq! (quits and saves)

I just added the class C network 192.168.100.0 via the router 192.168.105.1. These IPs are only used for illustration purposes.

To manipulate the routing table
Route Add, Route Change, Route Delete, Route Monitor, Route Flush

Sunday, February 11, 2007

Determine Controller, Target, Disk Size, and Slice

There are many instances when you might need to determine the available disks, controller numbers, target numbers, and disk sizes. The format command gives you that information. Usually, I use it to ascertain which drives are online and available for mount.

Use care. It can be destructive if you don't know what you are doing. Amongst many other things, it's used to slice the hard drive.
#format

Create New Filesystems via Command Line

Creating multiple filesystems is fairly easy using Solaris. We can create or re-create filesystems when we want to expand a slice or can't recover it with FSCK. In the example, we assume the filesystem is unmounted and it's a raw partition, i.e. rdsk.

Here's the example.

Creates a new filesystem on slice 3. It will prompt you for a go ahead response, y or n.
#newfs /dev/rdsk/c0t0d0s3

Loop the task for multiple slices. It will prompt you for a go ahead response, y or n, for each iteration. Gives you a chance to abort your decision.
#for slice in 0 3 4 5 6 7
do
newfs /dev/rdsk/c0t0d0s$slice
done

Loop the task for multiple slices. It will NOT prompt you for a go ahead response, y or n, for each iteration. Assumes you know what you are doing.
#for slice in 0 3 4 5 6 7
do
echo y | newfs /dev/rdsk/c0t0d0s$slice
done

Saturday, February 10, 2007

Monitor Processor Statistics

There are times when our headless servers are running sluggish and we have to make a determination as to what is causing it. One of our commonly used tools is the mpstat command. It provides per processor statistics in a table form.

Here’s an example of its use.

No arguments show 1 iteration of per processor statistics
#mpstat

This example updates per processor statistics every 3 seconds
#mpstat 3

Determine Times When a User Logged in and Out

You can determine the actual times when a particular user was logged onto the system. This can be quite useful when an undocumented change is upsetting your customer, and you need to back out the change soonest. Moreover, it can be useful in tracking down intruders.

Here's an example of its use.

No arguments will list all users and their times
# last

For a particular user
# last esofthub
esofthub pts/3 wkstn2 Wed Oct 31 23:57 - 01:07 (1+01:09)
esofthub console :0 Sun Oct 28 22:28 - 23:50 (4+01:22)
esofthub console :0 Wed May 30 22:16 - 22:37 (14+00:20)
esofthub console :0 Fri May 11 20:59 - 21:47 (00:47)
esofthub console :0 Tue Apr 24 23:03 - 07:32 (10+08:29)
esofthub console :0 Tue Apr 24 23:02 - 23:02 (00:00)

Tracing Network Paths

Occasionally we experience transmission delays in our network. We later discover that our networks paths have been changed.

We use the traceroute command to ascertain this information. Here's an example of its use. Note: Some routers are programmed to block the traceroute action.

#traceroute esofthub.blogspot.com

Friday, February 09, 2007

Commit NIS+ Transaction Log

We also noticed an over sized NIS+ transaction log. We had hundreds of entries. It was in need of a checkpoint. Normally, if you have more than 3 entries, a checkpoint is needed.

Here is an example of a run we did.

# nisping -Ca

Then we checked for the number of entries in the NIS+ transaction log.

# nislog | head -15

The NIS+ trans log contained 3 entries; therefore, it was fully checkpointed.

Replace Contents of a NIS+ Table

If you want to make a change to a NIS+ table, dump the table to a file. Then you can make changes to the file by using your favorite text editor (emacs, vi, nedit, etc). Personally, I like using the ubiquitous vi.

Here is an example (you can use relative or absolute path for dumping and replacement).
# cd /var/nis/backup (for relative path)

If C shell
# setenv PATH $PATH:/usr/lib/nis

If Bourne or Korn Shell
# PATH=$PATH:/usr/lib/nis; export PATH

Dump the NIS+ table to file
# nisaddent -d hosts > /var/nis/backup/hosts

Edit the file
# vi hosts
...
...
10.10.10.1 myaddedhost
:wq! (saves and quits vi)

Replace and populate the contents of hosts to the NIS+ hosts table.
# nisaddent -rv -f /var/nis/backup/hosts hosts

Here is another example
# nisaddent -d passwd > /var/nis/backup/passwd
# vi /var/nis/backup/passwd
# nisaddent -rv -f /var/nis/backup/passwd passwd

Backup NIS+ Tables

Today we had some serious problems with our NIS+ tables. I would strongly advise that you make a backup of the /etc/.rootkey file and /var/nis directory. Also, you should dump the NIS+ tables to files on a frequent basis.

Here is a recommended procedure:

If C shell
# cd /var/nis/backup
# setenv PATH $PATH:/usr/lib/nis

If Bourne or Korn Shell
# PATH=$PATH:/usr/lib/nis; export PATH
# nisaddent -d aliases > aliases
# nisaddent -d bootparams > bootparams
# nisaddent -d ethers > ethers
# nisaddent -d group > group
# nisaddent -d hosts > hosts
# nisaddent -d netgroup > netgroup
# nisaddent -d netid > netid
# nisaddent -d netmasks > netmasks
# nisaddent -d networks > networks
# nisaddent -d passwd > passwd
# nisaddent -d protocols > protocols
# nisaddent -d publickey > publickey
# nisaddent -d rpc > rpc
# nisaddent -d services > services
# nisaddent -d trusted > trusted
# nisaddent -d timezone > timezone
# nisaddent -d auto_home.org_dir > auto_home
# niscat auto_master.org_dir > auto_master
# niscat auto_direct.org_dir > auto_direct

Confirm 64-bit Application Support

We use the isainfo utility with the verbose option to confirm if we can run 64-bit applications. It also lets us confirm if the kernel runs 32-bit or 64-bit device drivers.

#isainfo -v

Thursday, February 08, 2007

Add Login to Sybase

Here's the syntax to add a login to the Sybase database.

For example, add login esofthub

#isql -Usa -Ppassword
>sp_addlogin esofthub, "mypassword", null, null, "A New Login"
>go
>quit

The user is assigned to the default database and the default language is used.

Add a User to a Database for Sybase

Here's the syntax to add a user to a database in Sybase.

For example, add user esofthub to database named mysybasedb

#isql -Usa -Ppassword
>use mysybasedb
>go
>sp_adduser esofthub
>go
>quit

Automatically Dump the Database for Sybase

Here's a quick and dirty way of automatically backing up your Sybase database. Personally, we save a dump for each day of the week.

Ensure that you have permissions to write to the destination directory.

Create the SQL script
#vi /home/esofthub/dump.sql
1>use master
2>go
1>dump database databasename to '/raid/sybdumps/dump.dat'
2>go
:wq! (saves and quits vi)

Create the shell script
#vi /home/esofthub/dump.sh
#!/usr/bin/sh
isql -U login -P password -e < /home/esofthub/dump.sql > dump.out
:wq! (saves and quits vi)

Add entry to the crontab
#crontab -e
0 5 * * * /home/esofthub/dump.sh
:wq! (saves and quits vi)

This crontab entry invokes the dump.sh script every day at 0500.

Tuesday, February 06, 2007

Run Debugger and Verbose Modes in a Script

We write scripts frequently and occassionally they are stricken with a few bugs. Most of our scripts are written in Bourne Shell. To debug in the verbose mode, we append the -xv options to /usr/bin/sh.

Here's a demo script to illustrate the aforementioned comments.

#!/usr/bin/sh -xv
#Name: SampleScript
#Purpose: Demonstrate debug and verbose options.
#
#Menu
echo "Choose either P, D, Q "
echo "[P]rint"
echo "[D]elete"
echo "[Q]uit"

#Get letter from user
read letter
#Match response
case $letter
in
P|p) echo "Name of file to print."
read file
lp $file;;
D|d) echo "Name of file to delete."
read file
rm $file;;
*) echo "Quitting program";;
esac

Print From the Buffer via the Command Line

When you are working with files, you might want to print a subsection of the page(s). In this example, I don't won't the whole page printed, so I perform a copy and paste action for the desired text. I normally use cmdtool utility, which uses the copy/paste keys.

Here's a partial description of My SysAd Blog header:

#lp (set for default printer)
UNIX stands for UNiplexed Information and Computing System--originally spelled UNICS. It supports such tasks as running hardware, device drivers, peripherals and third party applications. It's a multi-user, multi-tasking, multi-processing, and multi-threading environment. (press enter)
control ^d (control d)

Otherwise

#lp -d yourprinter
UNIX stands for UNiplexed Information and Computing System--originally spelled UNICS. It supports such tasks as running hardware, device drivers, peripherals and third party applications. It's a multi-user, multi-tasking, multi-processing, and multi-threading environment. (press enter)
control ^d (control d)

Monday, February 05, 2007

Count the Lines, Words and Characters in a File

Counting the number of lines in a file can be useful. I've used them to control a looping construct. Here's an example of a run.

# wc esofthub.dat
10 23 60 esofthub.dat
This file has 10 lines, 23 words and 60 characters.

# wc -lwc esofthub.dat esofthub1.dat
10 23 60 esofthub.dat
12 25 63 esofthub1.dat
22 48 123 total
This command totals the lines, words and characters.

or
This method also totals the lines, words and characters.
# wc *
7 7 38 user1.txt
9 9 47 user2.txt
11 11 66 user3.txt
5 5 31 user4.txt
32 32 182 total

Note: The Blogger application parsed out the less-than characters so an underscore was used to preserve the contiguous nature of the "<<_eof">

# wc <<_EOF
> This will show the
> number of lines, words
> and characters in this
> exercise
> _EOF
4 13 76

Methods of Accessing a Workstation

Most of the times you will need to have an account to log into most workstations. The exception is anonymous FTP.

These are just a few examples...
Note: rlogin and rsh will prompt you for a password if the remote system does not trust the local system.

# rlogin -l esofthub_user myserver
# rsh myserver (invokes rlogin without command line arguments)
# ftp myserver (prompts you for a password unless it is anonymous ftp)
# telnet myserver (prompts you for a password)

Add a Scroll Bar to xterm

Here is a quick and dirty way of adding a scrollbar (-sb) to an xterm window. I like adding colors to it, too, especially old school black and green. The xterm environment is determined by the .Xdefaults file if it is present.

# xterm -bg black -fg green -title "My Blog Log" -sb &

If you make changes to the .Xdefaults file during your login session, you can load the changes by doing the following action:

# xrdb -load /home/esofthub/.Xdefaults

You might also want to increase the buffer space. In this example, I am increasing the buffer space to 3000 lines.

# xterm -bg black -fg green -title "My Blog Log" -sb -sl 3000 &

Remap Buttons on a Mouse

Today I had a left-handed user ask me to remap the mouse buttons. Frankly speaking, I had to look it up. Here's how I did it.

#xmodmap -e 'pointer= 3 2 1'

Sunday, February 04, 2007

Get System Identification for Solaris

Here's the command to get system identification information, such as operating system (OS) implementation, network nodename, release level of OS, version of OS, and hardware platform. I use it frequently.

#uname -a

Limit Access from Remote Workstations

You should ensure that you have an /etc/hosts.allow file present. Populate it with the workstations you want to allow access.

vi /etc/hosts.allow
daemon_program:client_list:options

Here's an example:


#vi /etc/hosts.allow
in.telnetd:15.23.1.1,15.23.1.2:
in.ftpd:15.23.1.1,15.23.1.2:
in.rshd:15.23.1.1,15.23.1.2:
in.rlogind:15.23.1.1,15.23.1.2:
:wq! (saves and quits vi)

Copy Files to a Remote Workstation

To copy a file to a remote workstation, you must ensure that the receiving workstation is configured for such a task.

If you copying a file to the root directory, ensure that the /.rhosts file is properly populated. Bear in mind that the login directory for the root account could be set to something else other than /, so check your /etc/passwd file to verify. Suppose I wanted to copy /etc/default/login to another workstation.

On remote workstation:
#vi /.rhosts
remote_workstation root
:wq! (saves and quits)

On local workstation:
#rcp -p /etc/default/login remote_workstation:/etc/default

Determine Who is Logged on

There are several ways to determined who is logged onto a workstation. Here's a couple ways.

#who -r
Or
#finger

If you want to know who is logged onto remote machines, use this command.
#rusers

Set EDITOR Variable for vi

Do you ever have problems displaying vi in the xterm or cmdtool windows? Your EDITOR variable may have not been set correctly. Here is a simple fix.

Bourne shell:
# sh
# EDITOR=vi; export EDITOR

C shell:
# csh
# setenv EDITOR vi

I had to use these procedures today because I was having problems displaying text the crontab with crontab -e.

By the way, you can add this type of information into your initialization files ($HOME/.cshrc, $HOME/.kshrc, $HOME/.profile, etc).

Trouble With Strange Characters -- Might be TERM

Occassionally, I have had users complain about strange characters when they use xterm or cmdtool. But most of the time, it has to do with their TERM variable. Here's what you can do to check for it.

#echo $TERM (see what value is in the variable)
If its output is not what you expected, set the correct value.

For Sun:
#sh
#TERM=sun
#export TERM

For most others:
#TERM=vt100
#export TERM

For C shell:
#csh
#setenv TERM sun
or
#setenv TERM vt100

Note: TERM must match one of the terminal types listed in the /usr/lib/terminfo directory.

Determine the Directory Size Recursively

Sometimes you want to ascertain the space hogs on your system. You might have noticed that a certain top level directory is larger than usual, but you are unsure what subdirectory or subdirectories are the culprits.

Here's an example of what can be done:

#cd /huge_directory
#du -k . (current directory size given in kilobytes)

To find the sizes recursively (subdirectories):

#cd /huge_directory
#sh
#for size in 'ls'
do
du -k $size
echo $size done
done

Determine Available Space on a Filesystem

Lately our /var filesystem has been filling up and causing problems. How did we know that particular filesystem was filling up? We executed a UNIX command that provided a snapshot of all the filesystems.

Here's the command:

#df -k
shows the space status of all the filesystems on the system in kilobytes

Or you can be specific about the filesystem
#cd /var
#df -k .

Perform a Network File System Mount

Often we are tasked to mount a directory or directories from a server to a client. Usually we do this using the automounter, which creates a virtual directory on the client. We like to use these soft mounts because the automounter unmounts the filesystem after 10 minutes (default) of non-access.

Here's an example of doing a simple automount:

On the server:

#vi /etc/dfs/dfstab
share "options go here" /export/exportdir
:wq! (saves and quits vi)

#share /export/exportdir

On the client workstation:

#vi /etc/auto_esofthub
/opt/mount_point "options go here" server:/export/exportdir
:wq! (saves and quits vi)

Add this entry into the /etc/auto_master.
#vi /etc/auto_master
/- "tab or space delimiter" /etc/auto_esofthub
:wq! (saves and quits vi)

#automount -v (mounts virtual directory or directories in verbose mode)

Note: These virtual mounts can be used to hide directories underneath them.

Saturday, February 03, 2007

Prevent Process Hangup on Log Out

Often I start processes in the background, but most of the time, I can not hang around until they are done due to other pressing sysad matters. For security reasons, I have to log off the computer when unattended and that event normally terminates the children of a process.

Here's an example of how I ensure my process(es) will continue regardless of log on status:

#nohup sort esofthub.dat > esofthub.sorted &

OR I can even mail the results to myself.

#nohup sort esofthub.dat > esofthub.sorted | nohup mailx -s "esofthub's sorted file" &

Thursday, February 01, 2007

Problems Recovering Hard Drive with FSCK

After a hard crash today, a colleague of mine tried repeatedly (several hours) to recover a newly installed Sun v490 server (w/Solaris 8) and its Sun RAID with FSCK. However, each time he ran the FSCK command, the system returned UFS block read errors. The problem seemed somewhat familiar to me, and I asked him if he had logging configured. He said yes. I recommended temporarily removing the logging option from the /etc/vfstab file.

Here's what was done:

#cp –p /etc/vfstab /etc/vfstab.020107
OR
#cp -p /etc/vfstab /etc/vfstab.`date '+%m%d%y'`
#vi /etc/vfstab
change "logging" option to "-" where applicable
: wq! (quits and saves)

#init 0
boot

The system booted up and FSCK automatically invoked and was able to fix whatever UFS block errors that were present. Then the original /etc/vfstab file was manually restored.