Softpanorama

May the source be with you, but remember the KISS principle ;-)
Contents Bulletin Scripting in shell and Perl Network troubleshooting History Humor

Tiporama: Solaris Tips

News

Solaris

Recommended Books Recommended Links Shell Tips and Tricks AWK one liners
Shell Prompt Tips VIM Tips Perl Tips isainfo command How to reject remote logging in syslogd Core files creation blocking in Solaris
Enabling XDMCP in Solaris 10 Solaris DNS Tips DNS tricks and tips New options in Solaris 10 daemons Enabling TCP Wrappers in Solaris 10
Open source software Serial console Tips Resetting root password Humor Etc

It's not easy to define what is a tip. Tips are setting, commands, etc that are important to know but usually are hidden in the volume of documentation and/or capabilities that are are not evident.

The first and the most important tip that one can get to a Solaris user is to get a good shell prompt. What Sun ships is a disaster.

The second is to install open source software provided by Sun on a separate disk. Not all of it requires root access and administrator permission (difficult to obtain in corporate environment). Also if the server allow NFS mounting you can mount directory from you workstation to use many of those utilities.

Tips pages are usually do not last long on the Net. Please be ready to find out that some of the links below already disappeared.

Here are several of my favorite tip pages

Some little known Solaris utilities
Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

[Feb 04, 2017] Restoring deleted /tmp folder

Jan 13, 2015 | cyberciti.biz

As my journey continues with Linux and Unix shell, I made a few mistakes. I accidentally deleted /tmp folder. To restore it all you have to do is:

mkdir /tmp
chmod 1777 /tmp
chown root:root /tmp
ls -ld /tmp
 
mkdir /tmp chmod 1777 /tmp chown root:root /tmp ls -ld /tmp 

[Feb 04, 2017] Use CDPATH to access frequent directories in bash - Mac OS X Hints

Feb 04, 2017 | hints.macworld.com
The variable CDPATH defines the search path for the directory containing directories. So it served much like "directories home". The dangers are in creating too complex CDPATH. Often a single directory works best. For example export CDPATH = /srv/www/public_html . Now, instead of typing cd /srv/www/public_html/CSS I can simply type: cd CSS
Use CDPATH to access frequent directories in bash UNIX
Mar 21, '05 10:01:00AM • Contributed by: jonbauman

I often find myself wanting to cd to the various directories beneath my home directory (i.e. ~/Library, ~/Music, etc.), but being lazy, I find it painful to have to type the ~/ if I'm not in my home directory already. Enter CDPATH , as desribed in man bash ):

The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. A sample value is ".:~:/usr".
Personally, I use the following command (either on the command line for use in just that session, or in .bash_profile for permanent use):
CDPATH=".:~:~/Library"

This way, no matter where I am in the directory tree, I can just cd dirname , and it will take me to the directory that is a subdirectory of any of the ones in the list. For example:
$ cd
$ cd Documents 
/Users/baumanj/Documents
$ cd Pictures
/Users/username/Pictures
$ cd Preferences
/Users/username/Library/Preferences
etc...

