Mabuhay

Hello world! This is it. I've always wanted to blog. I don't want no fame but just to let myself heard. No! Just to express myself. So, I don't really care if someone believes in what I'm going to write here nor if ever someone gets interested reading it. My blogs may be a novel-like, a one-liner, it doesn't matter. Still, I'm willing to listen to your views, as long as it justifies mine... Well, enjoy your stay, and I hope you'll learn something new because I just did and sharing it with you.. Welcome!
Showing posts with label UNIX commands. Show all posts
Showing posts with label UNIX commands. Show all posts

Thursday, June 11, 2009

Scripting 101: Modification on the previous topic

Before I modified the original script, I was advised by my colleague to take note of the date especially for the single digits, which was not addressed before. So, the corrections include re-assigning of variables, deletion of unwanted, throwing errors to null, etc.

Here they are:

1. CSV_DATE=`date '+%a %b %d'`
2. LIST_DATE was removed.
3. echo-es were deleted.
4. Errors were thrown to /dev/null; when added to cron, this will be re-directed to /dev/null as well.
5. mail was not working so I used EOF for the body:

/usr/ucb/mail -s "Subject here..." $EMAIL_ADD <<\
EOF

# Whatever the content between EOFs will be evaluated a regular formatted text (including blank lines and spaces) except for variable substitution such as here, which will output the result - the current date.

This will be a regular text.
$(date)

EOF

6. Since LIST_DATE was removed, I used 'find' to locate the most recent files that were modified, as:

for CSV in `find /path/of/files -name "some*.csv" -mtime 0\
2> /dev/null`
do
cp -p $CSV /some/httpd/location/
done

I hope, everything will be ok now after this week's test. It'll be submitted for cron-nization!

Saturday, May 23, 2009

Scripting 101: Shell Script that uses Perl

Good morning (very sleepy now!).. I promised to myself that I will modify the script that we're using to generate a report. I'm not familiar - yet - with the contents but the thing is, we run this manually every night and then copy it to another directory which make it available to the user/s. It's just another basic modification but I added some "twists" a safety pre-caution or stop unwanted operation - well, that's what I wish, at least.

The main script was made by "Someone Else" (There! I ain't saying it's mine.). In time, I'll interpret the Perl part here.


#! /usr/bin/sh

#
# This is a modified version.
# Author: Someone Else
# Modified by: ME
# Renamed: badname_PT.sh
# Date: 23 May, 2009
# Version: 1
#

CSV_DATE=`date | awk '{print $1,$2,$3}'`
E_NOTCD=43
E_OK=0
E_OTHER=45
EMAIL_ADD="name@domain.com"
FILE_DATE=`date '+%d_%m_%y'`
HOSTS="/path/to/host_list_PT"
LIST_DATE=`date | awk '{print $2,$3}'`
SCRIPTDIR="/var/tmp/jf"
export all

# On top of the original script, hour condition was placed to make sure that it runs only after 17:59 daily.
if [ `date +%H` -gt "17" ]
then

cd $SCRIPTDIR || {
/usr/bin/mailx -s "Can't change to $SCRIPTDIR; Please \
check permissions..." $EMAIL_ADD
exit $E_NOTCD
}

# This generates the reports; the heart of the script
for H_LIST in `cat $HOSTS`
do
echo "Extracting bad names from P2PS: $H_LIST"

# No more manual intervention in changing the dates (CSV_DATE was used - from current date)
rsh $H_LIST cat /path/to/some.log* | grep \
"$CSV_DATE" | grep ptrade | perl -n -e \
'if (m/^.* ([0-9]*:[0-9]*:[0-9]*).*Open Failure for (\(.*:.*\)) \
by (\(.*\)) at (\(.*\/net\)).*/) {$_= "$1,$2,$3,$4"; $_ =~ s/[\)|\(]//g;\
print "$_\n";}' > /var/tmp/PT_BadRequests.$H_LIST.csv

sleep 1

echo "Copying /var/tmp/PT_BadRequests.$H_LIST.csv /var/tmp/jf"
cp /var/tmp/PT_BadRequests.$H_LIST.csv /var/tmp/jf
echo "Copy completed for $H_LIST"
done

sleep 3

chmod 666 /var/tmp/jf/PT_*

rm /tmp/PT_BadNames_*
rm /some/httpd/html/PT_BadNames*

tar cvf /tmp/PT_BadNames_$FILE_DATE.tar ./PT*csv
compress /tmp/PT_BadNames*.tar
cp /tmp/PT_BadNames* /some/httpd/html
chmod 666 /some/httpd/html/PT_BadNames*

