My SysAd BlogMy SysAd BlogMy UNIX-based blog covers a collection of tips for installations, programming, scripting, configuration, SQL, maintenance, troubleshooting, and command line syntax. What exactly is UNIX? Unix stands for UNiplexed Information and Computing System--ori Articles
Recursively Display File and Directory Inodes
2007-06-28 19:35:00 I've had a few requests on how to show inodes recursively. I would recommend using the ls command with the recursive option. Using the /etc/security directory as an example, here's a quick way of doing that.# cd /etc/security# lsaudit audit_startup bsmunconv libaudit_class audit_user dev policy.confaudit_control audit_warn device_allocate prof_attraudit_data auth_attr device_maps spoolaudit_event bsmconv exec_attr# ls -iR | more.: 429447 audit 425561 audit_class 425562 audit_control 425751 audit_data 425563 audit_event 425747 audit_startup 425564 audit_user 425565 audit_warn 425568 auth_attr 425566 bsmconv 425567 bsmunconv 437267 dev 425749 device_allocate 425750 device_maps 425569 exec_attr 445066 lib 425571 policy.conf 425570 prof_attr 448971 spool./audit: 433367 localhost./audit/localhost: 433368 files./dev: 437268 audio 437269 fd0 437270 sr0 437271 st0 437272 st1.... More About: File , Display , Directory , Tory , Director
Paginate a File or Command Output for Printing
2007-06-27 15:07:00 There are times when you might need to print out documents that can span numerous pages. Often times, it's helpful to have the pages paginated with a detailed header (date, time, filename, and page number). The pr command can do these things. Here are some examples of its use.Prints 5 Line Header and Trailer. It also provides date, time, filename, and page number.# pr esofthub.txt | lpJan 9 08:52 2006 esofthub.txt Page 1Suppresses 5 Line Header and Trailer. It also suppresses date, time, filename, and page number.#pr -t esofthub.txt | lpDouble spaced and prints 5 Line Header and Trailer. It also provides date, time, filename, and page number.# pr -d esofthub.txt | lpDouble spaced, numbered lines, and prints 5 Line Header and Trailer. It also provides date, time, filename, and page number.# pr -dn esofthub.txt | lpLists a directory and prints its contents in 6 columns without a header# ls | pr -t6 | lpLists a directory and starts printing on page 4 with a header#ls | pr +4 | lp... More About: File , Inti , Comm , Command , Printing
Unzip Zip Files in Unix
2007-06-26 15:25:00 Since the last post dealt with the zip command, it's only fitting that its counterpart, the unzip command, is presented here. The unzip command is compatible with the PC pkunzip command. Here's the syntax.# cd /tmp (or whatever your destination directory is supposed to be)# unzip myzipfile.zip More About: Unix , Files
Recursively Zip Files and Directories
2007-06-26 14:54:00 It's not uncommon for system administrators to zip files and directories, especially if they are frequently sending data over email. Personally, I prefer it over the UNIX compress command. By the way, the UNIX zip command is compatible with the PC pkzip command. Here's the syntax.Files and directories added to myzipfile# zip -r myzipfile esofthub softhub.tar archive_dir mypic.gif mydir restrict_dir# ls -l myzipfile.zipDon't try to compress these file extensions# zip -rn .zip: .jpg: .png: .gif myzipfile esofthub softhub.tar archive_dir mypic.gif mydir restrict_dirFiles only#zip zipfile myfile1 myfile2 myfile3 myfile4 ...#ls -l zipfile.zip More About: Directories , Tori , Director , Dire
Add, Change, Delete, Monitor, and Flush the Routing Table
2007-06-25 11:55:00 Awhile ago, I posted a post regarding adding a route, but it only covered a static route. Why? For that particular day's post, I was dealing with a static route issue.Here's a quick and dirty guide to adding (nets, default route), deleting, changing, flushing, and monitoring the routing table.Add a route to the routing table# route add net 192.168.X.0 esofthub 1add net 192.168.X.0: gateway esofthubChange destination in the routing table# route change net 192.168.X.0 router-1change net 192.168.X.0: gateway router-1Add default route# route add default esofthub 1add net default: gateway esofthubDelete route from the routing table# route delete net 192.168.X.0 esofthubdelete net 192.168.X.0: gateway esofthubDetermine which interface will be used to contact the URL/hostname# route get esofthub.com route to: xxxxx0.xxx.mud.yahoo.comdestination: default mask: default gateway: router-1interface: hme0 flags: recvpipe sendpipe ssthresh rtt,ms rttvar,ms hopcount mtu ex... More About: Flush , Monitor , Table
Check Link Mode, Link Status, and Link Speed for Ethernet Interface
2007-06-24 13:20:00 The ndd command is also used to check for link mode, link status, and link speed of an Ethernet interface. Here's an example.# ifconfig -alo0: flags=1000849 mtu 8232 index 1 inet 127.0.0.1 netmask ff000000hme0: flags=1000843 mtu 1500 index 2 inet 192.xxx.xx.xx netmask ffffff00 broadcast 192.xxx.xx.xxx ether 8:0:20:xx:xx:xx# ndd -set /dev/hme instance 0# ndd -get /dev/hme link_mode1# ndd -get /dev/hme link_status1# ndd -get /dev/hme link_speed1What do the return values mean?mode: 0 is half duplex and 1 is full duplexstatus: 0 is down and 1 is upspeed: 0 is 10 megabits and 1 is 100 megabits More About: Mode , Link , Check , Speed
Full Duplex Settings for Network Interface
2007-06-23 15:49:00 The other day I was having problems auto negotiating duplex settings between a remote switch and my workstation. Initially, the ndd command was used to set up the 100Mb interface in full duplex mode. But later, the /etc/system file was modified to make the settings permanent following a reboot.Determine status#netstat -k hme0 | grep link#ndd -set /dev/hme adv_autoneg_cap 0#ndd -set /dev/hme adv_100hdx_cap 0#ndd -set /dev/hme adv_100fdx_cap 1#vi /etc/system#set hme:hme_adv_autoneg_cap=0#set hme:hme_adv_100hdx_cap=0#set hme:hme_adv_100fdx_cap=1:wq! More About: Network , Full , Interface , Settings , Full Duplex
User Switching to root or root Switching to User
2007-06-22 13:41:00 For auditing purposes, it could be useful to know who was switching to the root user or vice versa. You can find this type of information in the /var/adm/sulog file. Here's an example of its output.#cd /var/adm#more sulog | moreSU 05/27 22:29 + pts/5 root-esofthubSU 05/27 22:59 + pts/9 root-topbloglistsSU 05/29 23:45 + pts/6 esofthub-rootSU 05/29 23:46 + pts/6 root-freeadlistsSU 05/29 23:49 + pts/6 root-esofthubSU 05/30 22:02 + pts/6 root-freeadlistsSU 05/30 22:14 + pts/3 esofthub-rootSU 06/02 19:40 + pts/3 root-esofthubSU 06/02 19:44 + pts/3 esofthub-rootSU 06/16 23:37 + pts/3 root-esofthub3SU 06/17 20:57 + pts/8 root-esofthubSU 06/17 21:12 + pts/8 esofthub-rootSU 06/22 20:31 + pts/7 root-freeadlists More About: User , Root , Switching , Witch
Display Binary Audit Log Information in ASCII Format
2007-06-22 13:01:00 The files in the /var/audit directory are useful for inspection purposes; however, they are in a binary format. I use the praudit command to translate them into a human readable format. Here's an example of the praudit's output, which are logged telnet/local connections.To terminate the current audit file.#cd /var/audit#audit -n#praudit 20070621120225.20070621120111.esofthub | morefile,Thu 21 Jun 2007 09:02:25 PM KST, + 843354 msec,header,44,2,system booted,na,Thu 21 Jun 2007 09:02:09 PM KST, + 449998911 msectext,booting kernelheader,81,2,login - local,,Thu 21 Jun 2007 09:02:41 PM KST, + 300000097 msecsubject,root,root,other,root,other,31 4,314,0 0 esofthubtext,successful loginreturn,success,0header,81,2,login - telnet,,Fri 22 Jun 2007 08:00:38 PM KST, + 889999653 msecsubject,root,root,other,root,other,60 6,606,746 65559 192.168.X.XXXtext,successful loginreturn,success,0header,81,2,login - telnet,,Fri 22 Jun 2007 08:03:24 PM KST, + 630007314 msecsubject,root,root,other,root,other,61 ... More About: Information , Display , Audit , Form , Format
Display System or User Defined Mail Aliases
2007-06-20 12:02:00 On various occasions, I've been asked to show the members of a system or user defined mail alias. To satisfy this request, I could have simply performed a more or cat on the local /etc/mail/aliases file. But I prefer to use the praliases command. Here's an example.#praliasesIf you create another mail alias, you will need to execute the newaliases command.#vi /etc/mail/aliasesegalias:member1,member2, member3, member4:wq!#newaliases#praliases More About: Mail , System , Display , User , Fine
Find Total Number of Reboots for a Workstation or Server
2007-06-19 18:08:00 Here's a quick and dirty way of checking how many times your server/workstation was rebooted. First, I obtained the total number of reboots since Oct and then obtained the total number for each month. Here's an example.Total rebootswtmp begins Sat Oct 22 20:10# last | grep reboot | wc -l 19Find the total number of reboots for each month# for i in Oct Nov Dec Jan Feb Mar Apr May Jun> do> echo server was rebooted `last | grep $i | grep reboot | wc -l` in $i> doneserver was rebooted 10 in Octserver was rebooted 3 in Novserver was rebooted 0 in Decserver was rebooted 0 in Janserver was rebooted 1 in Febserver was rebooted 0 in Marserver was rebooted 1 in Aprserver was rebooted 3 in Mayserver was rebooted 1 in Jun More About: Server , Workstation , Stat
Disk to Disk Backup using ufsdump
2007-06-18 14:16:00 I was asked the other day how to create a bootable backup disk. In a previous post, I used the dd command to perform this task. However, you can use the ufsdump/ufsrerestore procedure, too. Here are 2 generic scripts, one c shell and the other Bourne shell.=================================== ==C Shell Script=================================== ==#!/bin/cshforeach myslice ( 0 3 4 ) echo y | newfs /dev/rdsk/c1t1d0s$mysliceendcd /foreach myslice ( 0 3 4 ) mount /dev/dsk/c1t1ds$myslice /mnt cd /mnt ufsdump 0uf - /dev/rdsk/c1t0d0s$myslice | ufsrestore rf - rm restoresymtable cd / umount /mntendinstallboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/c1t1d0s0mount /dev/dsk/c0t1d0s0 /mntsed 's/t0/t1/g' /mnt/etc/vfstab > /var/tmp/vfstabcp /var/tmp/vfstab /mnt/etc/vfstabumount /mnt===================================== Bourne Shell Script=================================== ==#!/bin/shfor myslice in 0 3 4do echo y | newfs /dev/rdsk/c1t1d0s$myslicedonecd /for myslice in 0 3 4do... More About: Backup , Disk
Delete a User Account via passmgmt
2007-06-17 14:28:00 You can also delete a user account via passmgmt. However, you will have to delete the home directory manually. Here's an example.# passmgmt -d esofthub# more /etc/passwd | grep esofthub# more /etc/shadow | grep esofthub# rm -r /export/home/esofthub More About: User , Count , Account , Delete
Modify a User Account via passmgmt
2007-06-17 14:19:00 You can modify a user account with passmgmt. In this example, I'm modifying the comment field. Here's a before and after look.# more /etc/passwd | grep esofthubesofthub:x:1006:10:esofthub account:/export/home/esofthub:/bin/csh# passmgmt -m -c "My SysAd Blog" esofthub# more /etc/passwd | grep esofthubesofthub:x:1006:10:My SysAd Blog:/export/home/esofthub:/bin/csh More About: User , Count , Account , Modify , Modi
Add a User Account via passmgmt
2007-06-17 14:07:00 You can use admintool and useradd utilities to add user accounts. But there is another utility called passmgmt that will perform a similar function. However, it will not create a home directory. You will have to do that manually. Here's an example.# passmgmt -a -c "esofthub account" -h /export/home/esofthub -u 1006 -g 10 -s /bin/csh esofthub# pwckesofthub:x:1006:10:esofthub account:/export/home/esofthub:/bin/csh Login directory not found# mkdir -p /export/home/esofthub# chown -R esofthub:staff /export/home/esofthub# pwck esofthub# passwd esofthubNew password:Re-enter new password:passwd (SYSTEM): passwd successfully changed for esofthub# su - esofthubSun Microsystems Inc. SunOS 5.8 Generic Patch October 2001 More About: User , Count , Account
Find the Prime Factors of a Number
2007-06-16 16:45:00 The factor utility finds the prime factors of a number. Here's its syntax.# factor 101101 101# factor 111111 3 37# factor 10001000 2 2 2 5 5 5# factor 999999 3 3 3 37 More About: Find , Factor , Prime , Actor , Rime
Convert Quantities in Standard Scales to Their Equivalents in Other Scales
2007-06-16 11:34:00 The units command can convert a quantity in a standard scale to its equivalent in another scale. It can handle converting feet to meters, miles to kilometers, pounds to kilograms, degrees to radians, grams to ounces, and many more. Here's an example of a few conversions.#unitsyou have: 1inchyou want: cm * 2.540000e+00 / 3.937008e-01you have: 1ftyou want: meter * 3.048000e-01 / 3.280840e+00you have: 1mileyou want: km * 1.609344e+00 / 6.213712e-01you have: 127radianyou want: degrees * 7.276564e+03 / 1.374275e-04you have: 127degreesyou want: radian * 2.216568e+00 / 4.511479e-01you have: 1kmyou want: mile * 6.213712e-01 / 1.609344e+00you have: 1kgyou want: lbs * 2.204623e+00 / 4.535924e-01you have: 1lbsyou want: grams * 4.535924e+02 / 2.204623e-03you have: cyou want: mconformability 2.997925e+08 m/sec 1.000000e+00 myou have: gyou want: mconformability 9.806650e+00 m/sec2 ... More About: Standard , Scales , Convert , Anti , Scale
Clone Primary Partition Table to Second Hard Drive
2007-06-15 12:19:00 A colleague of mine was trying to duplicate the partition table of the primary disk onto the backup hard drive (same size, same brand/model). I mentioned using prtvtoc command to display the Volume Table of Contents and then pipe its output to the fmthard command. Unfortunately, he was already populating the second hard drive via the manual process. At any rate, here's an example.#prtvtoc /dev/rdsk/c1t10d0s2 | fmthard -s - /dev/rdsk/c1t11d0s2 More About: Drive , Clone , Hard , Primary
Display the Internet to Ethernet Address Translation Tables
2007-06-14 16:51:00 Here's an easy way to find the Internet Protocol address that is mapped to a hardware address on a local area network. The ubiquitous arp command outputs this information. Here's an example.#arp -a More About: Ethernet , Tables , Display , The Internet
Disable All Users From Logging Into the System
2007-06-13 15:23:00 There are times when you need to prevent users from logging into the system. Here's a way of doing that.#cat > /etc/nologinThe system is currently unavailable to all users. Please come back later.:wq!Here's the message you will get when you try to login as a user.# loginlogin: esofthubPassword:The system is currently unavailable to all users. Please come back later. More About: System , Users , Stem
Select Fields or Columns Using the cut Command
2007-06-12 12:21:00 Selecting fields and columns is a common task for system administrators. The cut command is an ideal utility for accomplishing this task. Here are examples of its use (selecting disk slices and checking for passwords).#df -k | grep c0 | grep d0s | cut -b16-17s0s3s4s5s7#cut -d: -f1-3 /etc/shadow More About: Columns , Comm , Command , Field , Fields
Display Kernel Statistics with kstat
2007-06-07 15:50:00 The kstat command is a handy command for providing kernel statistics to users. For each matching statistic, it reports the instance, module, name fields and actual values. Here are some examples of its use.#kstat | more#kstat -p | grep cpu#kstat -m cpu_info#kstat -n cpu_stat0#kstat -s dfreeDo a listing#kstat -l | more More About: Display , Statistics , Stat , Kernel
Display Input and Output (I/O) Statistics with iostat
2007-06-06 12:45:00 The input and output (I/O) statistics (iostat) command shows statistics regarding terminal, disk, tape, and CPU activity. I primarily use it in the extended format to monitor CPU and hard disk stats. Here's an example of its use at 3 second intervals.#iostat 3#iostat -ctx 3 More About: Display , Statistics , Stat , Input
Display Virtual Memory Statistics with vmstat
2007-06-05 17:29:00 The virtual memory statistics (vmstat) command shows statistics regarding process, virtual memory, disk, trap, and CPU activity. Frankly speaking, I primarily use it for CPU stats. Here's an example of its use at 3 second intervals.#vmstat 3 More About: Memory , Display , Statistics , Virtual , Memo
Adding and Deleting a Swap File
2007-06-04 17:08:00 On rare occasions, there might be a need to increase your system's swap space via a local file(s) on your filesystem. However, this should only be a temporary situation. Here?s an example on how to set up a 100MB swap file and then delete it.Get a summary of the VM#swap -sCreate the swap file# mkfile 100m /data/myswapAdd the swap#swap -a /data/myswapDo a listing of the added swap space#swap -lGet a summary of the VM#swap -sTo remove the file swap space, do the following:#swap -d /data/myswap#rm /data/myswapVerify swap file allocation was removed#swap -s#swap -l More About: File , Swap
ASCII, HTML and Conversion Tables - Decimal, Hexadecimal, Octal, Binary
2007-06-02 15:29:00 Here are two convenient lookup tables for ASCII and HTML. Also included is a conversion table for decimal, hexadecimal, octal, and binary. The tables are in Spanish and English. More About: Tables , Sion , Html , Conversion , Version
Create a Crontab That Preserves Existing Entries
2007-06-02 12:27:00 I've had a few queries on how to create a new crontab that preserves the existing entries.You will need to ensure that the user making the edits has cron permissions -- check /etc/cron.d/cron.allow and /etc/cron.d/cron.deny. Note: for the first example, you may have to set the EDITOR variable. Here's the syntax.#cd /var/spool/cron/crontabs#crontab -l > esofthub#crontab -e esofthubmake your edits:wq!OR#vi esofthubmake your edits:wq!#crontab esofthubFYI: What do the six fields meanminute 1-60hour 0-23day of month 1-31month of year 1-12day of week 0-6 (zero is Sunday)Your edit/addition/scriptThe following entry will kick off every minute* * * * * echo "I'm kicked off every minute" More About: That , Create , Exist , Preserves , Reserves
Download Solaris 10 Operating System at no Cost
2007-06-01 11:58:00 Get access to Solaris 10 software, the most advanced operating system on the planet -- at no charge.Join the Free Solaris ProgramGet the following free:Solaris 10 Download or Free Software KitSolaris 10 Entitlement DocumentSolaris How to GuidesAccess to Solaris Learning Centersand more... More About: System , Operating System , Cost
Convert Decimal to Hexadecimal, Octal or Binary using typeset
2007-05-31 15:27:00 Here's a quick and dirty way of converting a decimal number to hexadecimal, octal, or binary. Below is an inline script followed by a normal shell script file.#ksh# for i in 100 102 103 104 105 110 1000> do>> typeset -i16 hex> hex=$i> print $i equals $hex in hexadecimal>> typeset -i8 oct> oct=$i> print $i equals $oct in octal>> typeset -i2 bin> bin=$i> print $i equals $bin in binary>>print> done 100 equals 16#64 in hexadecimal100 equals 8#144 in octal100 equals 2#1100100 in binary 102 equals 16#66 in hexadecimal102 equals 8#146 in octal102 equals 2#1100110 in binary 103 equals 16#67 in hexadecimal103 equals 8#147 in octal103 equals 2#1100111 in binary 104 equals 16#68 in hexadecimal104 equals 8#150 in octal104 equals 2#1101000 in binary 105 equals 16#69 in hexadecimal105 equals 8#151 in octal105 equals 2#1101001 in binary 110 equals 16#6e in hexadecimal110 equals 8#156 in octal110 equals 2#1101110 in binary 1000 equals 16#3e8 in hex... More About: Convert , Types , Cima , Vert
Calculate with the Basic Calculator -- bc
More articles from this author:2007-05-30 15:44:00 You can do simple command line calculations with the basic calculator, bc, such as add, subtract, multiply, division, modulus, sqrt, raise a number to a power, logarithms, exponential, compute sines, cosines, loops, functions, and more. Here are some really basic examples -- scale was used to represent precision. I have used the bc command while in the single user mode.#bc12-12012+122412*1214412/121scale= 312/121.00012%1202^38sqrt(12)3scale=3sqrt (12)3.46422/73scale=622/73.142857scale=10 22/73.1428571428 More About: Calculator , Basic , Late , Calculate 1, 2, 3, 4, 5, 6, 7 |