[ robg adds: No, this isn't some deeply buried treasure of OS X, but I'd never heard of the CDPATH variable, so I'm assuming it will be of interest to some other readers as well.]

cdable_vars is also nice
Authored by: clh on Mar 21, '05 08:16:26PM

Check out the bash command shopt -s cdable_vars

From the man bash page:

cdable_vars

If set, an argument to the cd builtin command that is not a directory is assumed to be the name of a variable whose value is the directory to change to.

With this set, if I give the following bash command:

export d="/Users/chap/Desktop"

I can then simply type

cd d

to change to my Desktop directory.

I put the shopt command and the various export commands in my .bashrc file.

[Mar 28, 2014] You can use dtterm instead of xterm when you need a terminal via X11.

This is a better more convenient to work with terminal

Solaris IAOQ

  1. General
    1. How do I untar a file with absolute paths to a relative location?
    2. How do I do a recursive grep?
    3. How do I find out the number of files used on local filesystems?
    4. How do I use a FIFO?
    5. How do I list available signals?
    6. How do I show how a process will respond to a given signal?
    7. How do I remove a file that begins with a - ?
    8. ls(1) no longer works, how can I view directory contents?
    9. How can I tell what the various ERROR codes mean?
    10. How can I create a file of arbitrary size?
    11. How can I get seconds from epoch?
    12. How do I get yesterdays date?
    13. How do I get access, modify, creation time of a file?
    14. What is load average?
    15. What is the run queue?
    16. How can I copy directory contents to a remote machine?
    17. How do I archive directories with 155+ character directory names or 100+ character file names?
    18. How do I convert hexadecimal to decimal and vice versa?
    19. How do I convert binary to decimal and vice versa?
    20. What can I do about zombie processes?
    21. How do I list just directories, but not their contents?
    22. How do I grep for multiple patterns?
    23. How do I configure the system wide dynamic linker?

  2. Shell
    1. My setuid shell script keeps running as the real user, why?
    2. Why is cd() a shell built-in rather than an executable?
    3. How do I redirect stderr into stdout?
    4. How do I rename files by extension like MS-DOS?
    5. AWK Tricks
      1. Round up number to next whole number
    6. SED Tricks
  3. Kernel
    1. Where do I put kernel configuration?
    2. How do I add more PTYs?
    3. What is shared memory?
    4. How do I know the limits for shared memory kernel tunables?
    5. What is a semaphore?
    6. How do I know the limits for semaphore kernel tunables?
    7. What is a door?
    8. add_drv(1m) fails with "add_drv/rem_drv currently busy; try later".
    9. How do I increase the number of file descriptors available to an application?
    10. What is a register window?
    11. What is the default memory page size?
    12. What is the current memory page size?
    13. What kind of binaries can my kernel run?
    14. What kind of drivers and modules can my kernel run?
    15. How do I adjust interprocess communications (IPC) variables?
    16. How do I modify strings in the running kernel?
  4. Devices
    1. How do I make the system aware of new devices?
    2. How do I know what the video configuration for my adapter/display is?
    3. How do I know what the adapter/display is capable of?
    4. How do I change color depth?
    5. How can I prevent my system from halting when my terminal server is rebooted?
    6. What does hme stand for in /dev/hme?
    7. Where are device drivers located?
    8. How do I configure a device driver?
    9. How do I configure the scsi-options for my scsi controller?
    10. How do I change the default terminal setting on the system console?
    11. What instruction set does my CPU support?
  5. Filesystem
    1. How do I get a list of superblocks on a filesystem?
    2. How do I grow/shrink a ufs filesystem?
    3. How do I determine what type of filesystem a given device has?
    4. What are inodes 0, 1, and 2 used for?
    5. What do I do if I have a corrupt boot block?
    6. What is the DNLC?
    7. How does the DNLC relate to the kernel vfs layer?
    8. How do I get statistics about DNLC performance?
    9. How do I prevent the ufs filesystem from buffering my database files?
    10. How do I disable "access time" updates for file?
    11. What is the difference between file mode 1 and 5?
    12. How can i force an unmount of a filesystem?
    13. What is the default ufs block size?
    14. What is the default zfs block size?
    15. Why is /lib/libc.so.1 showing up as a mounted filesystem?
    16. How do I mount an ISO image file?
  6. X11
    1. How do I use an alternate window manager?
    2. How do I disable X Windows from starting at boot?
    3. How do I disable that annoying beep?
    4. How do I disable the CDE front panel?
    5. How do I determine which X11 version and extensions are supported?
  7. Crash Dump
    1. When did it happen?
    2. How do I get information about what was going on?
  8. Veritas Volume Manager
    1. How do I allow a user/group to write to a managed raw volume?
    2. How do I move rootdg from one system to another?
    3. What is the difference between Disk Suite nd Veritas Volume Manager?
    4. What is the difference between RAID 0+1 and 1+0?
  9. Veritas Filesystem
    1. How do I make vxfs support large files?
    2. How do I defragment a vxfs filesystem?
    3. How do I grow/shrink a vxfs filesystem?
    4. How do I prevent the vxfs filesystem from buffering my database files?
    5. How do I create a Quick I/O file?
    6. What is the default vxfs block size?
  10. Network ( Physical Layer | Transport Layer )
    1. Physical Layer
      1. How do I find the speed my network card is at?
      2. How do I configure what my network card is capable of?
      3. How do I display what my link partner is capable of?
      4. How can I tell if my card is active on the network?
      5. How do I use multiple ethernet interfaces on the same network segment?
      6. How do I determine if local mac addresses are in use on my host?
    2. Transport Layer
      1. How do I configure stronger sequence number generation?
      2. I have a large amount of connections in state CLOSE_WAIT, what can be done to reduce this number in the future?
      3. How can I increase my TCP Window size?
      4. What do all the TCP states actually mean?

[May 09, 2010] BigAdmin Shell Commands

Additional Resources
1. All Solaris Commands *
2. Alphabetical Directory of Linux Commands *
3. Awk, Nawk and GNU Awk Cheat Sheet *
4. commandlinefu.com - shell one-liners *
5. Comparision of Shell commands (PDF) *
6. coolcommands.com *
7. DOS to UNIX command translation *
8. Famous Awk One-Liners Explained, Part I *
9. Famous Awk One-Liners Explained, Part II *
10. Handy One-Liners for sed *
11. List of Unix Commands *
12. Man Pages: System Administration Commands (Solaris 10)
13. Man Pages: System Administration Commands (Solaris 9)
14. Man Pages: User Commands (Solaris 10)
15. Man Pages: User Commands (Solaris 9)
16. Sun Cluster Command Line Cheat Sheet
17. Tips on good shell programming practices *
18. Top 10 Best Cheat Sheets and Tutorials for Linux / UNIX Commands *
19. Universal Command Guide for Operating Systems *
20. Unix 'find command' helper *
21. Unix Find Command Tutorial *
22. Useful Solaris Commands (Blog) *
Debugging
23. cat -v -t -e [file]
/* Show non-printing characters */
24. dumpadm -d swap
/* Configure swap device as dump device */
25. ld -l <libname without 'lib'>
/* Check if you have a particular library */
26. truss -f -p <pid of a shell>
/* Using multiple windows, this can be used to trace setuid/setgid programs */
27. truss executable
/* Trace doing of given command ( useful debugging ) */
Disk Commands
28. /bin/mount -F hsfs -o ro /dev/sr0 /cdrom
/* Mount an ISO 9660 CDROM */
29. /usr/bin/iostat -E
/* Command to display drives statistics */
30. du -ad /var | sort -nr
/* Report the the disk used in /var in reverse order */
31. du -k .
/* Report disk usage in Kilobytes */
32. du -sk * | sort -nr | head
/* Shows the top ten largest files/directories */
33. du -sk *|sort -k1,1n
/* Reports total disk space used in Kilobytes in present directory */
34. du -sk .
/* Report total disk usage in Kilobytes */
35. du -sk `ls -A` | sort -nr | head
/* Shows the ten largest files/directories (including hidden ones) */
36. fdformat -d -U
/* Format diskette */
37. mount -F hsfs -o ro `lofiadm -a /export/temp/software.iso` /mnt
/* Mount an ISO Image */
38. newfs -Nv /dev/rdsk/c0t0d0s1
/* To view the superfblocks available */
39. One-liner to copy a partition table
/* prtvtoc /dev/dsk/c1t2d0s2 | fmthard -s - /dev/rdsk/c1t3d0s2 */
40. prtvtoc /dev/rdsk/c0t0d0s2
/* Disk geometry and partitioning info */
41. prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2
/* Copy partition table from one disk to another */
42. quot -af
/* How much space is used by users in kilobytes */
43. volrmmount -i floppy
/* Mount a floppy or other media easily by its nickname. */
Driver Parameters
44. ndd /dev/ip ip_forwarding
/* Show the ip_forwarding variable in the kernel */
45. ndd /dev/ip ip_forwarding 1
/* Set the ip_forwarding variable in the kernel */
46. ndd /dev/ip \?
/* Show all IP variables set in the kernel */
File Manipulation
47. bzcat mydir.tar.bz2 | tar xvf -
/* Untar and bunzip2 in a single command */
48. dos2unix | -ascii <filename>
/* Converts DOS file formats to Unix */
49. fold -w 180
/* To break lines to have maximum char */
50. split [-linecount] [file]
/* Split files into pieces */
51. tar cvf - ./mydir | bzip2 - >> mydir.tar.bz2
/* Create 'tar' archive and 'bzip2' in a single command */
52. [vi] : %s/existing/new/g
/* Search and Replace text in vi */
53. [vi] :set list
/* Show non-printing characters in vi */
54. [vi] :set nu
/* Set line numbers in vi */
55. [vi] :set ts=[num]
/* Set tab stops in vi */
File System
56. /sbin/uadmin x x
/* Syncs File Systems and Reboots systems fast */
57. awk ' END {print NR}' file_name
/* Display the Number of lines in a file */
58. cat /dev/null > filename
/* Zero's out the file without breaking pipe */
59. cksum [filename]
/* View the checksum value for the given file */
60. dd if=/dev/rdsk/... of=/dev/rdsk/... bs=4096
/* Make a mirror image of your boot disk */
61. df -k | grep dg| awk '{print $6}' |xargs -n 1 umount
/* Unmount all file systems in disk group dg */
62. fsck -F ufs -o b=97472 /dev/rdsk/c0t0d0s0
/* Check and repair a UFS filesystem on c0t0d0s0, using an alternate superblock */
63. fsck -F ufs -y /dev/rdsk/c0t0d0s0
/* Check a UFS filesystem on c0t0d0s0, repair any problems without prompting. */
64. fsck -F ufs /dev/rdsk/c0t0d0s0
/* Check a UFS filesystem on c0t0d0s0 */
65. gzip -d -c tarball.tgz | (cd /[dir];tar xf - ) &
/* Unpacking tarballs to diff location */
66. gzip -dc file1.tar.gz | tar xf -
/* Unpack .tar.gz files in place */
67. ln [-fhns] <source file> <destination file>
/* Creating hard links and soft links */
68. ls -1d [directory]/*
/* List only subdirectories - 1 per line */
69. ls -al | awk '$3 == "oracle" || $3 == "root" {print $9}'
/* List all file names by testing owner */
70. ls -l | sort +4n
/* List files by size */
71. ls -la | awk '{ print $5," ",$9 }' | sort -rn
/* File sizes of current directory */
72. ls -lR | awk '{total +=$5};END {print "Total size: " total/1024/1024 "MB" }'
/* Recursive directory size calculations in MB */
73. mkisofs -l -L -r -o [image-name].iso [directory]
/* Create an ISO image of a directory */
74. mount -F ufs -o rw,remount /
/* Used to remount root to make it writeable */
75. mount -o remount,logging /spare
/* Re-mount the ro file system rw and turn on ufs logging */
76. mount DOS fdisk partition from Solaris
/* mount -f pcfs /dev/dsk/c0d0p1 /export/dos */
77. mv [filename]{,.new_suffix}
/* Renaming file */
78. pax -rw . /newdir
/* Efficient alternative for copying directories */
79. prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2
/* Cloning Partitiontables */
80. rpm -q --queryformat '%{INSTALLPREFIX}\n' [packagename]
/* [Linux] Locate binaries */
81. tail -f <path to file>
/* Follow updates to a file in real time */
82. tar cf - . | (cd /newdir ; tar xf -)
/* Recursively copy files and their permissions */
83. tar cvf filename.tar
/* Create a tape (tar) archive */
84. tar xvf filename.tar
/* Extract a tape (tar) archive */
85. X=$(wc -l < filename); echo $X
/* Count number of lines in a file into a variable (ksh) */
86. zcat <patch_file.tar.Z | tar xvf -
/* Extract the patch_file that is a compressed tar file */
87. zcat [cpio file] | cpio -itmv
/* Show the contents of a compressed cpio */
File Transfer
88. find . -depth | cpio -pdmv /path/tobe/copied/to
/* Fast alternative to cp -pr */
89. find . -follow | cpio -pdumL /path/tobe/copied/to
/* Copy with symbolic links to be followed */
90. get filename.suffix |"tar xf -"
/* Undocumented Feature of FTP */
91. Move any file(s) without actually touching them
/* ssh cd /some/directory \&\& tar cf - | ssh cd /some/direstory \&\& tar xvf - */
92. put "| tar cf - ." filename.tar
/* Undocumented Feature of FTP */
93. sendport
/* FTP command for transferring large numbers of files within the same control session */
General
94. /bin/printf '%d\n' '0x<hex>'
/* Converts hexadecimal number to decimal. */
95. /usr/bin/catman -w
/* Create windex databases for man page directories */
96. echo 'obase=16;255' | bc
/* Simple way to convert decimal to hex */
97. FQ_FILENAME=<fully_qualified_file_name>; echo ${FQ_FILENAME%/*}
/* Extract directory from fully-qualified file name. */
98. mailx -H -u <username>
/* List out mail headers for specified user */
99. ps -ef | grep -i $@
/* Access common commands quicker */
100. set filec
/* Set file-completion for csh */
101. uuencode [filename] [filename] | mailx -s "Subject" [user to mail]
/* Send files as attachments */
102. xauth -f /home/${LOGNAME} extract - ${DISPLAY} | xauth merge -
/* Allow root to xdisplay after su */
Hardware
103. cfgadm
/* Verify reconfigurable hardware resources */
104. m64config -depth 8|24
/* Sets the screen depth of your M64 graphics accelerator */
105. m64config -prconf
/* Print M64 hardware configuration */
106. m64config -res 'video_mode'
/* Change the resolution of your M64 graphics accelerator */
107. prtpicl -v | grep sync-speed
/* Discover SCSI sync speed */
Kernel
108. /usr/sbin/modinfo
/* Display kernel module information */
109. /usr/sbin/modload <module>
/* Load a kernel module */
110. /usr/sbin/modunload -i <module id>
/* Unload a kernel module */
111. /usr/sbin/sysdef
/* Show system kernal tunable details */
112. nm -x /dev/ksyms | grep OBJ | more
/* Tuneable kernel parameters */
113. update_drv -f [driver name]
/* Force a driver to reread it's .conf file without reloading the driver */
Memory
114. pagesize -a
/* Available page sizes for Solaris 9 */
115. prtconf | grep Mem
/* Display Memory Size of the local machine. */
Network Information
116. arp -a
/* Ethernet address arp table */
117. arp -d myhost
/* Delete an ethernet address arp table entry */
118. lsof -iTCP@10.20.2.9
/* Display open files for internet address */
119. named-xfer -z qantas.com.au -f /tmp/allip
/* Get All IP Addresses On A DNS Server */
120. ndd /dev/arp arp_cache_report
/* Prints ARP table in cache with IP and MAC address */
121. netstat -a | grep EST | wc -l
/* Displays number active established connections to the localhost */
122. netstat -a | more
/* Show the state of all the sockets on a machine */
123. netstat -i
/* Show the state of the interfaces used for TCP/IP traffice */
124. netstat -k hme0
/* Undocumented netstat command */
125. netstat -np
/* Similar to arp -a without name resolution */
126. netstat -r
/* Show the state of the network routing table for TCP/IP traffic */
127. netstat -rn
/* Displays routing information but bypasses hostname lookup. */
128. snoop -S -ta [machine]
/* Snoop for network packets and get size and time stamp entries. */
129. traceroute <ipaddress>
/* Follow the route to the ipaddress */
Network Tuning
130. /sbin/ifconfig hme0:1 inet 10.210.xx.xxx netmask 255.255.0.0 broadcast 10.210.xxx.xxx
/* Virtual Interfaces */
131. /sbin/ifconfig hme0:1 up
/* Bring virtual interface up */
132. /usr/sbin/ndd -set /dev/hme adv_100fdx_cap 1
/* Nailling to 100Mbps */
133. ifconfig eth0 10.1.1.1 netmask 255.255.255.255
/* Add an Interface */
134. ifconfig eth0 mtu 1500
/* Change MTU of interface */
135. ndd -set /dev/ip ip_addrs_per_if 1-8192
/* To set more than 256 virtual ip addresses. */
136. ndd -set /dev/tcp tcp_recv_hiwat 65535
/* Increase TCP-receivebuffers on Sol2.5.1 systems with 100BaseTx */
137. ndd -set /dev/tcp tcp_xmit_hiwat 65535
/* Increase TCP-transmitbuffers on Sol2.5.1 systems with 100BaseTx */
Processes
138. /usr/proc/bin/ptree <pid>
/* Print the parent/child process 'tree' of a process */
139. /usr/proc/bin/pwdx <pid>
/* Print the working directory of a process */
140. /usr/ucb/ps -aux | more
/* Displays CPU % usage for each process in ascending order */
141. /usr/ucb/ps -auxww | grep <process name>
/* Gives the full listing of the process (long listing) */
142. coreadm -i core.%f.%p
/* Append program name and process id to core file names */
143. fuser -uc /var
/* Processes that are running from /var */
144. ipcs
/* Report inter-process communication facilities status */
145. kill -HUP `ps -ef | grep [p]roccess | awk '{print $2}'`
/* HUP any related process in one step */
146. lsof -i TCP:25
/* Mapping port with process */
147. pfiles <pid>
/* Shows processes' current open files */
148. pkill -n <name>
/* Kill a process by name */
149. prstat -a
/* An alternative for top command */
150. ps -edf -o pcpu,pid,user,args
/* Nicely formatted 'ps' */
151. ps -ef | grep -i <string> | awk '{ print $2 }'
/* Creates list of running PID by <string> */
152. ps -ef | grep -i <string> | awk '{ print $2 }'
/* Creates list of running PID by */
153. ps -ef | grep <process name> | grep -v grep | cut -c 10-15 | xargs kill -9
/* Find and kill all instances of a given process */
154. ps -ef | more
/* Show all processes running */
155. ps -ef|grep -v "0:00"|more
/* Gives you a list of any process with CPU time more than 0:00 */
156. ps -eo pid,args
/* List processes in simplified format */
157. ps -fu oracle|grep pmon
/* See which instances of Oracle are running */
158. top -b 1
/* Returns the process utilizing the most cpu and quits */
Resource Management
159. /usr/bin/ldd [filename]
/* List the dynamic dependencies of executable files */
160. /usr/proc/bin/pmap pid
/* Report address space map a process occupies */
Route Configuration
161. route add net 128.50.0.0 128.50.1.6 1
/* Add a route to the routing table */
162. route change 128.50.0.0 128.50.1.5
/* Changes the destination address for a route */
163. route delete net 128.50.0.0 128.50.1.6
/* Delete a route from the routing table */
164. route flush
/* Flush the routing table, which will remove all entries */
165. route get [hostname]
/* Which interface will be used to contact hostname */
166. route monitor
/* Monitor routing table lookup misses and changes */
Searching Items
167. cat <filename> | awk '{if (substr($1,1,1) == '#') print $0 }'
/* Print all lines in a file beginning with a specific character */
168. egrep "patterna|patternb" <filename>
/* Search for multiple patterns within the same file */
169. find <start_path> -name "<file_name>" -exec rm -rf {} \;
/* Recursively finds files by name and automatically removes them */
170. find . -type f -print | xargs grep -i [PATTERN]
/* Recursive grep on files */
171. find . ! -mtime -<days> | /usr/bin/xargs rm -rf
/* Finds and removes files older than <days> specified */
172. find . -exec egrep -li "str" {} \;
/* Find a string in files starting cwd */
173. find . -mtime -1 -type f
/* Find recently modified files */
174. find . -type f -exec grep "<sub-string>" {} \; -print
/* Find files (and content) containing <sub-string> within directory tree */
175. find . -type f -exec grep -l "<sub-string>" {} \;
/* Find files (and content) containing <sub-string> within directory tree */
176. find ./ \! -type f -exec ls -l {} \;|grep -v '^[l|p|s|-]'|grep -v 'total' | wc -l
/* Find number of directories under the current directory */
177. find / -fstype nfs -prune -o fstype autofs -prune -o -name filename -print
/* find without traversing NFS mounted file systems */
178. find / -mtime <# of days>
/* Find files modified during the past # of days */
179. find / -perm -2 -a ! -type l
/* Find files writable by 'others' */
180. find / -type f |xargs ls -s | sort -rn |more
/* List files taking up the most system space */
181. find / -user <username>
/* Find all files owned by <username> */
182. find / -xdev -type f -ls|sort -nr -k 7,7
/* Find largest files in a file system */
183. find / | grep [file mask]
/* Fast way to search for files */
184. find /proc/*/fd -links 0 -type f -size +2000 -ls
/* Find large files moved or deleted and held open by a process */
185. grep <full_path_to_filename> /var/sadm/install/contents| awk '{ print $1 ' ' $10 }'
/* Find which package contains a particular file */
186. ls -lR | grep <sub_string>
/* Fast alternative to find. */
187. pkgchk -l -p /absolute/path/todir
/* Which package does this file belong to? */
Security
188. cat /dev/urandom | tr -dc '[a-z][A-Z][0-9]-_!@#$%^&*()_+{}|:<>?=' | fold -w 10| head -n 5
/* Generate 5 random ten-character strings, with symbols */
189. crypt <abc.cr> abc && rm abc.cr
/* Decrypting a file that has been encrypted */
190. crypt <abc> abc.cr && rm abc
/* File encryption with crypt */
191. echo 'Please go away' > /etc/nologin
/* Stops users logging in */
192. find / -perm -0777 -type d -ls
/* Find all your writable directories */
193. find / -type f -perm -2000 -print
/* Find all SGID files */
194. find / -type f -perm -4000 -print
/* find all SUID files */
195. getpwenc [encryption scheme] password
/* Genrate passwords for LDAP Using 'getpwenc' Utility */
196. trap 'exit 0' 1 2 3 9 15
/* Trap specific signals and exit */
197. vi -x [filename]
/* Encrypt a file with vi editor */
Setting Term Options
198. stty erase ^?
/* Set the delete key to delete a character */
199. stty erase ^H
/* Set the backspace to delete a character */
200. stty sane
/* Reset terminal after viewing a binary file. */
201. tput rmacs
/* Reset to standard char set */
Snoop
202. snoop -d pcelx0
/* Watch all the packets on a device */
203. snoop -i /tmp/mylog -o /tmp/newlog host1
/* Filter out all the host1 packets and write them to a new logfile */
204. snoop -i /tmp/mylog -v -p101
/* Show verbose info on packet number 101 in the logfile */
205. snoop -i /tmp/mylog host1 host2
/* View packets from a logfile between hosts1 and host2 */
206. snoop -o /tmp/mylog pcelx0
/* Save all the packets from a device to a logfile */
207. snoop -s 120
/* Return the first 120 bytes in the packet header */
208. snoop -v arp
/* Capture arp broadcasts on your network */
209. snoop port [port-number]
/* Monitor particular port for traffic */
Swap Files
210. mkfile -nv 10m /export/disk1/myswap
/* Makes an empty 10 Megabyte swapfile in /export/disk */
211. mkfile -v 10m /export/disk1/myswap
/* Makes a 10 Megabyte swapfile in /export/disk */
Swap Space
212. swap -a /export/disk1/swapfile
/* Add a swap file */
213. swap -d /dev/dsk/c0t0d0s4
/* Delete a swap device */
214. swap -l
/* List the current swap devices */
215. swap -s
/* List the amount of swap space available */
System Configuration
216. /usr/sbin/eeprom auto-boot? false
/* Changes eeprom autoboot? setting without going to Ok prompt */
217. /usr/sbin/eeprom diag-switch? true
/* Set the system to perform diagnostics on the next reboot. */
218. /usr/sbin/eeprom local-mac-address?=true
/* Multiple Port Network Card Setting */
219. /usr/sbin/grpck
/* Check /etc/group file syntax */
220. /usr/sbin/pwck
/* Check /etc/passwd file syntax */
221. /usr/sbin/sys-unconfig
/* Clear host specific network configuration information */
222. /usr/sbin/useradd
/* Add a new user to the system */
223. drvconfig ; disks
/* Adding hot-plug disks to system */
System Information/Monitoring
224. /bin/echo "0t${stamp}>Y\n<Y=Y" | adb
/* Convert UNIX timestamp to something human-readable */
225. /usr/sbin/eeprom
/* Show eeprom parameters */
226. /usr/sbin/prtconf -vp
/* Show system configuration details */
227. coreadm -e log
/* Report global core */
228. grep "\-root" /var/adm/sulog | grep -v \+ | tail -25
/* List most recent attempts to switch to superuser account. */
229. isainfo -bv
/* Quickly checkout if machine is in 32 or 64 bit mode */
230. last
/* Tells who was or still is on the system */
231. logger -i
/* Log the process ID */
232. prtconf -pv | grep banner-name |awk -F\' ' { print $2 } ' | head -1
/* Show actual model name of machine */
233. prtconf -vp | grep bootpath
/* Determine which root disk you are booted from. */
234. prtdiag -v
/* System Diagnostics */
235. prtpicl -v | grep wwn
/* A command to find persistent binding of storage */
236. psradm -f [processor id]
/* Take processor offline */
237. psrinfo | wc -l
/* Display number of processors */
238. sar -u
/* Report CPU Utilization */
239. sar [ -aA ] [ -o filename ] t [ n ]
/* Provides cumulative reports about system activity. */
240. showrev -p
/* Show a list of patches installed */
241. telnet <remote machine> 13 | grep ':'
/* Get the time on remote Unix machine */
242. uname -a
/* Displays system information */
243. uname -X
/* Displays system information */
244. vmstat 10
/* Displays summary of what the system is doing every 10 seconds */
245. who -b
/* Displays the date of the last system reboot. */
246. ypcat hosts | sort -n -t. +0 -1 +1 -2 +2 -3 +3 -4
/* Take the input of "ypcat hosts" or "cat /etc/inet/hosts" and sort by IP. */

[Nov 30, 2007] freshmeat.net Project details for Expect-lite

About:
Expect-lite is a wrapper for expect, created to make expect programming even easier. The wrapper permits the creation of expect script command files by using special character(s) at the beginning of each line to indicate the expect-lite action. Basic expect-lite scripts can be created by simply cutting and pasting text from a terminal window into a script, and adding '>' '

Release focus: Major feature enhancements

Changes:
The entire command script read subsystem has changed. The previous system read directly from the script file. The new system reads the script file into a buffer, which can be randomly accessed. This permits looping (realistically only repeat loops). Infinite loop protection has been added. Variable increment and decrement have been added to support looping.

Author:
Craig Miller [contact developer]

[Nov 15, 2006] Miscellaneous Solaris notes -- many interesting and unique tips.

A couple of old utilities

scsiinfo' extracts formatting and other parameters from SCSI hard disk drives that aren't listed in /etc/format.dat and can optionally create entries to be added to your system's format.dat file.. Might be useful for old boxes.
$Id: ANNOUNCEMENT,v 1.24 2001/07/16 16:03:14 jdd Exp $

Version 4.7 of scsiinfo is now available.

New in release 4.7:
	o support for Sun's PLN fibre-channel SCSI host adapter.
        o support for Sun's simple SCSI target (sst) driver.
        o -O support (Solaris 2.x) to check for devices already open.
        o autodetection of host adapter include files.
	o Solaris 8 support.

For those unfamiliar with scsiinfo:

Scsiinfo displays information about SCSI devices attached to a given system,
as seen by a supported SCSI device driver.  For each target known to the SCSI
host adapter, scsiinfo reports SCSI transfer information for the device.  In
particular, when a target supports synchronous transfer, the negotiated
maximum transfer rate (in MB/sec) is reported.  Scsiinfo can also report the
type and speed of each supported host adapter attached to the system.  In
addition, it supports querying SCSI disks for geometry and formatting and
optionally generates a format.dat entry based on these values.  Finally,
scsiinfo supports querying SCSI devices for vendor, product, and revision
information, in the style of the Sun OpenBoot prom's probe-scsi and
probe-scsi-all commands.

Only suns with esp, isp, fas, ptisp and glm SCSI controllers
(sun4c/4m/4e/4d/4u) running SunOS 4.1 or later are supported.  The isp, fas
and glm controllers are only supported under SunOS 5.x.

Scsiinfo version 4.7 is available for anonymous ftp from:
	ftp://ftp.cs.toronto.edu/pub/jdd/scsiinfo/scsiinfo-4.7.shar

memconf - memory configuration utility for Sun SparcStations.

memconf' is a Perl script which determines the configuration of the RAM modules in Sun workstations. It uses the SunOS 5.x 'prtconf' and 'prtdiag' utilities extract relevent information and present it in more user-friendly format.

[Jun 5, 2006] open.itworld.com - Using stty to Your Advantage Note that in .progile you should use if statement to determine which erase symbol to use

The most commonly used stty command is undoubtedly the "stty erase ^h" command which is often used in scripts
if [ `tty | grep -ci console` -eq 0 ]
then
	stty ERASE ^H
	TERM=SUN
fi

[Jun 5, 2006] Sys Admin Cool Commands

truss -c (Solaris >= 8): This astounding option to truss provides a profile summary of the command being trussed:

$ truss -c grep asdf work.doc
syscall              seconds   calls  errors
_exit                    .00       1
read                     .01      24
open                     .00       8      4
close                    .00       5
brk                      .00      15
stat                     .00       1
fstat                    .00       4
execve                   .00       1
mmap                     .00      10
munmap                   .01       3
memcntl                  .00       2
llseek                   .00       1
open64                   .00       1
                        ----     ---    ---
sys totals:              .02      76      4
usr time:                .00
elapsed:                 .05

It can also show profile data on a running process. In this case, the data shows what the process did between when truss was started and when truss execution was terminated with a control-c. It’s ideal for determining why a process is hung without having to wade through the pages of truss output.

truss -d and truss -D (Solaris >= 8): These truss options show the time associated with each system call being shown by truss and is excellent for finding performance problems in custom or commercial code. For example:

$ truss -d who
Base time stamp:  1035385727.3460  [ Wed Oct 23 11:08:47 EDT 2002 ]
 0.0000 execve(“/usr/bin/who”, 0xFFBEFD5C, 0xFFBEFD64)  argc = 1
 0.0032 stat(“/usr/bin/who”, 0xFFBEFA98)                = 0
 0.0037 open(“/var/ld/ld.config”, O_RDONLY)             Err#2 ENOENT
 0.0042 open(“/usr/local/lib/libc.so.1”, O_RDONLY)      Err#2 ENOENT
 0.0047 open(“/usr/lib/libc.so.1”, O_RDONLY)            = 3
 0.0051 fstat(3, 0xFFBEF42C)                            = 0
. . .

truss -D is even more useful, showing the time delta between system calls:

Dilbert> truss -D who
 0.0000 execve(“/usr/bin/who”, 0xFFBEFD5C, 0xFFBEFD64)  argc = 1
 0.0028 stat(“/usr/bin/who”, 0xFFBEFA98)                = 0
 0.0005 open(“/var/ld/ld.config”, O_RDONLY)             Err#2 ENOENT
 0.0006 open(“/usr/local/lib/libc.so.1”, O_RDONLY)      Err#2 ENOENT
 0.0005 open(“/usr/lib/libc.so.1”, O_RDONLY)            = 3
 0.0004 fstat(3, 0xFFBEF42C)                            = 0

In this example, the stat system call took a lot longer than the others.

truss -T: This is a great debugging help. It will stop a process at the execution of a specified system call. (“-U” does the same, but with user-level function calls.) A core could then be taken for further analysis, or any of the /proc tools could be used to determine many aspects of the status of the process.

truss -l (improved in Solaris 9): Shows the thread number of each call in a multi-threaded processes. Solaris 9 truss -l finally makes it possible to watch the execution of a multi-threaded application.

Truss is truly a powerful tool. It can be used on core files to analyze what caused the problem, for example. It can also show details on user-level library calls (either system libraries or programmer libraries) via the “-u” option.

pkg-get: This is a nice tool (http://www.bolthole.com/solaris) for automatically getting freeware packages. It is configured via /etc/pkg-get.conf. Once it’s up and running, execute pkg-get -a to get a list of available packages, and pkg-get -i to get and install a given package.

plimit (Solaris >= 8): This command displays and sets the per-process limits on a running process. This is handy if a long-running process is running up against a limit (for example, number of open files). Rather than using limit and restarting the command, plimit can modify the running process.

coreadm (Solaris >= 8): In the “old” days (before coreadm), core dumps were placed in the process’s working directory. Core files would also overwrite each other. All this and more has been addressed by coreadm, a tool to manage core file creation. With it, you can specify whether to save cores, where cores should be stored, how many versions should be retained, and more. Settings can be retained between reboots by coreadm modifying /etc/coreadm.conf.

pgrep (Solaris >= 8): pgrep searches through /proc for processes matching the given criteria, and returns their process-ids. A great option is “-n”, which returns the newest process that matches.

preap (Solaris >= 9): Reaps zombie processes. Any processes stuck in the “z” state (as shown by ps), can be removed from the system with this command.

pargs (Solaris >= 9): Shows the arguments and environment variables of a process.

nohup -p (Solaris >= 9): The nohup command can be used to start a process, so that if the shell that started the process closes (i.e., the process gets a “SIGHUP” signal), the process will keep running. This is useful for backgrounding a task that should continue running no matter what happens around it. But what happens if you start a process and later want to HUP-proof it? With Solaris 9, nohup -p takes a process-id and causes SIGHUP to be ignored.

prstat (Solaris >= 8): prstat is top and a lot more. Both commands provide a screen’s worth of process and other information and update it frequently, for a nice window on system performance. prstat has much better accuracy than top. It also has some nice options. “-a” shows process and user information concurrently (sorted by CPU hog, by default). “-c” causes it to act like vmstat (new reports printed below old ones). “-C” shows processes in a processor set. “-j” shows processes in a “project”. “-L” shows per-thread information as well as per-process. “-m” and “-v” show quite a bit of per-process performance detail (including pages, traps, lock wait, and CPU wait). The output data can also be sorted by resident-set (real memory) size, virtual memory size, execute time, and so on. prstat is very useful on systems without top, and should probably be used instead of top because of its accuracy (and some sites care that it is a supported program).

trapstat (Solaris >= 9): trapstat joins lockstat and kstat as the most inscrutable commands on Solaris. Each shows gory details about the innards of the running operating system. Each is indispensable in solving strange happenings on a Solaris system. Best of all, their output is good to send along with bug reports, but further study can reveal useful information for general use as well.

vmstat -p (Solaris >= 8): Until this option became available, it was almost impossible (see the “se toolkit”) to determine what kind of memory demand was causing a system to page. vmstat -p is key because it not only shows whether your system is under memory stress (via the “sr” column), it also shows whether that stress is from application code, application data, or I/O. “-p” can really help pinpoint the cause of any mysterious memory issues on Solaris.

pmap -x (Solaris >= 8, bugs fixed in Solaris >= 9): If the process with memory problems is known, and more details on its memory use are needed, check out pmap -x. The target process-id has its memory map fully explained, as in:

# pmap -x 1779
1779:   -ksh
 Address  Kbytes     RSS    Anon  Locked Mode   Mapped File
00010000     192     192       -       - r-x--  ksh
00040000       8       8       8       - rwx--  ksh
00042000      32      32       8       - rwx--    [ heap ]
FF180000     680     664       -       - r-x--  libc.so.1
FF23A000      24      24       -       - rwx--  libc.so.1
FF240000       8       8       -       - rwx--  libc.so.1
FF280000     568     472       -       - r-x--  libnsl.so.1
FF31E000      32      32       -       - rwx--  libnsl.so.1
FF326000      32      24       -       - rwx--  libnsl.so.1
FF340000      16      16       -       - r-x--  libc_psr.so.1
FF350000      16      16       -       - r-x--  libmp.so.2
FF364000       8       8       -       - rwx--  libmp.so.2
FF380000      40      40       -       - r-x--  libsocket.so.1
FF39A000       8       8       -       - rwx--  libsocket.so.1
FF3A0000       8       8       -       - r-x--  libdl.so.1
FF3B0000       8       8       8       - rwx--    [ anon ]
FF3C0000     152     152       -       - r-x--  ld.so.1
FF3F6000       8       8       8       - rwx--  ld.so.1
FFBFE000       8       8       8       - rw---    [ stack ]
-------- ------- ------- ------- -------
total Kb    1848    1728      40       -

Here we see each chunk of memory, what it is being used for, how much space it is taking (virtual and real), and mode information.

df -h (Solaris >= 9): This command is popular on Linux, and just made its way into Solaris. df -h displays summary information about file systems in human-readable form:

$ df -h
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0t0d0s0      4.8G   1.7G   3.0G    37%    /
/proc                    0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
fd                       0K     0K     0K     0%    /dev/fd
swap                   848M    40K   848M     1%    /var/run
swap                   849M   1.0M   848M     1%    /tmp
/dev/dsk/c0t0d0s7       13G    78K    13G     1%    /export/home

piostat.pl

#!/local/unix/bin/perl # #Reads the output of iostat(1), with args -xnp, and plots the data for # the UFS partitions on the local box. The partitions are obtained w/ a # simple df. The swap partition is grok'd from /etc/ ...
http://www.sun.com/bigadmin/scripts/submittedScripts/piostat.pl.txt - October 5, 2004

Keep commands running after you leave with nohup

It's 3 p.m., and you want to start a long job running. Unfortunately, you can't be sure that the job will finish by 5 p.m. when you need to leave, and the company is very strict about making sure you log off when you leave. However, if you log off the system, the job will be stopped. What can you do?

On Solaris systems you can use the "nohup" (no hang-up) command to keep jobs running long after you log off the system. Using nohup tells the system not to "hang-up" on your job after you've logged off the system.

Here's how to run the job, and keep it running after you log off:

root> nohup my-long-job &

This creates a file named "nohup.out" in the current directory that contains the standard output of the command ("my-long-job") you're running. Everyone is happy because the job keeps running, you get to leave at 5 p.m., and you're properly logged off the system.

[Dec 25, 2005] Sun Solaris Tips An excellent collection of tips !!!

Use CDPATH to traverse filesystems faster

If you're like many Solaris users and administrators, you spend a lot of time moving back and forth between directories in similar locations. For instance, you might often work in your home directory (such as "/home/al"), the /usr/local directories, web page directories, or other user's home directories in /home.

If you're often moving back-and-forth between the same directories, and you use the Bourne shell (sh) or Korn shell (ksh) as your login shell, you can use the CDPATH shell variable to save yourself a lot of typing, and quickly move between directories.

Here's a quick demo. First move to the root directory:

cd /

Next, if it's not set already, set your CDPATH shell variable as follows:

CDPATH=/usr/spool

Then, type this cd command:

cd cron

What happens? Type this and see what happened:

pwd

The result should be "/usr/spool/cron".

When you typed "cd cron", the shell looked in your local directory for a sub-directory named "cron". When it didn't find one, it searched the CDPATH variable, and looked for a "cron" sub-directory. When it found a sub-directory named cron in the /usr/spool directory, it moved you there.

You can set your CDPATH variable just like your normal PATH variable:

CDPATH=/home/al:/usr/local:/usr/spool:/home

Group commands together with parentheses

Have you ever needed to run a series of commands, and pipe the output of all of those commands into yet another command?

For instance, what if you wanted to run the "sar", "date", "who", and "ps -ef" commands, and wanted to pipe the output of all three of those commands
into the "more" command? If you tried this:

sar -u 1 5; date; who; ps -ef | more

you'll quickly find that it won't work. Only the output of the "ps -ef" command gets piped through the "more" command, and the rest of the output
scrolls off the screen.

Instead, group the commands together with a pair of parentheses (and throw in a few echo statements for readability) to get the output of all these
commands to pipe into the more command:

(sar -u 1 5; echo; who; echo; ps -ef; echo; date; echo) | more

Use the "at" command to run jobs some other time

Many times it's necessary to schedule programs to run at a later time. For instance, if your computer system is very busy during the day, you may need
to run jobs late at night when nobody is logged on the system.

Solaris makes this very easy with the "at" command. You can use the "at" command to run a job at almost any time--later today, early tomorrow...whenever.

Suppose you want to run the program "my_2_hour_program" at ten o'clock tonight. Simply tell the at command to run the job at 10 p.m. (2200):

/home/al> at 2200
at> my_2_hour_program > /tmp/2hour.out
at> <CTRL><D>
warning: commands will be executed using /bin/ksh
job 890193600.a at Tue Mar 17 22:00:00 1998

Or suppose you'd like to run a find command at five o'clock tomorrow morning:

/home/al> at 0500 tomorrow
at> find /home > /tmp/find.out
at> <CTRL><D>
warning: commands will be executed using /bin/ksh
job 890215200.a at Wed Mar 18 05:00:00 1998

When you're at the "at" prompt, just type the command you want to run. Try a few tests with the at command until you become comfortable with the way
it works.

Add spice to interactive shell programs with tput

When you're writing interactive shell programs, you often want to add a little more spice to your user interface - those special nuances that make
your application more appealing. The Solaris "tput" command can be used to enhance your user interface.

Here's a couple of quick tput commands that can spice up your user interface:

The tput command can be used to make text appear bold on terminals that support a bold appearance. Making text appear bold works very well for
titles, or at times when you want a word or phrase to stand out from the rest of the text. Try these three commands at your command line to make
the "[Enter]" portion of the following echo statement output appear bold:

bold=`tput smso`
norm=`tput rmso`
echo "Hit the ${bold}[Enter]${norm} key to continue: \c"

You can also position the cursor on-screen with the tput command. Type this command at the command line to see what happens:

tput cup 10 40

I once wrote a crude interactive screen editor using tput cup to properly position the cursor when the user hit the various arrow keys.

Create a directory and move into it at the same time

Question: How often do you create a new directory and then move into that directory in your next command? Answer: Almost always.

I realized this trend in my own work habits, so I created a simple shell function to do the hard work for me.

md () {
mkdir -p $1 && cd $1
}

This is a Bourne shell function named "md" that works for Bourne and Korn shell users. It can be easily adapted for C shell users.

Taking advantage of the -p option of the mkdir command, the function easily creates multi-level subdirectories, and moves you into the lowest level of the directory structure. You can use the command to create one subdirectory like this:

/home/al> md docs
/home/al/docs> _

or you can create an entire directory tree and move right into the new directory like this:

/home/al> md docs/memos/internal/solaris8
/home/al/docs/memos/internal/solaris8>

Easily convert man pages to text documents

Have you ever wanted to convert a man page into a plain text document?
I do this occasionally when I want to share information via an email or other document format.

I used to think this was difficult, but then I discovered a simple way to do it. Here's the wrong way to write the man page for the ls command into a text file named ls.bad:

man ls > ls.bad

This keeps all of the formatting characters in your document, which is generally not what you want. Here's a better way that eliminates those formatting characters:

man ls | col -b > man.txt

The col command with the -b option removes the undesirable backspace characters from the text stream, so the only thing left in your document is the text you want, in the format you want.

How to page more than one command at a time

Have you ever wanted to group a bunch of commands into a paging program like "page" or "more", but didn't know how?

As a system administrator, I always worry about certain things, like who's doing what, what processes are running, what the network traffic looks like, etc. One day I decided to create a simple alias that would combine all the commands I wanted into one big chunk of information. Then I realized that it wouldn't all fit into one screen.
Fortunately I knew how to group all of the commands together, so the "more" command could handle them as one set of input.

First, here's the wrong way to try to page a sequence of four commands:

date; netstat -i; whodo; ps -ef | more

The only command that gets paged properly here is the "ps -ef" command
--the rest of them scroll off the screen before you can read them.

Here's the correct way to page four commands so they're all controlled
by "more":

(date; netstat -i; whodo; ps -ef) | more

Once you find the commands you want to group together, you can combine them into an alias or shell program. I recommend a shell program for this, because a few "echo" statements sure make it easier to see where one command ends and the next command begins!

Initializing log files

Like all Unix file systems, open log files can cause a real problem when they get too large and need to be deleted. The problem is, if you delete an open file, the link is removed, but all of the inodes are lost. Even worse, if the program continues to log to the file, the link never re-appears, and additional inodes are lost and are unrecoverable. I suggest two solutions to the above problems.

If you have lost inodes, a simple reboot (make sure FSCK is run on startup) will recover lost inodes and missing filespace.

To empty (or zero out) an open log file, simply issue the following command:

date > logfile

This will 'empty' the file and insert as the first line the output from the date command. If you want a completely empty file, don't enter date,

just > logfile.

This works great on apache and other web server logs, without ever stopping the service.

Don't forget the options that make ls work better for you

Generally speaking, most users type ls or ls -al to see their directory listings. But don't forget that there are a few other cool options that make it easier to read your directory listings.

The -aCF options are my next-favorite listing combination. The following command:

ls -aCF

lists (a) all files in columns with special characters appended to the end of each name to show whether the file is a normal file, directory, executable file, or link.

The -m option lets you list files in a comma-separated list, which can be useful if you're going to be exporting the list to a Perl program or shell script.

To sort the listing by file size, try

ls -al | sort -4n

To reverse the filesize listing, use

ls -al | sort -4nr

instead.

Using the which command

I think a good command in addition to the 'type' is the 'which' command. You can really see where the executable come from. This is very helpful to find out if there is an alias set to the command and if so - which one.

Example: # type ls
ls is a tracked alias for /usr/bin/ls
# which ls
ls: aliased to ls -aF

Sun Solaris Tips

Add spice to interactive shell programs with tput

When you're writing interactive shell programs, you often want to add a little more spice to your user interface - those special nuances that make
your application more appealing. The Solaris "tput" command can be used to enhance your user interface.

Here's a couple of quick tput commands that can spice up your user interface:

The tput command can be used to make text appear bold on terminals that support a bold appearance. Making text appear bold works very well for
titles, or at times when you want a word or phrase to stand out from the rest of the text. Try these three commands at your command line to make
the "[Enter]" portion of the following echo statement output appear bold:

bold=`tput smso`
norm=`tput rmso`
echo "Hit the ${bold}[Enter]${norm} key to continue: \c"

You can also position the cursor on-screen with the tput command. Type this command at the command line to see what happens:

tput cup 10 40

I once wrote a crude interactive screen editor using tput cup to properly position the cursor when the user hit the various arrow keys.

[Jan 17, 2005] Updating OpenBoot PROM for Sun Workstations and Workgroup Servers Based on SPARC Technology

Having the latest version of OpenBoot PROM (OBP) on a SPARC processor-based workstation or workgroup server can be critical when adding new applications or hardware, or when upgrading the machine's Solaris Operating System (OS). Updating may also save some time and difficulty by resolving any latent bugs that have been detected and fixed since the previous releases. The paragraphs that follow guide you through the steps required to do the update.

Note: This Tech Tip does not cover larger servers; for those systems, see SunSolve document #41723 entitled Updating the Sun Fire 3800-6800 series Flash Proms.

Phil's Solaris hints

VMware's back

New Bigadmin community submissions:

Sys Admin Cool Commands

There are so many commands in Solaris that it is difficult to separate the cool ones from the mundane. For example, there are commands to report how much time a program spends in each system call, and commands to dynamically show system activities, and most of these commands are included with Solaris 8 as well as Solaris 9. This month, I’m highlighting some of the commands that you might find particularly useful.

Systems administrators are tool users. Through experience, we have learned that the more tools we have, the better able we are to diagnose problems and implement solutions. The commands included in this column are gleaned from experience, friends, acquaintances, and from attendance at the SunNetwork 2002 conference in September. “The /procodile Hunter” talk by Solaris kernel developers Brian Cantrill and Mike Shapiro was especially enlightening and frightening because Cantrill wrote code to illustrate a point faster than Shapiro could explain the point they were trying to illustrate!

Useful Solaris Commands

truss -c (Solaris >= 8): This astounding option to truss provides a profile summary of the command being trussed:

$ truss -c grep asdf work.doc
syscall              seconds   calls  errors
_exit                    .00       1
read                     .01      24
open                     .00       8      4
close                    .00       5
brk                      .00      15
stat                     .00       1
fstat                    .00       4
execve                   .00       1
mmap                     .00      10
munmap                   .01       3
memcntl                  .00       2
llseek                   .00       1
open64                   .00       1
                        ----     ---    ---
sys totals:              .02      76      4
usr time:                .00
elapsed:                 .05 

It can also show profile data on a running process. In this case, the data shows what the process did between when truss was started and when truss execution was terminated with a control-c. It’s ideal for determining why a process is hung without having to wade through the pages of truss output.

truss -d and truss -D (Solaris >= 8): These truss options show the time associated with each system call being shown by truss and is excellent for finding performance problems in custom or commercial code. For example:

$ truss -d who
Base time stamp:  1035385727.3460  [ Wed Oct 23 11:08:47 EDT 2002 ]
 0.0000 execve(“/usr/bin/who”, 0xFFBEFD5C, 0xFFBEFD64)  argc = 1
 0.0032 stat(“/usr/bin/who”, 0xFFBEFA98)                = 0
 0.0037 open(“/var/ld/ld.config”, O_RDONLY)             Err#2 ENOENT
 0.0042 open(“/usr/local/lib/libc.so.1”, O_RDONLY)      Err#2 ENOENT
 0.0047 open(“/usr/lib/libc.so.1”, O_RDONLY)            = 3
 0.0051 fstat(3, 0xFFBEF42C)                            = 0
. . .

truss -D is even more useful, showing the time delta between system calls:

Dilbert> truss -D who
 0.0000 execve(“/usr/bin/who”, 0xFFBEFD5C, 0xFFBEFD64)  argc = 1
 0.0028 stat(“/usr/bin/who”, 0xFFBEFA98)                = 0
 0.0005 open(“/var/ld/ld.config”, O_RDONLY)             Err#2 ENOENT
 0.0006 open(“/usr/local/lib/libc.so.1”, O_RDONLY)      Err#2 ENOENT
 0.0005 open(“/usr/lib/libc.so.1”, O_RDONLY)            = 3
 0.0004 fstat(3, 0xFFBEF42C)                            = 0

In this example, the stat system call took a lot longer than the others.

truss -T: This is a great debugging help. It will stop a process at the execution of a specified system call. (“-U” does the same, but with user-level function calls.) A core could then be taken for further analysis, or any of the /proc tools could be used to determine many aspects of the status of the process.

truss -l (improved in Solaris 9): Shows the thread number of each call in a multi-threaded processes. Solaris 9 truss -l finally makes it possible to watch the execution of a multi-threaded application.

Truss is truly a powerful tool. It can be used on core files to analyze what caused the problem, for example. It can also show details on user-level library calls (either system libraries or programmer libraries) via the “-u” option.

Solaris Tips and Tricks

Boot

Where has the XXX command gone now?

There are too many of these changes to include in this FAQ, but here are some key ones:

a. locations are often different

Note that the last two commands are back in /usr/bin in Solaris 2.5.

b. some old commands don't exist or have replacements

This information can be found in the Solaris 2.x Transition Guide - Appendix A (commands), Appendix B (system calls), Appendix C (files).

This guide has undergone some changes from 2.0 -> 2.1 and beyond. Several manuals have ended up being combined into this single manual. This manual discusses administrative transition and developer transition issues.

The command "whatnow" (for Solaris 2.x) is included in the "Admigration Toolkit" package (see below). The Admigration toolkit can be obtained from:

Admigration toolkit

Sample output:

	% whatnow hostname
	hostname                                        4.x command only
	hostname        /usr/ucb/hostname               part of SCP package
	hostname        /usr/bin/uname -n               alternate command

The whatnow command is limited in that it may point to one command which may only implement a subset of the old command (e.g., pstat points to sar, while pstat -s is identical to swap -s)

Description
The default login shell for the Solaris superuser root is /sbin/sh, a statically linked Bourne shell. This shell is not dependent on any other files to run. The usual user shells like /usr/bin/ksh are dynamically linked and are dependent on library files. If the root login shell is changed from /sbin/sh to a non-static shell, root will not be able to log into the system if certain filesystems cannot mount. A simple addition to root's /.profile will change the shell safely.
Directions
To change the root shell to Korn shell at login if the file /usr/bin/ksh exists, add the following lines to the end of the root user's profile (usually /.profile):

if [ -x /usr/bin/ksh ]; then
SHELL=/usr/bin/ksh
export SHELL
exec /usr/bin/ksh
else
echo /usr/bin/ksh not found using default shell of $SHELL
fi

Make certain that the login shell for root in /etc/passwd is /sbin/sh.

Core files creation blocking in Solaris

Description
Core files provide debugging information about a process that has terminated unexpectedly. Unless you are developing an application, core files are typically of little use and can cause serious problems by filling up filesystems. This recipe describes configuring Solaris to turn off core file creation for processes.

The coreadm command controls the generation of core files. To determine the current coreadm settings, run coreadm as root. Output such as the following will be generated: global core file pattern:
init core file pattern: core
global core dumps: disabled
per-process core dumps: enabled
global setid core dumps: disabled
per-process setid core dumps: disabled
global core dump logging: disabled


Given the sample configuration above, per-process core dumps are enabled. When a process terminates abnormally or receives an appropriate signal, it will generate a core file named 'core' in the working directory of the process.

To disable per-process core file creation, use:

coreadm -d process


This will modify the /etc/coreadm.conf which is read at boot when /etc/init.d/coreadm is executed from a runtime control script. To make permanent changes to coreadm, do not edit the /etc/coreadm.conf file, use the coreadm command.

 

New Options in Solaris 10 daemons

New Options in Solaris 10 FTPD

docs.sun.com man pages section 1M System Administration Commands

New options in Solaris 10 TELNETD

isainfo command

The isainfo command can be used to determine if a Solaris system has been configured to run in 32 or 64 bit mode. Run the command
isainfo -v
If the system is running in 32 bit mode, you will see the following output: "32-bit sparc applications". On a 64 bit Solaris system, you'll see:
64-bit sparcv9 applications
32-bit sparc applications

psrinfo to view the processor info on a system running Solaris, the following command can be used

How to reject remote logging in syslogd

syslogd -t will turn on sysloging but it will not receive remote logging from other devices.

Best way to enable is to go to /etc/init.d/syslog and edit the script. Go to line
/usr/sbin/syslogd >/dev/msglog 2>&1 &

and edit it with the -t option to look like:

/usr/sbin/syslogd -t >/dev/msglog 2>&1 &

The start syslogd again and verify with a ps -ef | grep

Tech-Recipes.com - creating a solaris 8 flash archive boot disk

creating a solaris 8 flash archive boot disk
Home -> UNIX -> Solaris -> System administration
3794 views
From the computer of: weezlboy (1 recipe)
created: 2004-05-27 10:53:27 last updated: 2004-05-28 09:15:02
1 comments: View all comments Add a comment
Description
creating a Solaris 8 flash archive boot disk with Schily's mkisofs

Directions
#! /bin/csh
# script asumptions:
# the /opt/make_os directory is present.
# the flash archive s8.archive is in the /opt/make_os directory
# the file profind is located in /opt/make_os
# the mkisofs is located in /opt/schily/bin
# the Solaris 8 Software 1 of 2 disk


cd /opt/make_os
# make the solaris_8 directory to assemble the image in
mkdir solaris_8
# pull off the s0 directory from the cd
cd /cdrom/cdrom0/
find s0 -print | cpio -pudm /opt/make_os/solaris_8
cd /opt/make_os/solaris_8
# dump the rest of the info from the cd
/etc/init.d/volmgt stop
sleep 10
foreach i (1 2 3 4 5)
dd if=/dev/dsk/c0t2d0s$i of=s8u5.s$i bs=512
end
/etc/init.d/volmgt start
sleep 10
# remove the packages from the Product directory
cd /opt/make_os/solaris_8/s0/Solaris_8/Product
rm -rf *
# copy the s8.archive file into the Product directory
cp /opt/make_os/s8.archive /opt/make_os/solaris_8/s0/Solaris_8/Product
# remove the configuration files from the .install_config directory
cd /opt/make_os/solaris_8/s0/.install_config
rm *

# create the s8.profile in the .install_config directory

echo "install_type flash_install" > s8.profile
echo "archive_location local_file /cdrom/Solaris_8/Product/s8.archive" >> s8.profile
echo "partitioning explicit" >> s8.profile
echo " " >> s8.profile
echo "filesys rootdisk.s0 free /" >> s8.profile
echo "filesys rootdisk.s1 1:1450 swap" >> s8.profile
echo "filesys rootdisk.s7 1451:4 unnamed" >> s8.profile

chmod 644 s8.profile

# run check on the rules file to create the rules.ok file
# copy the rules.ok to the .install_config directory

# rules file looks like
echo "any - - s8.profile -" > rules
chmod 644 rules

/cdrom/cdrom0/s0/Solaris_8/Misc/jumpstart_sample/check
rm rules
#cd /opt/make_os/solaris_8/s0/Solaris_8/Tools/Boot/usr/sbin/install.d
# edit the profind file and modify cdrom() to look like

#cdrom()
#{
# Factory JumpStart is only allowed with factory
# stub images, indicated by the file /tmp/.preinstall
#
# if [ -f /tmp/.preinstall ]; then
# mount -o ro -F lofs ${CD_CONFIG_DIR} ${SI_CONFIG_DIR} >/dev/null 2>&1

# if [ $? -eq 0 ]; then
# verify_config "defaults" "CDROM"
# fi
# fi

# gettext " <<< using CDROM install_config >>>"; echo #new
# rmdir ${SI_CONFIG_DIR} #new
# ln -s /cdrom/.install_config ${SI_CONFIG_DIR} #new
#}

# copy the profind file from the /opt/make_os directory
cp -p /opt/make_os/profind /opt/make_os/solaris_8/s0/Solaris_8/Tools/Boot/usr/sbin/install.d

# now edit the sysidcfg on slice 1

lofiadm -a /opt/make_os/solaris_8/s8u5.s1
mount /dev/lofi/1 /mnt
rm /mnt/etc/sysidcfg
cd /mnt/etc
# create a new sysidcfg

echo "system_locale=en_US" > sysidcfg
echo "timezone=US/Pacific" >> sysidcfg
echo "network_interface=primary {hostname=YOUR HOSTNAME" >> sysidcfg
echo " ip_address=YOUR HOST'S IP" >> sysidcfg
echo " netmask=255.255.255.0" >> sysidcfg
echo " protocol_ipv6=no}" >> sysidcfg
echo "terminal=vt100" >> sysidcfg
echo "security_policy=NONE" >> sysidcfg
echo "root_password=PASSWORD FROM SHADOW FILE" >> sysidcfg
echo "name_service=NONE" >> sysidcfg
echo "timeserver=localhost" >> sysidcfg

chmod 777 sysidcfg

#
cd /opt/make_os/solaris_8
umount /mnt
lofiadm -d /dev/lofi/1

# create the image using Schily's mkisofs
/opt/schily/bin/mkisofs -R -D -d -L -l -sparc-boot s8u5.s1,s8u5.s2,s8u5.s3,s8u5.s4,s8u5.s5 -o s8u5.image ./s0

# burn the cd
#cdrw -C -d cdrom0 -i /opt/make_os/solaris_8/s8u5.image

Hi.

Just a comment on this otherwise nice script. The delete lines such as:

# remove the packages from the Product directory
cd /opt/make_os/solaris_8/s0/Solaris_8/Product
rm -rf *

and

# remove the configuration files from the .install_config directory
cd /opt/make_os/solaris_8/s0/.install_config
rm *

are extremely dangerous. If for some reason the cd command fails (permission problems, missing directories etc), the next command will wipe the rootdisk clean (or at least every file in the directory the command is issued from and all directories below). A much better version would be to do the rm command directly on the directory:

rm -rf /opt/make_os/solaris_8/s0/Solaris_8/Product/*

In this case the rm command will fail if the directory doesn't exist, and no harm would be done. Another approach would be to test for the existence of the directory prior to issue the commands, and to exit with an error code if the check fails. 

Unix/Solaris: One-Liners

Source: http://www.kevlo.com/~ebs/unix_commands.txt

Listed here are a bunch of unix commands.

--> change file date stamp
touch -t 199906042020 filename

--> move partitions
ufsdump 0f - /dev/rdsk/c0t0s0s0 | (cd /home; ufsrestore xv -)

--> lay down file system with 1% minfree and inode density
newfs -m1 -i81920 /dev/rdsk/c0t0d0s0

--> check file system
fsck /dev/rdsk/c0t0d0s0

Q: starting sybase
login as sybase, run: ./install/RUN_SYBASE

Q: logging in as sybase sa
isql -U sa <password>

--> dump a partition and pipe to gzip. Watch > 2GB limit
ufsdump 0f - /home | gzip - >/tmp/home.dump.gz

--> rewind offline a tape
mt -f /dev/rmt/0 rewoffl

--> only allow 300MB for user /tmp access
swap - /tmp tmpfs - yes SIZE=300M

--> verbose interactive restore
ufsrestore -ivf /dev/rmt/1

--> remove a printer from a class
lpadmin -p level5-line1 -r level5-line

--> truss a command
truss --f --o /tmp/log.txt

--> [DB] feed a script into sybase
isql -Urfe_xfer -Uuser -Ppassword -isqlscript >>blah.txt

--> make a printer class
lpadmin -p level5-line1 -c level5-line

--> remove level2-line2 printer from printer class level2-line
lpadmin -p level2-line2 -r level2-line

--> add level2-line3 to printer class
lpadmin -c level2-line -p level2-line3

--> [DB] how to change your password in isql
sp_password password, password-new

--> move a directory
tar cf - ./games | (cd /tmp; tar xvBpf - )

--> [DB] run a sybase script, and dump to file
$ISQL -i$SCRIPTFILE -U$USER -D$DATABASE -P$PASS_ENC >> $SCRIPTLOGFILE

--> move a directory to another server
tar cf - ./games | rsh brucey cd /tmp\; tar xvBpf -

--> check for SUID SGID files
ncheck -F ufs -s /dev/dsk/c3t0d0s

-- remove core files
find / -name core -exec rm -f {} \; -o -fstype nfs -prune

--> rebuild man pages
catman -w -M man-page-directory or /usr/lib/makewhatis

--> vi command to show special characters
: set list

--> adding an account
useradd -u 120 -g dls -d /apps/dls -s /bin/ksh -c "comment" -m dls

--> create a mysql database
mysqladmin -uroot -ppassword create ebs

--> starting mysql database
/etc/rc.d/init.d/mysql.server start
/usr/local/bin/safe_mysqld

--> Invoke CPAN module install
perl -MCPAN -eshell

--> dump to zip
ufsdump 0f - /filesystem | /opt/local/gzip - > /tmp/dump.gz

--> shutdown mysql databse
/usr/local/bin/mysqladmin shutdown -ppassword
/etc/rc.d/init.d/mysql.server stop

--> test the loading of a module
PERL_DL_DEBUG=255 perl -e 'use CGI;'

--> shows open files
fuser -cu /

--> Writing a Daemon:
1. edit /etc/services
add service and port.
2. edit /etc/inetd.conf
add in: edwardd stream tcp nowait root /bin/sh /bin/sh /home/sextone/bin/SERVER.mine
3. kill -HUP inetd.conf

--> how to mount a file system
mount /dev/dsk/c3t0d0s4 /apps/data/easysoft/DEVT

--> look at sar log
sar -f /var/adm/sa/sa24

--> write file checksums and size
cksum filename

--> show storage array info
ssaadm display /dev/rdsk/c1t5d2s0
--> show all disks on device d
luxadm display d

--> examine for a specific OS finerprint
nmap -sS -p 80 -O -v <host> = examine OS

--> show print jobs
/usr/ucb/lpq -Plevel6

--> Scan for known ports. log it. do OS scan.
nmap -sS -F -o foo.log -v -O www.foo.com//24 =

--> show status of printer
/usr/ucb/lpc status

--> make a swap file:
dd if=/dev/zero of=swapfile bs=1024 count=65535
mkswap ./swapfile
chmod 600 ./swapfile
swapon ./swapfile

--> show open files for process
lsof -p PID

--> show open files for all TCP connections
lsof -iTCP

--> show open files for internet address
lsof -iTCP@10.20.2.9

--> as above
lsof -i @10.20.2.122

--> examine tcp ports
lsof -iTCP@sarah:1-50000

--> show open files for user.
lsof -u username

--> show processes that has the file in use.
lsof /apps/cms/ECMS-Server

--> show open files and retry every 5 seconds
lsof -p process-id -r 5

--> mount a floppy
mount -t vfat /dev/fd0 /mnt/floppy

--> check here for debugging processes and errno.h for errors
/usr/include
/usr/include/sys
/usr/include/sys/errno.h

--> scp a whole directory, preserve mods
sudo scp -prv devel webadmin@203.19.123.140:/home/httpd/cgi-bin

--> take processor 2 and 3 offline.
psradm -f 2 3
--> show processor stats verbose.
psrinfo -v

--> how to skip grant tables in mysql (over ride security)
/usr/local/libexec/mysqld -Sg

--> how to feed in an SQL program
mysql <create_table.sql

--> rm all files in directories
find . -type f -exec rm {} \;

--> dump packets to a capture file
sudo snoop -o /tmp/tcp.txt cp

--> backup one liner
tar cvf - /home/ebs | gzip - > ebs.tar.gz

--> Look at selected packets in capture file
sudo snoop -i /tmp/tcp.txt

--> unzip and pipe to tar
gzip -dc <kmysql-1_1_6_tar.gz | tar xvf -

--> watch packets from two servers.
snoop sarah brucey

--> enable ip masquerading
/sbin/ipchains -P forward DENY
/sbin/ipchains -A forward -s 10.100.100.100/8 -j MASQ

-> view su log file
cat /var/adm/sulog

--> establish a default router or gateway.
echo "sagacity.com" > /etc/defaultrouter
echo "10.100.100.100 sagacity.com sagacity" >> /etc/hosts
change /etc/nsswitch.conf so that hosts has files, dns
edit resolv.conf put in
search .
nameserver 203.7.132.98

--> turn off automounter on /export/home.
vi /etc/auto_master, comment out /export/home

--> configuration file for sudoers
/opt/local/etc/sudoers

--> building ssh-1.2.27 on x86Solaris2.6 needed a few things:
/usr/openwin/bin in path
/usr/xpg4/bin in path
declare AR="/usr/xpg4/bin/ar"
declare NM_PATH="/usr/xpg4/bin/nm"

--> snoop network packets and get size and time stamp entries.
snoop -S -ta empa1

--> access perl CPAN
perl -MCPAN -e shell
install DBI

--> search for no password entries and lock all accounts.
for i in `passwd -sa | grep NP | awk ‘{print $1’`
do
echo "locking $i"
passwd -l $i
done

--> delete from a tar
tar --delete -f fs_backup_Sunday.tar home/ebs/tmp

--> Example on backing up files to tape. Must specify non rewinding, else you will over-write the files.
for file in `ls`
do
echo "sending $file to tape..."
echo `date`
tar cvpf /dev/rmt/0n $file
done

--> making/adding a partition.
1. use fdisk to make a parition.
2. mkfs -t ext2 -c /dev/hda11
3. mount -t ext2 /dev/hda11 /opt2
4. update /etc/fstab

--> rebuild the windex file
catman -w -M /usr/share/man

--> execute tar on remote host sarah and send tarball to standard output,
which becomes standard input for tar xvf - and the file gets dumped locally,
in this case on crawl. you have to cd to dir before tar or else you
will include path in tar
ssh maggie "cd $DIRNAME; tar cvf - $BASENAME" | (cd $TPATH; tar xvf - )

--> dump a remote filesystem and send it to local tape drive.
ssh --x $fw /usr/sbin/ufsdump 0cf - $fs | dd obs=63k of=$TAPE

--> encrypt filename 1 and output to 1.crypt file
crypt < 1 > 1.crypt ; rm 1

--> decrypt filename 1.crypt and stdout to screen
crypt < 1.crypt

--> send a file to tape
tar cvpf /dev/rmt/0 filename

--> quicker way to search and replace in vi
: %s/existing/new/g

--> shows where and which shared library files an application uses.
ldd binary

--> shell script stuff:
# repeat a command 100 times
x=100
while [ $x -gt 0 ]
do
command
x=$(($x-1))
done

--> Something very important to remember about partitions
It is important to note that Cylinder 0 contains the disklabel, which
contains the partition table. A normal filesystem can be placed
starting at Cylinder 0, since it will not touch the disklabel.
If you lay down a raw device, for a database, over Cylinder 0,
then you will completely lose all your partitions. You will then
have to restore the disklabel, and backup from tape if you happen to do this.

--> move a partition
find . |cpio -pdm /apps

--> cron structure
min hour day-of-month month weekday command

--> PatchDiag Tool. Get patches from:
http://sunsolve.sun.com/private-cgi/patchpage.pl
patchdiag.xref is available at: http://sunsolve.sun.com/sunsolve/patchdiag/
/opt/local/bin/patchdiag -x /opt/local/lib/patchdiag.xref > patchdiag.`uname -n`

--> command showing system parameters
/usr/sbin/sysdef

--> Get Ambient Temperature of Server
/usr/platform/SUNW,Ultra-4/sbin/prtdiag -v

--> good ps formatting showing percent cpu first.
ps -edf -o pcpu,pid,user,arg

--> full details on ps
/usr/bin/ps -A -o user,pid,pcpu,pmem,vsz,rss,tty,s,stime,time,args

--> chown the hidden files as well.
find . -print -exec chown -R sextone:staff {} \;

--> The nsradmin command is a command-line based administrative
program for the NetWorker system. Normally nsradmin monitors
and modifies NetWorker resources over the network.
/usr/sbin/nsr/nsradmin

--> Spray a server
-c number of packets
-d delay in microseconds
-l pakcet size in bytes
/usr/sbin/spray -c 1 -d 20 -l 4096 maggie

--> Turn on bold.
bold=`tput smso`
offbold=`tput rmso`
echo "${bold}You must be the \"root\" user to run this script.${offbold}"

--> good way to send a dir to tape
tar cf /dev/rmt/0n directory

--> example of bringing up an interface
ifconfig hme0:1 inet 10.2.25.52 up

--> show all connections
netstat -f inet

--> rpcinfo makes an RPC call to an RPC server and reports
what it finds.
rpcinfo -b 390109 2 | sort -u

--> rewind a tape fast
< /dev/rmt/0

--> show loaded modules
/usr/sbin/modinfo

--> find world readable files and dirs
find / -type d -perm -2 -print
find . -type f -perm -2 -print

--> adding in a boot alias, eg:
boot sarahroot1 -s
nvalias sarahroot1 /sbus@1f,0/sunw,fas@e,8800000/sd@9,0:a

--> clever way to archive
tar cvf - `find . -print` >/tmp/dumpfile.tar
tar xvf - </tmp/dumpfile.tar

--> tee to a file
echo "Start Date/Time: `date`" | tee -a $LOG_FILE

--> read a snoop file
snoop -i anz-telnet.snoop

--> write a snoop log (this will count the number of connections, which is pretty neat).
snoop -osnoop.log sarah

--> set default run level. 5 for gui.
/etc/inittab

--> show all exported filesystems
showmount -e crawl

--> shows all configurable variables for tcp interface.
sudo ndd -get /dev/tcp
- ?
eg:
sudo ndd -get /dev/tcp tcp_conn_req_max_q
128
ndd /dev/arp \?
ndd /dev/ip \?
ndd /dev/tcp \?
ndd /dev/udp \?
ndd /dev/icmp \?

--> set sticky bit on group files, only the owner can change the mode.
--> the +l is mandatory file and record locking while a program
--> is accessing that file.
chmod g+s,+l file

--> print duplex landscape 4 qudrant printing
mpage -t -l -4

--> install a patch
installpatch .

--> check to see if a patch has been installed
showrev -p |grep package name

--> unzip, untar in a /tmp directory
zcat 104708-16.tar.gz | ( cd /tmp; sudo tar xvf - )

--> check out revision level on ssa controller
/usr/sbin/ssaadm display controller

--> unzip and untar a file without having to create an intermediate tar file
sudo gzip -dc /tmp/270599/post-EOD.tar.gz |tar xvf -

--> selectively extract from a tar archive
tar xvf /tmp/iona.tar ./iona/.sh_history

--> send a bunch of files to tape
tar cf /tmp/rules.tar ruleb* objects.C *.W

--> examine section 5 of man
man -s 5 signal

--> shows signals and definitions of structures, eg sigaction
/usr/include/sys/signal.h

--> location of the limits file on solaris
/usr/include/limits.h

--> send an attachment via email from command prompt
uuencode file.tar.gz file.tar.gz | mailx -s “backup” root@crawl

--> zero a file
cat /dev/null > isam.log

--> good way to restore from cdrom a binary file
zcat < /cdrom/cdrom0/Solaris_2.6/Product/SUNWcsu/install/reloc.cpio.Z |
cpio -idm usr/lib/fs/ufs/ufsrestore

--> running su as a user then ssh
su - dls-PROD -c "/opt/local/bin/ssh drp-stagger \"cd /tmp; /bin/ls\" "

--> verify a newfs format
sudo newfs -Nv /dev/md/dsk/d96

--> making lost_found. must be 8192 bytes in size.
mkdir ./lost+found;chown root ./lost+found; chgrp root ./lost+found ;chmod 700 ./lost+found’; cd ./lost+found
nofiles=0 ; while [ "$nofiles" -le 650 ] ; do ; /usr/ucb/touch $nofiles ; nofiles=`expr $nofiles + 1` ; done

--> execute lynx
lynx -cfg /usr/lib/lynx.cfg

--> sed search example
sed '/Sep\ 25/!d; /castill/!d' /var/log/syslo

-->should only be used at the EEPROM
boot -r
--> should be used at single user mode
reboot -- -r
--> should be used in multiuser mode
touch /reconfigure

--> performing a remote dump

find MFASYS
|cpio -oc |gzip -c
|ssh brucey -l chaup dd obs=18k of=/dev/rmt/0n

- to extract -
cd /ssa/emphasys/sybase/dump
dd ibs=18k if=<TAPE DEVICE>|gunzip -c |cpio -idc

--> boot block located here.
/usr/platform/`uname -i`/lib/fs/ufs

--> getting a server on the network
add hosts entry for IP address
clear configs: ifconfig pe0 unplumb
ifconfig pe0 10.20.2.27 netmask 255.0.0.0 up
route add default 10.20.0.1 1
verify the routing table: netstat -rn
add resolv.conf entry: domain rabobank.com.au nameserver 192.192.192.252
edit /etc/nsswitch.conf change hosts to files, dns

lesson here is to unplumb interface, and let ifconfig setup the routing.
if you specify an ip address and a netmask it will manage
the routing and the broadcasting.

--> find all, files associated with PID 22240
/usr/proc/bin/pfiles 22240
find file based on inode
find -i number
“ncheck -i number

--> good redirection example
./a.out </etc/termcap | (sleep 10; cat) >trash

--> synchronize files from one server to another. This is useful for
synchronizing database dump files, binary files, etc. This is definitely a powerful tool.

rsync -avz -e ssh --rsync-path="/usr/local/bin/rsync" `pwd` myhost.com:/home/ebs/public_html

--> Example Awk Script

# run with awk -f/tmp/1.awk /etc/group

BEGIN { FS = ":" }
{ print $1 | "sort" }
{ nlines++ }
END { print nlines }

--> awk example.
awk '/#/ {print "Got a comment"}' /etc/hosts

--> delete every 2nd field in file
awk '{$2= ""; print}' datafile > datafile.new

--> awk average/standard deviation program

x1 += $1
x2 += $1*$1

END {
x1 = x1/NR
x2 = x2/NR
sigma = sqrt(x2 - x1*x1)
if (NR > 1) std_err = sigma/sqrt(NR - 1)
print "Number of points = " NR
print "Mean = " x1
print "Standard Deviation = " sigma
print "Standard Error = " std_err

  • restore from client using ssh and restore
    By : Rob ( Tue May 11 08:23:02 2004 )

    from client "linux" to backup server "solaris":

    clent> cd /tmp
    client> ssh -x server "dd if=/dev/rmt/0ln ibs=63k" | /sbin/restore -ivf -
    Verify tape and initialize maps
    Input is from file/pipe
    user@server's password:
    Input block size is 32
    Dump date: Tue May 9 07:07:49 2004
    Dumped from: the epoch
    Level 0 dump of / on client.comp.com:/dev/sda3
    Label: /
    Extract directories from tape
    Initialize symbol table.
    /sbin/restore >

  • UNIX Tips and Tricks

    Enabling TCP Wrappers in Solaris 10

    Glenn Brunette's Security Weblog Tip of the Month: Enabling TCP Wrappers in Solaris 10

    Before answering this question, let's first provide a little background. TCP Wrappers has been around for many, many years. It is used to restrict access to TCP services based on host name, IP address, network address, etc. For more detailed on what TCP Wrappers is and how you can use it, see tcpd(1M). TCP Wrappers was integrated into Solaris starting in Solaris 9 where both Solaris Secure Shell and inetd-based (streams, nowait) services were wrapped. Bonus points are awarded to anyone who knows why UDP services are not wrapped by default.

    TCP Wrappers support in Secure Shell was always enabled since Secure Shell always called the TCP Wrapper function host_access(3) to determine if a connection attempt should proceed. If TCP Wrappers was not configured on that system, access, by default, would be granted. Otherwise, the rules as defined in the hosts.allow and hosts.deny files would apply. For more information on these files, see hosts_access(4). Note that this and all of the TCP Wrappers manual pages a stored under /usr/sfw/man in Solaris 10. To view this manual page, you can use the following command:

    $ man -M /usr/sfw/man -s 4 hosts_access

    inetd-based services use TCP Wrappers in a different way. In Solaris 9, to enable TCP Wrappers for inetd-based services, you must edit the /etc/default/inetd file and set the ENABLE_TCPWRAPPERSparameter to YES. By default, TCP Wrappers was not enabled for inetd.

    In Solaris 10, two new services were wrapped: sendmail and rpcbind. sendmail works in a way similar to Secure Shell. It always calls the host_access function and therefore TCP Wrappers support is always enabled. Nothing else needs to be done to enable TCP Wrappers support for that service. On the other hand, TCP Wrappers support for rpcbind must be enabled manually using the new Service Management Framework ("SMF"). Similarly, inetd was modified to use a SMF property to control whether TCP Wrappers is enabled for inetd-based services.

    Let's look at how to enable TCP Wrappers for inetd and rpcbind...

    To enable TCP Wrappers support for inetd-based services, you can simply use the following commands:

    # inetadm -M tcp_wrappers=true
    # svcadm refresh inetd

    This will enable TCP Wrappers for inetd-based (streams, nowait) services like telnet, rlogin, and ftp (for example):

    # inetadm -l telnet | grep tcp_wrappers
    default  tcp_wrappers=TRUE

    You can see that this setting has taken effect for inetd by running the following command:

    # svcprop -p defaults inetd
    defaults/tcp_wrappers boolean true

    Note that you can also use the svccfg(1M) command to enable TCP Wrappers for inetd-based services.

    # svccfg -s inetd setprop defaults/tcp_wrappers=true
    # svcadm refresh inetd

    Whether you use inetadm(1M) or svccfg is really a matter of preference. Note that you can also use inetadm or svccfg to enable TCP Wrappers on a per-service basis. For example, let's say that we wanted to enable TCP Wrappers for telnet but not for ftp. By default, both the global and per-service settings for TCP Wrappers are disabled:

    # inetadm -p | grep tcp_wrappers
    tcp_wrappers=FALSE
    
    # inetadm -l telnet | grep tcp_wrappers
    default  tcp_wrappers=FALSE
    
    # inetadm -l ftp | grep tcp_wrappers
    default  tcp_wrappers=FALSE

    To enable TCP Wrappers for telnet, use the following command:

    # inetadm -m telnet tcp_wrappers=TRUE

    Let's check out settings again:

    # inetadm -p | grep tcp_wrappers
    tcp_wrappers=FALSE
    
    # inetadm -l telnet | grep tcp_wrappers
             tcp_wrappers=TRUE
    
    # inetadm -l ftp | grep tcp_wrappers
    default  tcp_wrappers=FALSE

    As you can see, TCP Wrappers has been enabled for telnet but none of the other inetd-based services. Pretty cool, eh?

    You can enable TCP Wrappers support for rpcbind by running the following command:

    # svccfg -s rpc/bind setprop config/enable_tcpwrappers=true
    # svcadm refresh rpc/bind

    This change can be verified by running:

    # svcprop -p config/enable_tcpwrappers rpc/bind
    true

    That is all that there is to it! Quick, easy and painless! As always, let me know what you think!

    Take care!

    Recommended Links

    Softpanorama hot topic of the month

    Softpanorama Recommended

    ***** Sun Solaris Tips An excellent collection of tips !!!

    Solaris IAOQ (INFREQUENTLY ASKED AND OBSCURE QUESTIONS )

    Tips and Tricks at OpenSolaris.org

    Solaris tips Sheets

    Phil's Solaris hints

    Volume manager tips aka automounter

    Solaris Tips and Tricks

    Modular Debugger (mdb) cheatsheet (PDF)

    Sys Admin Cool Commands

    Sun documentation by product

    Solaris Admininstror's Quick Reference (PDF)

    Solaris Tips and tricks knowledge base (outdated)

    Solaris Hints and Tips

    Solaris - Tips & Tricks collection

    My Solaris page

    Some scripts I have written for Solaris that you may find interesting:

    Oracle Tips and Tricks of the Week Part 3

    Everything Solaris Filesystem Tips and Tricks



    Etc

    FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit exclusivly for research and educational purposes.   If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner. 

    ABUSE: IPs or network segments from which we detect a stream of probes might be blocked for no less then 90 days. Multiple types of probes increase this period.  

    Society

    Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

    Quotes

    War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

    Bulletin:

    Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

    History:

    Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

    Classic books:

    The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

    Most popular humor pages:

    Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

    The Last but not Least


    Copyright © 1996-2016 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License.

    The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

    Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

    FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

    This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

    You can use PayPal to make a contribution, supporting development of this site and speed up access. In case softpanorama.org is down you can use the at softpanorama.info

    Disclaimer:

    The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

    Last modified: July, 13, 2017