sleep 2

rm /tmp/PT_BadNames*
rm /var/tmp/jf/PT_BadReq*

# This was added to copy the newly generated CSVs from /var/tmp to /app/httpd/html site
if cd /var/tmp
then
for csv in `ls -l *csv | grep PT_BadRequests | grep "$LIST_DATE" \
| awk '{print $9}'`
do
cp -p $csv /some/httpd/html/Primetrade_BadRequests/
ls -l /some/httpd/html/Primetrade_BadRequests/$csv
done

# On completion, a mail will be sent to intended recipient/s.
/usr/bin/mailx -s "Bad Name PRIMETRADE Report is DONE" $EMAIL_ADD
exit $E_OK

else
/usr/bin/mailx -s "Can't change to /var/tmp; Please check \
permissions..." $EMAIL_ADD
exit $E_NOTCD
fi

fi

echo "Not yet..."
exit $E_OTHER

Also, if this script is run manually, which uses csh, copying each file would be "tedious". So, I made a FOR-loop to do it - very basic but syntax is tricky.

% set LIST_DATE=`date +%b" "%d`
% foreach csv (`ls -l /var/tmp/*csv | grep PT_BadRequests | grep "$LIST_DATE" | awk '{print $9}'`)
? do
? cp -p $csv /some/httpd/html/Primetrade_BadRequests/
? ls -l /some/httpd/html/Primetrade_BadRequests/$csv
? end
%

Wednesday, April 01, 2009

Scripting 101: Monitoring Autosys Jobs - Changes

When I got to the office today, I started working on the planned changes for the script. 'Though not all, I was able to find a way to implement number 4 from my early list. So here it goes.

Let me establish first the fact that this is primarily designed to address the current setup of jobs that we're monitoring. We already know when it'll be executed so the list is pre-arranged according to time of execution. From which I have considered the changes that I did. And as always, this is a work in progress so bear with me.

First change that I did was to add a couple of lines in the JOB_CHECKER function after the SU_MAILER.

cp -p JOBLIST.txt TEMP.out
sed '1d' TEMP.out > JOBLIST.txt

It deletes job 1 from the JOBLIST.txt as not to waste time when doing a FOR-loop for jobs already marked as SU. It's kinda lame really but am looking for better way to cleanup this mess.

The second one is changing the condition in JOB_CHECKER function.

if [ "$DONE_JOB" = "$ONQUEUE_JOB" ]

was changed to [and DONE_JOB is removed]:

if grep -w $ONQUEUE_JOB EXCLUDEJOB.txt

Third is on WHILE-loop. The script exits when there's nothing left [to read] in the JOBLIST.txt. Hence, COUNTER is no longer needed.

while [ "$NO_JOBS" -gt "0" ]
...

It's still consuming a lot of CPU and I haven't figure this one out yet. To allow "others", after a FOR-loop, I put the script into sleep.

And lastly, a safety net was added in the SU_MAILER function. It'll erase duplicate entries from the exclusion list.

SU_MAILER() {
/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep $JOBNAME | awk '{sub (/:/,""); print $1$2$3}' >> EXCLUDEJOB.txt

awk '!x[$0]++' EXCLUDEJOB.txt > EXCLUDEJOB.txt

I hope I'm on track on improving my scripting skills; always looking forward for a new challenge.

********
This part was added on 15 April, 2009 at 21:33 SST.

The variable $NO_JOBS was removed. Instead, its value was placed in the WHILE-loop. It was late when I found out that it is NOT being updated. Also, there are times when some of the jobs listed may be invalid for one reason or another. With this, condition was added as well. So the code will be:

while [ `cat JOBLIST.txt | wc -l` -gt "0" ]
do
for JOBNAME in `cat JOBLIST.txt`
do

if /sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep "Invalid Job Name" 2>&1 > /dev/null
then
cp -p JOBLIST.txt VALJOB.out
sed -e "\|^$JOBNAME\$|d" VALJOB.out > JOBLIST.txt
continue
fi

...
done

exit $E_DONE

SU_MAILER () is still in the works. I still can't find how to delete duplicate entries while leaving one of them. The "awk" part that previously used was scrapped. It's NOT up to the job. Of course, it's my fault. ;)

I really hope I'll have the flame to continue on this for I started on my new job and is being "forced" to take on Perl which seems great. Now I know that it ain't a scripting language but rather on the grey area between interpreted and compiled. Still a long wayyyyyy. See'ya round.

Scripting 101: Monitoring Autosys Jobs - Evolved Form

Finally, here it is! I have this tested last night - on a PROD server [Linux only for some commands might NOT run on Solaris] - and it went well. After making some adjustments, it did behave as expected. Wow, I can't believe it. After a long while, I did it. Not of course without the valuable insights from my mentors - CJ and Mors - who gave their all [I hope!?]. I am a student and beginner in scripting. As for now, I'm still analyzing the logs to maximize performance for I have seen that it wastes so much time in loops. So anyone out there, please help me!

Here are some of what I've observed and future plans:
1. Run via cron; OR run it via "screen"
2. High CPU utilization
3. Integrate mutt in the script [not sure where but I'll try; it's a bit cool, ain't it?]
4. Instead of having an exclusion file, after a job is done, it will remove from the JOBLIST.txt and exit when nothing to read.

**********
#! /bin/bash

# Calling AUTOSYS environment
. /sbcimp/shared/config/CA/Autosys/v4.0/prod/autouser/shellPLN

# Definition and initialization of VARIABLES.
E_NOTFOUND=66
E_MISSING=43
E_DONE=0
EMAIL_ADD=`whoami`
COUNTER=0
NO_JOBS=`cat JOBLIST.txt | wc -l`


# Initialization of EXCLUSION file; this will be used to exclude successful job
> EXCLUDEJOB.txt
/bin/touch EXCLUDEJOB.txt
if [ ! -w EXCLUDEJOB.txt ]
then
/bin/echo "EXCLUDEJOB.txt file does not exist and/or not writeable! Check write permissions on the directory." | /bin/mail -s "EXCLUDEJOB.txt Missing" $EMAIL_ADD
exit $E_NOTFOUND
fi


# This is a mailer function for successful jobs; once the job ended successfully, it will write to EXCLUDEJOB.txt before sending a mail
SU_MAILER() {
/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep $JOBNAME | awk '{sub (/:/,""); print $1$2$3}' >> EXCLUDEJOB.txt

/bin/mail -s "FOS Job Monitor Update" $EMAIL_ADD >>EOF
****** Feed Status ******

Job ended SU-ccessfully!
$(/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -d -J $JOBNAME)

***** End of Status *****
EOF
} # End of SU_MAILER function


FA_MAILER() {
/bin/mail -s "FOS Job Monitor Alert" $EMAIL_ADD >> EOF
***** PLEASE check Job Status *****

$(/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -d -J $JOBNAME)
$(/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -q -J $JOBNAME)

***** End of Status ****
EOF
} # End of FA_MAILER function


JOB_CHECKER() {
DONE_JOB=`grep $JOBNAME EXCLUDEJOB.txt`
ONQUEUE_JOB=`/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep $JOBNAME | awk '{sub (/:/,""); print $1$2$3}'`

if [ "$DONE_JOB" = "$ONQUEUE_JOB" ]
then
continue
else
JOB_TIMESTAMP=`/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep $JOBNAME | awk '{sub (/:/,""); print $3}'`

if [ "$DATE_STAMP" = "$JOB_DATE" ] && [ "$TIME_STAMP" -ge "$JOB_TIMESTAMP" ]
then
if /sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep $JOBNAME | grep -w SU 2>&1 > /dev/null
then

SU_MAILER
COUNTER=$[$COUNTER+1]

elif /sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep $JOBNAME | egrep -w "ST|AC|RU" 2>&1 > /dev/null
then
break
else

FA_MAILER
COUNTER=$[$COUNTER+1]

fi
fi
fi
}
# End of JOB_CHECKER function

# This is basically the main function of the script; it will continue to run until all jobs listed in the JOBLIST.txt are successful

while [ "$COUNTER" -lt "$NO_JOBS" ]
do
for JOBNAME in `cat JOBLIST.txt`
do
JOB_TZ=`/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME -q | grep timezone | awk '{print $2}' | cut -d/ -f2`

if [ -z "$JOB_TZ" ]
then
/bin/echo "Timezone is NOT defined in $JOBNAME properties. Please check." | /bin/mail -s "Missing TIMEZONE" $EMAIL_ADD
continue
else

JOB_DATE=`/sbcimp/run/tp/CA/Autosys/v4.0/bin/autorep -J $JOBNAME | grep $JOBNAME | awk '{print $2}'`

case $JOB_TZ in
London)
DATE_STAMP=`TZ=GMT date +%m/%d/%Y`
TIME_STAMP=`TZ=GMT date +%X | cut -d: -f1-2 | awk '{sub (/:/,""); print}'`;;

Zurich)
DATE_STAMP=`TZ=GMT-1 date +%m/%d/%Y`
TIME_STAMP=`TZ=GMT-1 date +%X | cut -d: -f1-2 | awk '{sub (/:/,""); print}'`;;

Eastern)
DATE_STAMP=`TZ=GMT+5 date +%m/%d/%Y`
TIME_STAMP=`TZ=GMT+5 date +%X | cut -d: -f1-2 | awk '{sub (/:/,""); print}'`;;

Singapore|HongKong)
DATE_STAMP=`TZ=GMT-8 date +%m/%d/%Y`
TIME_STAMP=`TZ=GMT-8 date +%X | cut -d: -f1-2 | awk '{sub (/:/,""); print}'`;;

Tokyo)
DATE_STAMP=`TZ=GMT-9 date +%m/%d/%Y`
TIME_STAMP=`TZ=GMT-9 date +%X | cut -d: -f1-2 | awk '{sub (/:/,""); print}'`;;

Sydney)
DATE_STAMP=`TZ=GMT-11 date +%m/%d/%Y`
TIME_STAMP=`TZ=GMT-11 date +%X | cut -d: -f1-2 | awk '{sub (/:/,""); print}'`;;

*)
/bin/echo "What else could go wrong? Notify the script owner... Stressful." | /bin/mail -s "FOlSe Alert. Something is missing..." $EMAIL_ADD
exit $E_MISSING;;
esac
fi

JOB_CHECKER

done # End of FOR-loop

# Sleep will be added here for about 5 minutes
sleep 300

done
# End of WHILE-loop

exit $E_DONE

Sunday, March 29, 2009

Solaris Cheat Sheet: Episode 1

Yellow everyone! Guess who's back?!? Who?? No one..

It's been a very long time since that day [whatever it is]. I've been busy lately [honestly, I'm tired blogging] so why not drop by and post something that's already there. As always, these are for my reference. You can take whatever you could and encouraged to share some. By the way, I just finished reading Hajime No Ippo and looking forward for Takamura-san's fight. As you know, Ichiro-kun just won his OPBF title defense against Randy Boy Jr. [Philippines; and it's a lame name - sorry!]. But the question is, will Ippo vs. Ichiro really materialize? Can't wait either.

Ooops.. got carried away but after reading the above, I came across a good, known site that can really help me. So here it is the first installment of my Solaris cheat sheet! [My other script is on it's way - some refinement, always, and suggestions from my colleagues -.. if you're interested, keep an eye on it ;)]

Debugging
18. cat -v -t -e [file]
/* Show non-printing characters */
19.
dumpadm -d swap
/* Configure swap device as dump device */
20.
ld -l

/* Check if you have a particular library */
21.
truss -f -p

/* Using multiple windows, this can be used to trace setuid/setgid programs */
22.
truss executable
/* Trace doing of given command ( useful debugging ) */


Disk Commands
23. /bin/mount -F hsfs -o ro /dev/sr0 /cdrom
/* Mount an ISO 9660 CDROM */
24.
/usr/bin/iostat -E
/* Command to display drives statistics */
25.
du -ad /var | sort -nr
/* Report the the disk used in /var in reverse order */
26.
du -k .
/* Report disk usage in Kilobytes */
27.
du -sk * | sort -nr | head
/* Shows the top ten largest files/directories */
28.
du -sk *|sort -k1,1n
/* Reports total disk space used in Kilobytes in present directory */
29.
du -sk .
/* Report total disk usage in Kilobytes */
30.
fdformat -d -U
/* Format diskette */
31.
mount -F hsfs -o ro `lofiadm -a /export/temp/software.iso` /mnt
/* Mount an ISO Image */
32.
newfs -Nv /dev/rdsk/c0t0d0s1
/* To view the superfblocks available */
33.
prtvtoc /dev/dsk/c1t2d0s2 | fmthard -s - /dev/rdsk/c1t3d0s2
/* One-liner to copy a partition table */
34.
prtvtoc /dev/rdsk/c0t0d0s2
/* Disk geometry and partitioning info */
35.
prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2
/* Copy partition table from one disk to another */
36.
quot -af
/* How much space is used by users in kilobytes */
37.
volrmmount -i floppy
/* Mount a floppy or other media easily by its nickname. */



Driver Parameters
38. ndd /dev/ip ip_forwarding
/* Show the ip_forwarding variable in the kernel */
39.
ndd /dev/ip ip_forwarding 1
/* Set the ip_forwarding variable in the kernel */
40.
ndd /dev/ip \?
/* Show all IP variables set in the kernel */



File Manipulation
41. dos2unix | -ascii

/* Converts DOS file formats to Unix */
42.
fold -w 180
/* To break lines to have maximum char */
43.
split [-linecount] [file]
/* Split files into pieces */
44.
[vi] : %s/existing/new/g
/* Search and Replace text in vi */
45.
[vi] :set list
/* Show non-printing characters in vi */
46.
[vi] :set nu
/* Set line numbers in vi */
47.
[vi] :set ts=[num]
/* Set tab stops in vi */



File System
48. /sbin/uadmin x x
/* Syncs file systems and reboots systems fast */
49.
awk ' END {print NR}' file_name
/* Display the Number of lines in a file */
50.
cat /dev/null > filename
/* Zero's out the file without breaking pipe */
51.
cksum [filename]
/* View the checksum value for the given file */
52. dd if=/dev/rdsk/... of=/dev/rdsk/... bs=4096
/* Make a mirror image of your boot disk */
53.
df -k | grep dg| awk '{print $6}' |xargs -n 1 umount
/* Unmount all file systems in disk group dg */
54.
fsck -F ufs -o b=97472 /dev/rdsk/c0t0d0s0
/* Check and repair a UFS filesystem on c0t0d0s0, using an alternate superblock */
55.
fsck -F ufs -y /dev/rdsk/c0t0d0s0
/* Check a UFS filesystem on c0t0d0s0, repair any problems without prompting. */
56.
fsck -F ufs /dev/rdsk/c0t0d0s0
/* Check a UFS filesystem on c0t0d0s0 */
57.
gzip -d -c tarball.tgz | (cd /[dir];tar xf - ) &
/* Unpacking tarballs to diff location */
58.
gzip -dc file1.tar.gz | tar xf -
/* Unpack .tar.gz files in place */
59.
ln [-fhns]

/* Creating hard links and soft links */
60.
ls -al | awk '$3 == "oracle" || $3 == "root" {print $9}'
/* List all file names by testing owner */
61.
ls -l | sort +4n
/* List files by size */
62.
ls -la | awk '{ print $5," ",$9 }' | sort -rn
/* File sizes of current directory */
63.
ls -lR | awk '{total +=$5};END {print "Total size: " total/1024/1024 "MB" }'
/* Recursive directory size calculations in MB */
64.
mkisofs -l -L -r -o [image-name].iso [directory]
/* Create an ISO image of a directory */
65.
mount -F ufs -o rw,remount /
/* Used to remount root to make it writeable */
66.
mount -o remount,logging /spare
/* Re-mount the ro file system rw and turn on ufs logging */
67.
mount -f pcfs /dev/dsk/c0d0p1 /export/dos
/* DOS fdisk partition from Solaris */
68.
mv [filename]{,.new_suffix}
/* Renaming file */
69.
pax -rw . /newdir
/* Efficient alternative for copying directories */
70.
prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2
/* Cloning Partitiontables */
71.
rpm -q --queryformat '%{INSTALLPREFIX}\n' [packagename]
/* [Linux] Locate binaries */
72.
tar cf - . | (cd /newdir ; tar xf -)
/* Recursively copy files and their permissions */
73.
tar cvf filename.tar
/* Create a tape (tar) archive */
74.
tar xvf filename.tar
/* Extract a tape (tar) archive */
75. X=$(wc -l < filename); echo $X
/* Count number of lines in a file into a variable (ksh) */
76. zcat < patch_file.tar.Z) | tar xvf -
/* Extracts the patch_file that is a compressed tar file */
77. zcat [cpio file] | cpio -itmv
/* Show the contents of a compressed cpio */


File Transfer
78. find . -depth | cpio -pdmv /path/tobe/copied/to
/* Fast alternative to cp -pr */
79.
find . -follow | cpio -pdumL /path/tobe/copied/to
/* Copy with symbolic links to be followed */
80.
get filename.suffix |"tar xf -"
/* Undocumented Feature of FTP */
81.
ssh cd /some/directory \&\& tar cf - | ssh cd /some/direstory \&\& tar xvf -
/* Move any file(s) without actually touching them */
82.
put "| tar cf - ." filename.tar
/* Undocumented Feature of FTP */
83.
sendport
/* FTP command for transferring large numbers of files within the same control session */


General
84. /bin/printf '%d\n' '0x'
/* Converts hexadecimal number to decimal. */
85.
/usr/bin/catman -w
/* Create windex databases for man page directories */
86.
echo 'obase=16;255' | bc
/* Simple way to convert decimal to hex */
87.
FQ_FILENAME=
; echo ${FQ_FILENAME%/*}
/* Extract directory from fully-qualifi
ed file name. */
88.
mailx -H -u

/* List out mail headers for specified user */
89.
ps -ef | grep -i $@
/* Access common commands quicker */
90.
set filec
/* Set file-completion for csh */
91.
uuencode [filename] [filename] | mailx -s "Subject" [user to mail]
/* Send files as attachments */
92.
xauth -f /home/${LOGNAME} extract - ${DISPLAY} | xauth merge -
/* Allow root to xdisplay after su */



Hardware
93. cfgadm
/* Verify reconfigurable hardware resources */
94.
m64config -depth 8|24
/* Sets the screen depth of your M64 graphics accelerator */
95.
m64config -prconf
/* Print M64 hardware configuration */
96.
m64config -res 'video_mode'
/* Change the resolution of your M64 graphics accelerator */
97.
prtpicl -v | grep sync-speed
/* Discover SCSI sync speed */



Kernel
98. /usr/sbin/modinfo
/* Display kernel module information */
99.
/usr/sbin/modload

/* Load a kernel module */
100.
/usr/sbin/modunload -i

/* Unload a kernel module */
101.
/usr/sbin/sysdef
/* Show system kernal tunable details */
102.
nm -x /dev/ksyms | grep OBJ | more
/* Tuneable kernel parameters */
103.
update_drv -f [driver name]
/* Force a driver to reread it's .conf file without reloading the driver */


Memory
104. pagesize -a
/* Available page sizes for Solaris 9 */
105.
prtconf | grep Mem
/* Display Memory Size of the local machine. */



Network Information
106. arp -a
/* Ethernet address arp table */
107.
arp -d myhost
/* Delete an ethernet address arp table entry */
108.
lsof
-iTCP@10.20.2.9
/* Display open files for internet address */
109.
named-xfer -z qantas.com.au -f /tmp/allip
/* Get All IP Addresses On A DNS Server */
110.
ndd /dev/arp arp_cache_report
/* Prints ARP table in cache with IP and MAC address */
111.
netstat -a | grep EST | wc -l
/* Displays number active established connections to the localhost */
112.
netstat -a | more
/* Show the state of all the sockets on a machine */
113.
netstat -i
/* Show the state of the interfaces used for TCP/IP traffice */
114.
netstat -k hme0
/* Undocumented netstat command */
115.
netstat -np
/* Similar to arp -a without name resolution */
116.
netstat -r
/* Show the state of the network routing table for TCP/IP traffic */
117.
netstat -rn
/* Displays routing information but bypasses hostname lookup. */
118.
snoop -S -ta [machine]
/* Snoop for network packets and get size and time stamp entries. */
119.
traceroute

/* Follow the route to the ipaddress */



Network Tuning
120. /sbin/ifconfig hme0:1 inet 10.210.xx.xxx netmask 255.255.0.0 broadcast 10.210.xxx.xxx
/* Virtual Interfaces */
121. /sbin/ifconfig hme0:1 up
/* Bring virtual interface up */
122.
/usr/sbin/ndd -set /dev/hme adv_100fdx_cap 1
/* Nailling to 100Mbps */
123.
ifconfig eth0 10.1.1.1 netmask 255.255.255.255
/* Add an Interface */
124.
ifconfig eth0 mtu 1500
/* Change MTU of interface */
125.
ndd -set /dev/ip ip_addrs_per_if 1-8192
/* To set more than 256 virtual ip addresses. */
126.
ndd -set /dev/tcp tcp_recv_hiwat 65535
/* Increase TCP-receivebuffers on Sol2.5.1 systems with 100BaseTx */
127.
ndd -set /dev/tcp tcp_xmit_hiwat 65535
/* Increase TCP-transmitbuffers on Sol2.5.1 systems with 100BaseTx */


Processes
128. /usr/proc/bin/ptree

/* Print the parent/child process 'tree' of a process */
129.
/usr/proc/bin/pwdx

/* Print the working directory of a process */
130.
/usr/ucb/ps -aux | more
/* Displays CPU % usage for each process in ascending order */
131.
/usr/ucb/ps -auxww | grep

/* Gives the full listing of the process (long listing) */
132.
coreadm -i core.%f.%p
/* Append program name and process id to core file names */
133.
fuser -uc /var
/* Processes that are running from /var */
134.
ipcs
/* Report inter-process communication facilities status */
135.
kill -HUP `ps -ef | grep [p]roccess | awk '{print $2}'`
/* HUP any related process in one step */
136.
lsof -i TCP:25
/* Mapping port with process */
137.
pfiles

/* Shows processes' current open files */
138.
pkill -n

/* Kill a process by name */
139.
prstat -a
/* An alternative for top command */
140.
ps -edf -o pcpu,pid,user,args
/* Nicely formatted 'ps' */
141.
ps -ef | grep -i
| awk '{ print $2 }'
/* Creates list of running PID by
*/
142.
ps -ef | grep -i
| awk '{ print $2 }'
/* Creates list of running PID by */
143.
ps -ef | grep
| grep -v grep | cut -c 10-15 | xargs kill -9
/* Find and kill all instances of a given process */
144.
ps -ef | more
/* Show all processes running */
145.
ps -ef|grep -v "0:00"|more
/* Gives you a list of any process with CPU time more than 0:00 */
146.
ps -eo pid,args
/* List processes in simplified format */
147.
ps -fu oracle|grep pmon
/* See which instances of Oracle are running */
148.
top -b 1
/* Returns the process utilizing the most cpu and quits */


Resource Management
149. /usr/bin/ldd [filename]
/* List the dynamic dependencies of executable files */
150.
/usr/proc/bin/pmap pid
/* Report address space map a process occupies */



Route Configuration
151. route add net 128.50.0.0 128.50.1.6 1
/* Add a route to the routing table */
152.
route change 128.50.0.0 128.50.1.5
/* Changes the destination address for a route */
153.
route delete net 128.50.0.0 128.50.1.6
/* Delete a route from the routing table */
154.
route flush
/* Flush the routing table, which will remove all entries */
155.
route get [hostname]
/* Which interface will be used to contact hostname */
156.
route monitor
/* Monitor routing table lookup misses and changes */


Searching Items
157. cat
| awk '{if (substr($1,1,1) == '#') print $0 }'
/* Print all lines in a file beginning with a specific character */
158.
egrep "patterna|patternb"

/* Search for multiple patterns within the same file */
159.
find
-name "" -exec rm -rf {} \;
/* Recursively finds files by name and automatically removes them */
160.
find . -type f -print | xargs grep -i [PATTERN]
/* Recursive grep on files */
161.
find . ! -mtime -
| /usr/bin/xargs rm -rf
/* Finds and removes files older than
specified */
162.
find . -exec egrep -li "str" {} \;
/* Find a string in files starting cwd */
163.
find . -mtime -1 -type f
/* Find recently modified files */
164.
find . -type f -exec grep "
" {} \; -print
/* Find files (and content) containing
within directory tree */
165.
find . -type f -exec grep -l "
" {} \;
/* Find files (and content) containing
within directory tree */
166.
find ./ \! -type f -exec ls -l {} \;|grep -v '^[l|p|s|-]'|grep -v 'total' | wc -l
/* Find number of directories under the current directory */
167.
find / -fstype nfs -prune -o fstype autofs -prune -o -name filename -print
/* Find without traversing NFS mounted file systems */
168.
find / -mtime <# of days>
/* Find files modified during the past # of days */
169.
find / -perm -2 -a ! -type l
/* Find files writable by 'others' */
170.
find / -type f |xargs ls -s | sort -rn |more
/* List files taking up the most system space */
171.
find / -user

/* Find all files owned by
*/
172.
find / -xdev -type f -ls|sort -nr -k 7,7
/* Find largest files in a file system */
173.
find / | grep [file mask]
/* Fast way to search for files */
174.
find /proc/*/fd -links 0 -type f -size +2000 -ls
/* Find large files moved or deleted and held open by a process */
175.
grep
/var/sadm/install/contents| awk '{ print $1 ' ' $10 }'
/* Find which package contains a particular file */
176.
ls -lR | grep

/* Fast alternative to find. */
177.
pkgchk -l -p /absolute/path/todir
/* Which package does this file belong to? */



Security
178. crypt
abc && rm abc.cr
/* Decrypting a file that has been encrypted */
179.
crypt
abc.cr && rm abc
/* File encryption with crypt */
180.
echo 'Please go away' > /etc/nologin
/* Stops users logging in */
181.
find / -perm -0777 -type d -ls
/* Find all your writable directories */
182.
find / -type f -perm -2000 -print
/* Find all SGID files */
183.
find / -type f -perm -4000 -print
/* find all SUID files */
184.
getpwenc [encryption scheme] password
/* Genrate passwords for LDAP Using 'getpwenc' Utility */
185.
trap 'exit 0' 1 2 3 9 15
/* Trap specific signals and exit */
186.
vi -x [filename]
/* Encrypt a file with vi editor */



Setting Term Options
187. stty erase ^?
/* Set the delete key to delete a character */
188.
stty erase ^H
/* Set the backspace to delete a character */
189.
stty sane
/* Reset terminal after viewing a binary file. */
190.
tput rmacs
/* Reset to standard char set */



Snoop
191. snoop -d pcelx0
/* Watch all the packets on a device */
192.
snoop -i /tmp/mylog -o /tmp/newlog host1
/* Filter out all the host1 packets and write them to a new logfile */
193.
snoop -i /tmp/mylog -v -p101
/* Show verbose info on packet number 101 in the logfile */
194.
snoop -i /tmp/mylog host1 host2
/* View packets from a logfile between hosts1 and host2 */
195.
snoop -o /tmp/mylog pcelx0
/* Save all the packets from a device to a logfile */
196.
snoop -s 120
/* Return the first 120 bytes in the packet header */
197.
snoop -v arp
/* Capture arp broadcasts on your network */
198.
snoop port [port-number]
/* Monitor particular port for traffic */


Swap Files
199. mkfile -nv 10m /export/disk1/myswap
/* Makes an empty 10 Megabyte swapfile in /export/disk */
200.
mkfile -v 10m /export/disk1/myswap
/* Makes a 10 Megabyte swapfile in /export/disk */



Swap Space
201. swap -a /export/disk1/swapfile
/* Add a swap file */
202.
swap -d /dev/dsk/c0t0d0s4
/* Delete a swap device */
203.
swap -l
/* List the current swap devices */
204.
swap -s
/* List the amount of swap space available */



System Configuration
205. /usr/sbin/eeprom auto-boot? false
/* Changes eeprom autoboot? setting without going to Ok prompt */
206.
/usr/sbin/eeprom diag-switch? true
/* Set the system to perform diagnostics on the next reboot. */
207.
/usr/sbin/eeprom local-mac-address?=true
/* Multiple Port Network Card Setting */
208.
/usr/sbin/grpck
/* Check /etc/group file syntax */
209.
/usr/sbin/pwck
/* Check /etc/passwd file syntax */
210.
/usr/sbin/sys-unconfig
/* Clear host specific network configuration information */
211.
/usr/sbin/useradd
/* Add a new user to the system */
212.
drvconfig ; disks
/* Adding hot-plug disks to system */



System Information/Monitoring
213. /bin/echo "0t${stamp}>Y\n<Y=Y" | adb
/* Convert UNIX timestamp to something human-readable */
214.
/usr/sbin/eeprom
/* Show eeprom parameters */
215.
/usr/sbin/prtconf -vp
/* Show system configuration details */
216.
coreadm -e log
/* Report global core */
217.
grep "\-root" /var/adm/sulog | grep -v \+ | tail -25
/* List most recent attempts to switch to superuser account. */
218.
isainfo -bv
/* Quickly checkout if machine is in 32 or 64 bit mode */
219.
last
/* Tells who was or still is on the system */
220.
logger -i
/* Log the process ID */
221.
prtconf -pv | grep banner-name |awk -F\' ' { print $2 } ' | head -1
/* Show actual model name of machine */
222.
prtdiag -v
/* System Diagnostics */
223.
prtpicl -v | grep wwn
/* A command to find persistent binding of storage */
224.
psradm -f [processor id]
/* Take processor offline */
225.
psrinfo | wc -l
/* Display number of processors */
226.
sar -u
/* Report CPU Utilization */
227.
sar [ -aA ] [ -o filename ] t [ n ]
/* Provides cumulative reports about system activity. */
228. telnet 13 | grep ':'
/* Get the time on remote Unix machine */
229.
uname -a
/* Displays system information */

230.
uname -X
/* Displays system information */
231. v
mstat 10
/* Displays summary of what the system is doing every 10 seconds */
232.
who -b
/* Displays the date of the last system reboot. */
233.
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. */

World Clock