Vous êtes sur la page 1sur 39

11/26/13

Linux & Shell Script

Linux & Shell Script


What is UMASK? When user creates a file or directory it will be created with permission. The default value is 022. If we create a file or directory the file will be created with 755 permission. the calculation is the difference between 777 and the umask value. ie. 777-022=755. If umask is 022 then Owner will have read, write, execute permissions Group will have read, execute permissions Others will have read, execute permissions How will you delete last ten days records in OS level? $ find . mtime -10 exec rm {} \ What is RPM? How will you install RPMS? RPM Package Manager (originally Red Hat Package Manager, abbreviated RPM) is a package management system. $ rpm -Uvh rpmname.rpm How will you find how many users were connected to a database named sss from linux level? ps ef|grep i local|grep sss How will you get the count of all arguments that is passed in a Shell script? echo $# How to check whether the last command executed successfully or not? Echo$? if the result is 0(zero) then the command is successfully executed else if the number is from 1 to 255 it is failed. From Linux how will you find how many users were connected to the database sakthi? ps -ef|grep -i local|grep -i sakthi|wc -l How will you view Alertlog file from different directory? tail -f /home/oracle/db/bdump/alertlog.log How will you see all the arguments in shell script? echo $* How will you configure host name and ipaddress? Connect to root user and use neat command to add the hostname and ipaddress. Then restart the network service using # service network restart In /etc/hosts add the ipaddress and hostname. How will execute a shell script in background?
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 1/39

11/26/13

Linux & Shell Script

./script.sh & or nohup ./script.sh & which will create a nohup.out in the current directory. Where will you find the OS level errors In /var/log/messages and $ dmesg How to view last 15 lines of a file? $Tail -15 filename How to copy a folder from one server to another First compress the folder using tar command $tar -zcvf directory_name.tar.gz directory_name Scp oracle@192.168.1.140:/home/sss/directory_name.tar.gz oracle@192.168.1.130:/home/oracle/sss/ or using FTP you can transfer a file or using third party utilities like winscp, Wsftp etc. How to edit the crontab? How will you schedule on a file January 26 10:30 am? crontab -e Edit your crontab file, or create one if it doesnt already exist. crontab -l Display your crontab file. crontab -r Remove your crontab file. crontab -v Display the last time you edited your crontab file Jan 26 10:30 am assign one job in crontab 30 10 26 1 * . text.sh How to find the size of a directory and a file? $du sh directory_name $ls -lrth filename How will you find the modified the files in a home directory? $find $HOME type f mtime 0 $find ~ type f mtime 0 What is Chmod R? chmod -R 755 directory (-R set permissions recursively , ie changes the permission to current directory,sub direstory and files) How will you find obsolete path of sqlplus? $which sqlplus $type sqlplus What are the Compress commands? Gzip Zip
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 2/39

11/26/13

Linux & Shell Script

Tar Compress cpio Add two numbers in a shell script? Echo `expr $1 + $2`arguments we pass two values echo $*list of arguments echo $#-total number of count echo $0output first word How will you solve filename.sh permission denied in linux ? $ chmod +x filename.sh What will happen when you execute root.sh? Its used to create /etc/oratab file Set the environment variables (ORACLE_OWNER,ORACLE_HOME) Intimate the environment variables to bin. How do you see how many instancesare running in Linux? ps -ef|grep pmon|grep -v grep|wc -l Given an error number, how will you see description of the error and action in OS level? oerr ora 0060 00060, 00000, deadlock detected while waiting for resource // *Cause: Transactions deadlocked one another while waiting for resources. // *Action: Look at the trace file to see the transactions and resources // involved. Retry if necessary. What is SAR? (System activity report) ? The sar (system activity reporter) command is useful for displaying both current and historical processor load. Use sar with the -u option to report on CPU statistics. By default, sar will report on the current days activities: $ sar -u To report on the previous days worth of CPU statistics, use the -f option. The files that sar uses to report on statistics for different days of the month are located in the /var/log/sa directory and have the naming convention of saNN,where NN is the two-digit day of the month. For example, to have sar display CPU statistics for the tenth day of the month, run it as follows: $ sar -u -f /var/log/sa/sa10 02:40:01 PM CPU %user %nice %system %iowait %idle 02:50:01 PM all 0.22 0.00 0.24 0.00 99.54 03:00:01 PM all 0.22 0.00 0.24 0.00 95.53 03:10:01 PM all 0.22 0.00 0.23 0.00 99.55 03:20:01 PM all 0.42 0.00 1.06 2.11 96.41 03:30:01 PM all 0.24 0.00 1.22 0.01 92.54 Average: all 0.19 0.00 0.19 0. 07 99.55 The columns in the prior output have the same meaning as the mpstat output A low %idle could be an indication that the CPUs are underpowered or indicative of a high application load. $ sar -u 2 20 To use sar to report on the current days CPU activity, simply specify the -u option:
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 3/39

11/26/13

Linux & Shell Script

$ sar -u To use sar to report on a previous day in the month, use the -f option. See the examples in the Solution section of this recipe for techniques for reporting on a previous days statistics. If you have multiple CPUs, you can view the output per CPU with the -P ALL options. You should now see one line per CPU in the output: $ sar -u -P ALL Here is a partial listing of the output: 04:30:01 PM 0 0.10 0.00 0.01 0.00 99.99 04:30:01 PM 1 0.11 0.00 0.01 0.00 99.98 To display paging activity: sar -B 3 100 To display swapping activity: sar -W 3 100 To display block I/O activity: sar -b 3 100 To display block I/O activity for each block device: sar -d 3 100 To display network activity: sar -n DEV 3 100 How will you remove memory segment in linux? There are two instances currently running [oracle@sss-oracle ~]$ ps -ef|grep pmon oracle 4772 1 0 11:12 ? 00:00:00 ora_pmon_test oracle 2753 1 0 14:12 ? 00:00:00 ora_pmon_sakthi oracle 13149 13009 0 15:54 pts/1 00:00:00 grep pmon use $ipcs to view the memory segments [oracle@sss-oracle ~]$ ipcs Shared Memory Segments key shmid owner perms bytes nattch status 000000000 3375105 oracle 600 393216 2 dest 000000000 3407875 oracle 600 393216 2 dest 000000000 3440644 oracle 600 393216 2 dest 000000000 3473413 oracle 600 393216 2 dest 000000000 3506182 oracle 600 393216 2 dest 000000000 3899399 oracle 600 393216 2 dest 000000000 3571720 oracle 600 393216 2 dest 000000000 3604489 oracle 600 393216 2 dest 000000000 3637258 oracle 600 393216 2 dest 0x0a2b21c4 3702795 oracle 660 633339904 21 051417090 3768332 oracle 640 289406976 15 Semaphore Arrays key semid owner perms nsems 0x4c0bf348 229376 oracle 660 104 0xa70c84e8 360449 oracle 640 154 Message Queues key msqid owner perms used-bytes messages [oracle@sss-oracle ~]$ sysresv -l sakthi
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 4/39

11/26/13

Linux & Shell Script

IPC Resources for ORACLE_SID sakthi : Shared Memory: ID KEY 3768332 051417090 Semaphores: ID KEY 360449 0xa70c84e8 Oracle Instance alive for sid sakthi [oracle@sss-oracle ~]$ ipcrm -s 360449 The memory segment is removed. [oracle@sss-oracle ~]$ ps -ef|grep pmon oracle 4772 1 0 11:12 ? 00:00:00 ora_pmon_test oracle 13149 13009 0 15:54 pts/1 00:00:00 grep pmon How will you create a swap size in your environment? And how will you find free space in swap and RAM in your environment? To find RAM size [oracle@sss-oracle ~]$ grep MemTotal /proc/meminfo MemTotal: 1035064 kB [oracle@sss-oracle ~]$ grep SwapTotal /proc/meminfo SwapTotal: 2097144 kB [oracle@sss-oracle ~]$ free -l total used free shared buffers cached Mem: 1035064 867052 168012 0 89100 592468 Low: 904056 761404 142652 High: 131008 105648 25360 -/+ buffers/cache: 185484 849580 Swap: 2097144 820 2096324 If youre short on swap space, you can temporarily add a swap file to your server. As the root user, run the following commands to add approximately 1GB of swap space: # dd if=/dev/zero of=tempswap bs=1k count=1000000 # chmod 600 tempswap # mkswap tempswap # swapon tempswap Verify that the swap space was added with the -s option of the swapon command: # swapon -s To remove the temporary swap file, as root run the following commands: # swapoff tempswap # rm tempswap After disabling the swap file, you should see the swap space in /proc/meminfo return to its original value.

How will you print the 25th line in your file? $ cat -n filename|grep 25 or $ head -25 filename | tail -1
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 5/39

11/26/13

Linux & Shell Script

Write a shell script to check diskspace/mountpoint limit # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #c h e c k _ F S . s h # #S c r i p tf o rc h e c k i n gm o u n t p o i n ts p a c eb yp a s s i n gt h r e s h o l dl i m i ta sa r g u m e n t # # F r o mS a k t h iS o f t w a r eS o l u t i o n sP v tL t d # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # f o rii n` d fP | g r e pv" F i l e " | t rs""" ~ " | c u td " ~ "f 5 | t rs" % """ ` d o i f[$ ig t$ 1] t h e n e c h o$ i f i d o n e

OR # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #c h e c k _ F S . s h # #S c r i p tf o rc h e c k i n gm o u n t p o i n ts p a c eb yp a s s i n gt h r e s h o l dl i m i ta sa r g u m e n t # # F r o mS a k t h iS o f t w a r eS o l u t i o n sP v tL t d # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # f o rii n` d fh | g r e pv" F i l e " | a w k{ " p r i n t$ 5 " } | t rs" % """ ` d o i f[$ ig t$ 1] t h e n e c h o$ i f i d o n e OUTPUT : [ o r a c l e @ s s s o r a c l e~ ] $d fh F i l e s y s t e m S i z e U s e dA v a i lU s e %M o u n t e do n / d e v / m a p p e r / V o l G r o u p 0 0 L o g V o l 0 0 1 8 G 1 3 G 3 . 7 G 7 8 %/ / d e v / s d a 1 9 9 M 1 2 M 8 2 M 1 3 %/ b o o t


oracle-12c.blogspot.in/2012/03/linux-shell-script.html 6/39

11/26/13

Linux & Shell Script

t m p f s / d e v / s d b 1 . h o s t : /

5 0 6 M 0 5 0 6 M 0 %/ d e v / s h m 2 0 G 1 5 G 4 . 6 G 7 6 %/ u 0 2 2 0 2 G 1 5 6 G 4 6 G 7 8 %/ m n t / h g f s

[ o r a c l e @ s s s o r a c l e~ ] $. / c h e c k _ F S . s h2 0 7 8 7 6 7 8 With sendmail OPTION ############################################################## ######### # # check_FS.sh # # Script for checking mountpoint space by passing threshold limit as argument # #From Sakthi Software Solutions Pvt Ltd # ############################################################### ########## for i in `df -P|grep -v "File"|tr -s " " "~"|cut -d"~" -f5|tr -s "%" " "` do if [ $i -gt $1 ] then echo "date: `date`" > /tmp/check_FS.log echo "to: test@oraclehost.oracledomain" >> /tmp/check_FS.log echo "subject: WARNING! - FileSystem" >> /tmp/check_FS.log #echo "from: `hostname`" >> /tmp/check_FS.log echo "" >>/tmp/check_FS.log echo " Filesystem Threshold Check : " >> /tmp/check_FS.log echo " ----------------------------- " >> /tmp/check_FS.log echo "" >>/tmp/check_FS.log echo "" >>/tmp/check_FS.log echo `df -h |grep $i%` >> /tmp/check_FS.log /usr/sbin/sendmail -t test@oraclehost.oracledomain < /tmp/check_FS.log fi done crontab -l # check for every 5 minutes with threshold value 90 */5 * * * * /home/oracle/scripts/check_FS.sh 90

Write a shell script to check analyzed objects


oracle-12c.blogspot.in/2012/03/linux-shell-script.html 7/39

11/26/13

Linux & Shell Script

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #c h e c k _ a n a l y z e . s h # #S c r i p tf o rc h e c k i n ga n a l y z e do b j e c t s # #F r o mS a k t h iS o f t w a r eS o l u t i o n sP v tL t d # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # f o rii n` e c h o$ * ` d o e c h o"" e c h o"" e c h o" -A n a l y z e ds t a t u so f $ i " e c h o"" e c h o"" s q l p l u ss/ n o l o g< < E O F c o n n/a ss y s d b a s e l e c tt a b l e _ n a m e , l a s t _ a n a l y z e df r o md b a _ t a b l e sw h e r eo w n e r = u p p e r ( ' $ i ' ) ; e x i t E O F d o n e output: [ o r a c l e @ s s s o r a c l e~ ] $. / c h e c k _ a n a l y z e . s ht e s ts c o t t

-A n a l y z e ds t a t u so f t e s t

T A B L E _ N A M E L A S T _ A N A L -A

-A n a l y z e ds t a t u so f s c o t t

T A B L E _ N A M E
oracle-12c.blogspot.in/2012/03/linux-shell-script.html

L A S T _ A N A L
8/39

11/26/13

Linux & Shell Script

-D E P T 3 0 A U G 1 2 E M P 3 0 A U G 1 2 B O N U S 3 0 A U G 1 2 S A L G R A D E 3 0 A U G 1 2 B 3 0 A U G 1 2

Write a shell script to analyze schema

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #a n a l y z e . s h # #S c r i p t st oa n a l y z es c h e m a / s,w h e r es c h e m an a m ei sp a s s e da sa r g u m e n t # #F r o mS a k t h iS o f t w a r eS o l u t i o n sP v tL t d # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # f o rii n` e c h o$ * ` d o e c h o"" e c h o"" e c h o" -A n a l y z i n gs c h e m a $ i " e c h o"" e c h o"" s q l p l u ss/ n o l o g< < E O F c o n n/a ss y s d b a e x e cd b m s _ s t a t s . g a t h e r _ s c h e m a _ s t a t s ( ' $ i ' ) ; e x i t E O F d o n e Output :

$. / a n a l y z e . s hs c o t tt e s t -A n a l y z i n gs c h e m as c o t t -

P L / S Q Lp r o c e d u r es u c c e s s f u l l yc o m p l e t e d .

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

9/39

11/26/13

Linux & Shell Script

-A n a l y z i n gs c h e m a t e s t

P L / S Q Lp r o c e d u r es u c c e s s f u l l yc o m p l e t e d .

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #U s a g e:. / c h e c k _ d b . s h # #S c r i p tf o rc h e c k i n gs t a t u so fd a t a b a s e si nas e r v e r # #F r o mS a k t h iS o f t w a r eS o l u t i o n sP v tL t d # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # f o rii n` p se f | g r e pp m o n|a w k' { p r i n t$ 8 } ' | g r e pv" g r e p " | c u td " _ "f 3 ` d o e x p o r tO R A C L E _ S I D = $ i s q l p l u ss/ n o l o g< < E O F> / t m p / t e m p . s q l s e th e a do f fe c h oo f f c o n n/a ss y s d b a s e l e c td e c o d e ( o p e n _ m o d e , ' R E A DW R I T E ' , ' O P E N ' , ' M O U N T ' )f r o mv \ $ d a t a b a s e ; e x i t E O F f o rxi n` c a t/ t m p / t e m p . s q l| e g r e p" O P E N | M O U N T | O R A 0 1 5 0 7 " | g r e pv" ^ s e l " | a w k{ ' p r i n t $ 1 } ' ` d o i f[" $ x "=" O R A 0 1 5 0 7 : "] t h e n e c h o" D a t a b a s e$ ii nN O M O U N Ts t a g e " e l s e e c h o " D a t a b a s e$ ii n$ xs t a g e " f i d o n e r m/ t m p / t e m p . s q l d o n e

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

10/39

11/26/13

Linux & Shell Script

O U T P U T: [ o r a c l e @ s s s o r a c l e~ ] $p se f | g r e pp m o n o r a c l e 6 0 6 1 1 01 6 : 1 0? 0 0 : 0 0 : 0 0o r a _ p m o n _ s s s o r a c l e 1 6 6 8 2 1 02 1 : 0 4? 0 0 : 0 0 : 0 0o r a _ p m o n _ s a k t h i o r a c l e 1 6 7 5 8 7 8 2 1 02 1 : 0 5p t s / 1 0 0 : 0 0 : 0 0g r e pp m o n

[ o r a c l e @ s s s o r a c l e~ ] $. / c h e c k _ d b . s h D a t a b a s es s si nO P E Ns t a g e D a t a b a s es a k t h ii nN O M O U N Ts t a g e

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
A b o u tL i n u xF i l es y s t e m

/-t h et o p m o s t / d e v-a l lt h ed e v i c e sa r ea c c e s s i b l ea sf i l e s / v a r- v a r i a b l e d a t as u c ha sm a i l s ,l o gf i l e s ,d a t a b a s e s / u s r-a l m o s ta l lt h ep a c k a g e si n s t a l l e d / e t c-c o n f i g u r a t i o nf i l e s / h o m e-h o m ed i r e c t o r i e sf o ra l lt h eu s e r s / r o o t-h o m ed i r e c t o r yo ft h ep r i v i l e g e du s e rr o o t / m n t-u s e dt om o u n to t h e rd i r e c t o r i e s / p a r t i t i o n s

C o m p r e s s i o n t a rc v f ,t v f ,x v f ,z c v f ,z x v f z i pr c o m p r e s s gzip b a c k g r o u n dj o b s n o h u p f gj o b s j o b s b gj o b s S y s t e ml o gc o m m a n d s
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 11/39

11/26/13

Linux & Shell Script

D m e s g C a t v a r / l o g / m e s s a g e s O t h e rC o m m a n d s p w d c a lm o n t hy e a r c l e a r s l e e p2 d a t e a l i a s u n a l i a s U s e ra n dP r o c e s s F r e e K i l l M a i l M a n P i n g R e b o o t S h u t d o w n hn o w S h u t d o w n rm i n u t e s s y n c-c o m p l e t e sa l lp e n d i n gI / OO p e r a t i o n s t e l n e t t o p t r a c e r o u t eh o s t u p t i m e w-c u r r e n ts y s t e mu s e r s s u p a s s w d w h o w a l l-s e n d sm e s s a g et ou s e r s p s e f ,a u x ,u s s h f d i s k m o u n t u m o u n t d u d f q u o t a r e b o o t p o w e r o f f #u s e r a d dc h u c k #p a s s w dc h u c k #u s e r d e lrc h u c k


oracle-12c.blogspot.in/2012/03/linux-shell-script.html 12/39

11/26/13

Linux & Shell Script

Who -r V i e w i n gc o m m a n d s l sl l sa l sl r t l sd

l s Ao p t i o nm a k e sl ss h o wf i l e sb e g i n n i n gw i t h.b u te l i m i n a t e st h e.a n d. .f i l e sf r o mt h ed i s p l a y .

to p t i o ni su s e dt os o r tt h eo u t p u to fl sb yt h et i m et h ef i l ew a sm o d i f i e d

uo p t i o nw i l lg i v et h et i m et h ef i l ew a sl a s tu s e do ra c c e s s e d . So p t i o nd i s p l a y sf i l e sb yt h e i rs i z e ,i nd e s c e n d i n go r d e r .

ro p t i o nr e v e r s e st h ed i s p l a y ,s o r t i n gs i z e si na s c e n d i n go r d e r . O w n e r s h i p / P e r m i s s i o nc o m m a n d s u m a s k c h o w nR c h m o d7 7 7 c h m o d+ t F i l eS e a r c hc o m m a n d s l o c a t e w h e r e i s w h i c h f i n d p a t hn a m ep r i n te x e c m t i m e W i l dC r a dc h a r a c t e r s * , ? E c h o G r e p l r ,v,i

F i n d i n gf i l e so l d e rt h a n2 0y e a r s

#f i n d. /m t i m e+ 7 3 0 0

F i n d i n gA n yF i l e sM o d i f i e di nt h eP a s t3D a y s

$f i n d. /m t i m e3
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 13/39

11/26/13

Linux & Shell Script

F i n d i n g. t x tF i l e sM o d i f i e di nt h eP a s t3D a y s

$f i n d.n a m e' * . t x t 'm t i m e3

F i n d i n gF i l e sL a r g e rt h a n1 0 , 0 0 0 k

#f i n d.s i z e+ 1 0 0 0 0 k

D e l e t i n gF i l e sU s i n gF i l eP r o p e r t i e s t od e l e t ea l lf i l e sw i t h i nad i r e c t o r yt h a th a v en o tb e e nu s e do ra c c e s s e di nm o r et h a n3 0d a y s $f i n d. m a x d e p t h1a t i m e+ 3 0e x e cr m{ }\ ;

D i r e c t o r yc o m m a n d s m k d i r m k d i rp( c r e a t et h ed i r e c t o r i e sa sm e n t i o n e dr e c u r s i v e l y ) r mr f r mi r m d i r c d. . c d~ c d

F i l eM a n i p u l a t i o n m v c p c pi( c h e c k se x i s t a n c eo ff i l e s ) c pd ( l i n k s ) p ( p e r m i s s i o n s )r ( r e c u r s i v e c a t c a t> c a t> > m o r e l e s s c m pf 1f 2 c o m mf 1f 2 d i f ff 1f 2 d i f fy q-s a y sw h e t h e rd i f f e r e n c eo rn o tb u tn o th o w r i w clc w


oracle-12c.blogspot.in/2012/03/linux-shell-script.html 14/39

11/26/13

Linux & Shell Script

l n s f i l e -d e s c r i b e st h ef i l et y p e s s c p s p l i tf i l e c u tc ,d" "f 1 s o r t r , t , n s o r tt "" k2( s o r t st h ef i l eb a s e do nt h es e c o n df i e l du s i n gt h ed e l i m i t e ra ss p a c e ) p a s t ef 1f 2

O t h e ri m p o r t a n tc o m m a n d s W h a ti sX a r g s ? X a r g s Most Linux commands are about getting an output: a list of files, a list of strings, and so on. But what if you want to use some other command with the output of the previous one as a parameter? For example, the f i l ecommand shows the type of the file (executable, ascii text, and so on); you can manipulate the output to show only the filenames and now you want to pass these names to the l slcommand to see the timestamp. The command x a r g sdoes exactly that. It allows you to execute some other commands on the output. Remember this syntax from Part 1: f i l eL z*|g r e pA S C I I|c u td " : "f 1|x a r g sl sl t r Let's dissect this command string. The first, f i l eL z* , finds files that are symbolic links or compressed. It passes the output to the next command, g r e pA S C I I , which searches for the string "ASCII" in them and produces the output similar to this: a l e r t _ D B A 1 0 2 . l o g : a l e r t _ D B A 1 0 2 . l o g . Z : A S C I IE n g l i s ht e x t A S C I It e x t( c o m p r e s s ' dd a t a1 6b i t s )

d b a 1 0 2 _ a s m b _ 1 2 3 0 7 . t r c . Z :A S C I IE n g l i s ht e x t( c o m p r e s s ' dd a t a1 6b i t s ) d b a 1 0 2 _ a s m b _ 2 0 6 5 3 . t r c . Z :A S C I IE n g l i s ht e x t( c o m p r e s s ' dd a t a1 6b i t s ) Since we are interested in the file names only, we applied the next command, c u td " : "f 1 , to show the first field only: a l e r t _ D B A 1 0 2 . l o g a l e r t _ D B A 1 0 2 . l o g . Z d b a 1 0 2 _ a s m b _ 1 2 3 0 7 . t r c . Z d b a 1 0 2 _ a s m b _ 2 0 6 5 3 . t r c . Z Now, we want to use the l slcommand and pass the above list as parameters, one at a time. The x a r g scommand allowed you to to that. The last part, x a r g sl sl t r , takes the output and executes the command l sl t ragainst them, as if executing: l sl t ra l e r t _ D B A 1 0 2 . l o g l sl t ra l e r t _ D B A 1 0 2 . l o g . Z l sl t rd b a 1 0 2 _ a s m b _ 1 2 3 0 7 . t r c . Z l sl t rd b a 1 0 2 _ a s m b _ 2 0 6 5 3 . t r c . Z Thus x a r g sis not useful by itself, but is quite powerful when combined with other commands.

S ow h a td o e sl o a da v e r a g ef r o mt o pc o m m a n d i n d i c a t e ? l o a da v e r a g e s :2 . 4 3 ,2 . 9 6 ,3 . 4 1
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 15/39

11/26/13

Linux & Shell Script

o n em i n u t el o a da v e r a g ei s2 . 4 3 f i v em i n u t ei s2 . 9 6 f i f t e e nm i n u t el o a da v e r a g ei s3 . 4 1 . H e r ea r es o m ec o n c l u s i o n sw ec a nd r a wf r o mt h i s . O na v e r a g e ,o v e rt h ep a s to n em i n u t et h e r eh a v eb e e n2 . 4 3p r o c e s s e sr u n n i n go rw a i t i n gf o rar e s o u r c e O v e r a l lt h el o a di so nad o w n t r e n ds i n c et h ea v e r a g en u m b e ro fp r o c e s s e sr u n n i n go rw a i t i n gi nt h ep a s tm i n u t e ( 2 . 4 3 )i sl o w e rt h a nt h ea v e r a g er u n n i n go rw a i t i n go v e rt h ep a s t5m i n u t e s( 2 . 9 6 )a n d1 5m i n u t e s( 3 . 4 1 ) T h i ss y s t e mi sb u s y ,b u tw ec a n n o tc o n c l u d eh o wb u s ys o l e l yf r o ml o a da v e r a g e s . I ti si m p o r t a n th e r et om e n t i o nt h a tt h el o a da v e r a g ed o e sn o tt a k ei n t oa c c o u n tt h en u m b e ro fp r o c e s s e s .A n o t h e r c r i t i c a ld e t a i li st h a tp r o c e s s e sc o u l db ew a i t i n gf o ra n yn u m b e ro ft h i n g si n c l u d i n gC P U ,d i s k ,o rn e t w o r k . S ow h a tw ed ok n o wi st h a tas y s t e mt h a th a sal o a da v e r a g es i g n i f i c a n t l yh i g h e rt h a nt h en u m b e ro fC P U si s p r o b a b l yp r e t t yb u s y ,o rb o g g e dd o w nb ys o m eb o t t l e n e c k .C o n v e r s e l yas y s t e mw h i c hh a sal o a da v e r a g es i g n i f i c a n t l y l o w e rt h a nt h en u m b e ro fC P U si sp r o b a b l yd o i n gj u s tf i n e .

W h a ti ss t i c k yb i t ? U s e df o rs h a r e dd i r e c t o r i e st op r e v e n tu s e r sf r o mr e n a m i n go rd e l e t i n ge a c ho t h e r s f i l e s . T h eo n l yu s e r sw h oc a n r e n a m eo rd e l e t ef i l e si nd i r e c t o r i e sw i t ht h es t i c k yb i ts e ta r et h ef i l eo w n e r ,t h ed i r e c t o r yo w n e r ,o rt h e s u p e r u s e r( r o o t ) . T h es t i c k yb i ti sr e p r e s e n t e db yt h el e t t e rti nt h el a s tp o s i t i o no ft h eo t h e rp e r m i s s i o n s d i s p l a y . S U I D

S e tu s e rI D ,u s e do ne x e c u t a b l ef i l e st oa l l o wt h ee x e c u t a b l et ob er u na st h ef i l eo w n e ro ft h ee x e c u t a b l er a t h e r t h a na st h eu s e rl o g g e di n t ot h es y s t e m . S G I D S e tg r o u pI D ,u s e do ne x e c u t a b l ef i l e st oa l l o wt h ef i l et ob er u na si fl o g g e di n t ot h eg r o u p( l i k eS U I Db u tu s e s f i l eg r o u pp e r m i s s i o n s ) . $c h m o d+ tp u b l i c o r $c h m o d1 7 7 7p u b l i c w h e r et h eS U I Da n dS G I Do p t i o n sc o m ei n . c h m o du + s , g + sd r o p _ b o x o r
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 16/39

11/26/13

Linux & Shell Script

c h m o d6 7 7 7d r o p _ b o x

F i n d i n gP r o c e s sI n f o r m a t i o nb yP r o c e s sI D $p su4 4 4 4 F i n dP r o c e s s e sB e l o n g i n gt oaS p e c i f i cU s e r $p sub b

H o ww i l ly o uf i n dC P Uu s a g ea n dw h a tw i l ly o us e ei nt h a t ? Display the Most Active Processes T h et o pc o m m a n dp r o v i d e sad y n a m i cd i s p l a yo ft h ec u r r e n ta c t i v i t yw i t h i naL i n u xs y s t e m . B yd e f a u l tt o pw i l ll i s t r u n n i n gp r o c e s s e so w n e db ya l lu s e r s . T h ep r o c e s s e sw h i c ha r ec u r r e n t l yu s i n gt h em o s tC P Ua r el i s t e df i r s ta n d t o pw i l ll i s ta sm a n yp r o c e s s e sa sw i l lf i to nt h es c r e e n . $t o p t o p-2 2 : 5 8 : 2 8u p 4 : 4 9 , 2u s e r s , l o a da v e r a g e :0 . 0 3 ,0 . 0 8 ,0 . 0 5 T a s k s : 7 9t o t a l , M e m : S w a p : 1r u n n i n g , 7 8s l e e p i n g , 5 . 6 %s y s t e m , 2 3 8 2 0 8 ku s e d , 0 ku s e d , 0s t o p p e d , 0z o m b i e 2 3 4 6 0 kb u f f e r s 9 6 4 0 0 kc a c h e d C p u ( s ) : 2 2 . 3 %u s e r , 2 5 5 6 5 6 kt o t a l , 5 0 6 0 0 8 kt o t a l , 0 . 0 %n i c e , 7 2 . 1 %i d l e 1 7 4 4 8 kf r e e , 5 0 6 0 0 8 kf r e e ,

P I DU S E R 1 8 3 2 5r o o t 2 1 2 3 4t e r r y 1 1 7 8 4r o o t 1r o o t 2r o o t 3r o o t 4r o o t 5r o o t 6r o o t 7r o o t 8r o o t 1 2r o o t 1 3 2 8 2r o o t 1 4 3 0 1r o o t 8 2 3 5r o o t 1 3 0 1 6r p c 1 8 6 7r o o t 9 0 3 8r o o t 2 7 9 2 0x f s 4 9 1 8r o o t 3 1 9 8 2d a e m o n

P R N I V I R T R E S S H RS% C P U% M E M 1 7 1 2 1 4 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 04 1 5 2 4 1 6 m1 9 5 2S2 3 . 6 6 . 5 01 0 6 4 8 1 0 m7 1 8 0S 2 . 6 4 . 2 0 0 0 0 0 0 0 0 0 0 0 0 0 9 8 4 9 8 4 7 7 2R 1 . 6 0 . 4 5 0 0 5 0 0 4 4 8S 0 . 0 0 . 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0S 0 . 0 0 . 0 0S 0 . 0 0 . 0 0S 0 . 0 0 . 0 0S 0 . 0 0 . 0 0S 0 . 0 0 . 0 0S 0 . 0 0 . 0 0S 0 . 0 0 . 0 0S 0 . 0 0 . 0 0S 0 . 0 0 . 0 0S 0 . 0 0 . 0

T I M E + C o m m a n d 5 : 1 0 . 9 9X 0 : 3 3 . 2 0g n o m e t e r m i n a l 0 : 0 0 . 4 6t o p 0 : 0 5 . 1 2i n i t 0 : 0 0 . 0 6k e v e n t d 0 : 0 0 . 1 5k a p m d 0 : 0 0 . 0 0k s o f t i r q d _ C P U 0 0 : 0 0 . 0 0k s w a p d 0 : 0 0 . 0 0b d f l u s h 0 : 0 0 . 1 4k u p d a t e d 0 : 0 0 . 0 0m d r e c o v e r y d 0 : 0 0 . 3 3k j o u r n a l d 0 : 0 0 . 0 0k h u b d 0 : 0 0 . 0 0k j o u r n a l d 0 : 0 0 . 0 0d h c l i e n t 0 : 0 0 . 0 1p o r t m a p 0 : 0 0 . 2 5s y s l o g d 0 : 0 0 . 3 2k l o g d 0 : 0 0 . 2 5x f s 0 : 0 0 . 1 8g d m b i n a r y 0 : 0 0 . 0 0a t d
17/39

1 8 1 9

12 0

9 6 8 9 6 8 6 9 6S 0 . 0 0 . 4 5 3 6 5 3 6 4 6 4S 0 . 0 0 . 2 6 2 4 6 2 4 5 2 0S 0 . 0 0 . 2

0 1 3 1 21 3 1 2 4 3 6S 0 . 0 0 . 5 0 3 7 2 43 7 2 4 9 5 2S 0 . 0 1 . 5 0 3 0 9 63 0 9 62 9 5 2S 0 . 0 1 . 2 0 5 0 4 5 0 4 4 4 4S 0 . 0 0 . 2

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

11/26/13

Linux & Shell Script

1 4 6 6 6r o o t 1 4 7 4 4r o o t 1 8 5 8 8r o o t 2 2 9 6 9r o o t 2 4 0 2 0l p 2 2 0 8 1r o o t 1 7 1 9 7r o o t 2 9 9 2 1r o o t 2 7 8 0 8l p

9 9 9 9 9 9 9 9 9

0 1 3 6 01 3 6 01 1 4 8S 0 . 0 0 . 5 0 8 7 6 8 7 6 7 5 6S 0 . 0 0 . 3 0 4 1 6 04 1 6 03 7 2 8S 0 . 0 1 . 6 0 2 0 4 02 0 4 01 2 9 6S 0 . 0 0 . 8 0 4 2 3 24 2 3 23 7 5 6S 0 . 0 1 . 7 0 2 3 3 22 3 3 21 1 6 4S 0 . 0 0 . 9 0 0 4 5 2 4 5 2 4 1 6S 0 . 0 0 . 2 5 5 2 5 5 2 5 0 8S 0 . 0 0 . 2

0 : 0 0 . 1 4s s h d 0 : 0 0 . 0 2x i n e t d 0 : 0 0 . 8 4g d m b i n a r y 0 : 0 1 . 0 8c u p s d 0 : 0 7 . 7 2f o o m a t i c r i p 0 : 0 0 . 5 8s m b 0 : 0 0 . 0 0r w h o d 0 : 0 0 . 0 7r w h o d 0 : 0 0 . 0 1f o o m a t i c r i p

0 4 2 3 64 2 3 64 0 5 6S 0 . 0 1 . 7

O n c ey o ua r ed o n ei nt o py o uj u s tn e e dt ot y p eqt oq u i ta n dr e t u r nt ot h ec o m m a n dl i n e . H e r ew es e et h ed e f a u l tt o po u t p u t . T h e r e ' sal o th e r e ,b u th e r ea r eaf e wo ft h eh i g h l i g h t s . S o m eo ft h i sw i l l b ef a m i l i a rf r o mt h ep so u t p u t . top output field u p Description H o wl o n gt h i ss y s t e mh a sb e e nr u n n i n g . M a yb ei n d a y s u s e r s l o a da v e r a g e N u m b e ro fc o n n e c t e du s e r s N u m b e ro fp r o c e s s e sc u r r e n t l yr u n n i n gp l u st h en u m b e r w a i t i n gt or u no v e ro n e ,f i v ea n df i f t e e nm i n u t e s * .

T a s k s( o rp r o c e s s e s ) C P U s y s t e m i o w a i t( n o ts h o w n ) T h ep e r c e n to fC P Uc o n s u m e db yu s e rp r o c e s s e s

T h et o t a ln u m b e ro fa c t i v ep r o c e s s e s u s e r i d l e H o wt h eC P Ui sc u r r e n t l yb e i n gu s e d T h ep e r c e n to fC P Uc o n s u m e db ys y s t e mp r o c e s s e s

T h ep e r c e n to fC P Un o tc u r r e n t l yb e i n gu s e d

T h ep e r c e n to fC P Us p e n tw a i t i n gf o rd a t a( t y p i c a l l y d i s k )

M e m u s e d M e m o r yu s a g ei n f o r m a t i o n M e m o r yc u r r e n t l yu s e di nt h es y s t e m S w a p u s e d I n f o r m a t i o na b o u td i s kb e i n gu s e da sm e m o r y S w a pc u r r e n t l yi nu s e P I D

t o t a l f r e e T h et o t a la m o u n to fm e m o r yi nt h i ss y s t e m U n u s e dm e m o r y t o t a l f r e e T o t a la m o u n to fd i s ka s s i g n e df o ru s ea sm e m o r y U n u s e ds w a p P r o c e s sI Dn u m b e ro ft h i sp r o c e s s

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

18/39

11/26/13

Linux & Shell Script

U S E R % C P U

U s e r n a m eo ft h ep r o c e s so w n e r P e r c e n to fC P Uc u r r e n t l yb e i n gu s e db yt h i sp r o c e s s

% M E M

P e r c e n to ft o t a lm e m o r yb e i n gu s e db yt h i sp r o c e s s

T I M E C o m m a n d

T o t a lC P Ut i m ec o n s u m e db yt h i sp r o c e s s T h ec o m m a n dw h i c hw a se x e c u t e d( t r u n c a t e d )

*T h ec a l c u l a t i o ni sm o r ec o m p l i c a t e dt h a nt h i s ,b u tt h i ss i m p l ee x p l a n a t i o nw i l ls u f f i c ef o rn o w . G e n e r a l l ya s y s t e mw i t hal o a da v e r a g el o w e rt h a ni t sn u m b e ro fC P U si sk e e p i n gu pw i t hi t sw o r k . O n ew i t hal o a da v e r a g eo f o n et ot w ot i m e si t sn u m b e ro fC P U si ss t a r t i n gt of a l lb e h i n da n dt h i n g sa r e n ' tg e t t i n gd o n ea sq u i c k l ya st h e y a r ec o m i n gi n ,b u tal o a da v e r a g eo fs e v e r a lt i m e st h en u m b e ro fC P U st y p i c a l l yi n d i c a t e st h es y s t e mi sb o g g e d d o w n . O fc o u r s eu s e re x p e r i e n c ei st h eb e s ti n d i c a t o ro fs y s t e mp e r f o r m a n c e . T h eo n e ,f i v ea n df i f t e e nm i n u t el o a da v e r a g e sa r eu s e f u lf o ri d e n t i f y i n gt h et r e n do ft h es y s t e m . I ft h eo n e m i n u t el o a da v e r a g ei sl o w e rt h a nt h ef i v ea n df i f t e e nm i n u t ea v e r a g e st h es y s t e mh a sp r o b a b l yf i n i s h e ds o m el a r g e t a s k sa n dt h es y s t e mi sg e t t i n gl e s sb u s yt h a ni tp r e v i o u s l yw a s . I ft h eo n ea n df i v em i n u t ea v e r a g e sa r eh i g h e r i ti sl i k e l yt h es y s t e mi sg e t t i n gb u s i e rt h a ni tw a sf i f t e e nm i n u t e sa g o . W h i l er u n n i n gt o pt h e r ea r es e v e r a lc o m m a n d sw h i c hw i l lc h a n g ew h a tt o ps h o w sy o u . S o m ec o m m o no n e sa r e : *S p a c e b a r :R e f r e s h e st h ed i s p l a y *h :D i s p l a yt h eh e l ps c r e e n *k :K i l l sap r o c e s s * *n :C h a n g e st h en u m b e ro fp r o c e s s e sd i s p l a y e d *u :S p e c i f yw h a tu s e r ' st a s k st ov i e w( b l a n kf o ra l lu s e r s ) *p :S o r t st a s k sb yC P Uu s a g e *s :C h a n g et h en u m b e ro fs e c o n d sb e t w e e nr e f r e s h i n g *q :Q u i tt o p * W e ' l lt a l km o r ea b o u tk i l l i n gp r o c e s s e sl a t e ri nt h i sc h a p t e r . F o rn o wy o up r o b a b l yd o n ' tw a n tt ou s et h i s c o m m a n d . T h er e s to ft h e my o uc a ng oa h e a da n de x p e r i m e n tw i t h . A sw i t hm o s to t h e rc o m m a n d s ,t o pc a nb es t a r t e dw i t han u m b e ro fd i f f e r e n to p t i o n s . T h em o s tc o m m o n l yu s e do p t i o n w h e nl o g g e di na sr o o ti st h euo p t i o nt ol i m i tt h ea c t i v ep r o c e s sd i s p l a yt oap a r t i c u l a ru s e r . $t o p ut e r r y t o p-2 3 : 2 0 : 2 2u p 5 : 1 1 , 2u s e r s , l o a da v e r a g e :0 . 3 3 ,0 . 1 7 ,0 . 0 6 T a s k s : 7 9t o t a l , M e m : S w a p : 2r u n n i n g , 7 7s l e e p i n g , 4 . 2 %s y s t e m , 2 4 0 7 4 8 ku s e d , 0 ku s e d , 0s t o p p e d , 0z o m b i e 2 4 7 7 2 kb u f f e r s 9 6 7 9 6 kc a c h e d C p u ( s ) : 1 8 . 8 %u s e r , 2 5 5 6 5 6 kt o t a l , 5 0 6 0 0 8 kt o t a l , 0 . 0 %n i c e , 7 7 . 0 %i d l e 1 4 9 0 8 kf r e e , 5 0 6 0 0 8 kf r e e ,

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

19/39

11/26/13

Linux & Shell Script

P I DU S E R 2 1 4 6 2t e r r y 2 1 2 3 4t e r r y 4 0 2 9t e r r y 7 4 1 6t e r r y 6 5 1 3t e r r y 3 6 9 6t e r r y 4 0 5 4t e r r y 2 5 8 1 2t e r r y o u t p u t 1 1 4 6 7t e r r y 1 3 0 2 1t e r r y 1 1 1 3 5t e r r y 2 5 6 0 9t e r r y 3 1 9 9 2t e r r y 1 1 4 5 6t e r r y 2 2 1 6t e r r y 1 8 7 8 5t e r r y i d = O A F I I D : G N 3 0 9 9 9t e r r y 8 4 9 4t e r r y 4 8 9 0t e r r y 1 6 7 9 6t e r r y 2 9 5 9 0t e r r y 2 3 5 8 3t e r r y 1 7 2 6 3t e r r y 1 4 2 4 1t e r r y

P R N I V I R T R E S S H RS% C P U% M E M 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 9 9 9 9 9 01 2 4 4 0 1 2 m8 3 3 2S 2 . 4 4 . 9 01 2 3 8 0 1 2 m8 1 6 0S 1 . 8 4 . 8 0 7 4 7 67 4 7 65 0 4 0S 1 . 4 2 . 9 02 7 6 0 0 2 6 m 1 0 mS 1 . 01 0 . 8 01 1 7 3 6 1 1 m 1 0 mS 0 . 2 4 . 6 0 8 7 2 48 7 2 05 8 7 6S 0 . 0 3 . 4 0 7 2 2 47 2 2 41 9 8 8S 0 . 0 2 . 8 0 2 4 7 22 4 7 21 9 0 4S 0 . 0 1 . 0 0 2 6 7 62 6 7 62 1 4 8S 0 . 0 1 . 0 0 6 4 2 06 4 1 65 0 9 2S 0 . 0 2 . 5 0 1 7 4 41 7 4 41 1 4 0S 0 . 0 0 . 7 02 7 6 0 0 2 6 m 1 0 mS 0 . 01 0 . 8 02 7 6 0 0 2 6 m 1 0 mS 0 . 01 0 . 8 02 7 6 0 0 2 6 m 1 0 mS 0 . 01 0 . 8 02 7 6 0 0 2 6 m 1 0 mS 0 . 01 0 . 8 0 6 9 2 06 9 1 65 6 0 4S 0 . 0 2 . 7 0 4 2 2 84 2 2 83 5 0 8S 0 . 0 1 . 7 01 7 7 2 4 1 7 m 1 3 mS 0 . 0 6 . 9 0 7 8 8 87 8 8 87 6 8 4S 0 . 0 3 . 1 0 8 3 8 08 3 8 08 0 8 0S 0 . 0 3 . 3 0 8 9 2 48 9 2 48 5 4 0S 0 . 0 3 . 5 0 8 5 2 48 5 2 48 1 8 8S 0 . 0 3 . 3 0 5 7 6 5 7 6 5 0 4S 0 . 0 0 . 2

T I M E + C o m m a n d 0 : 1 5 . 1 1g n o m e p a n e ls m c l i e n t i dd e f a u l t 2 0 : 4 7 . 2 1/ u s r / b i n / g n o m e t e r m i n a l 0 : 3 0 . 1 5/ u s r / b i n / m e t a c i t ys m c l i e n t i d = d e f a u l t 1 0 : 3 2 . 5 5n a u t i l u sn o d e f a u l t w i n d o ws m c l i e n t i dd e f a u l t 3 0 : 0 2 . 2 0k d e i n i t :k d e d 0 : 0 1 . 7 9g n o m e s e s s i o n 0 : 0 1 . 7 9/ u s r / l i b / g c o n f d 21 1 0 : 0 0 . 3 9/ u s r / l i b / b o n o b o a c t i v a t i o n s e r v e ra c a c t i v a t ei o r 0 : 0 0 . 8 8g n o m e s m p r o x ys m c l i e n t i dd e f a u l t 0 0 : 0 0 . 9 7g n o m e s e t t i n g s d a e m o no a f a c t i v a t e 0 : 0 6 . 0 7[ f a m ] 0 : 0 0 . 1 9n a u t i l u sn o d e f a u l t w i n d o ws m c l i e n t i dd e f a u l t 3 0 : 0 0 . 5 8n a u t i l u sn o d e f a u l t w i n d o ws m c l i e n t i dd e f a u l t 3 0 : 0 1 . 5 5n a u t i l u sn o d e f a u l t w i n d o ws m c l i e n t i dd e f a u l t 3 0 : 0 0 . 0 0n a u t i l u sn o d e f a u l t w i n d o ws m c l i e n t i dd e f a u l t 3 0 : 0 0 . 6 9/ u s r / l i b / n o t i f i c a t i o n a r e a a p p l e to a f a c t i v a t e 0 : 0 1 . 0 8p a m p a n e l i c o ns m c l i e n t i dd e f a u l t 4 0 : 3 0 . 3 4k w r i t e 0 : 0 0 . 0 3k d e i n i t :R u n n i n g . . . 0 : 0 0 . 0 8k d e i n i t :d c o p s e r v e rn o s i ds u i c i d e 0 : 0 0 . 2 1k d e i n i t :k l a u n c h e r 0 : 0 0 . 2 3k d e i n i t :k i o _ f i l ef i l e/ t m p / k s o c k e t 0 : 0 0 . 0 2[ g n o m e p t y h e l p e ] 0 : 0 0 . 2 8b a s h

i i d = O A F I I D : G N O M E _ S e t t i n g s

e r r y / k l a u n c h e r j E h e b b . s l a v 0 1 5 4 01 5 4 01 0 9 6S 0 . 0 0 . 6

H e r ew es e et h et o pp r o c e s s e so w n e db yt h eu s e rt e r r y . A sy o uc a ns e e ,t h e uo p t i o nw o r k sv e r ys i m i l a r l yw i t ht o p a si td i dw i t hp s . W h i l ey o ua r er u n n i n gt o py o uc a n Now that we know how to track down running processes we might find some we need to do away with. In the next section we'll see how to kill processes. Be careful with these commands, especially if you have root privileges! T h ev ie d i t o rp r o v i d e sc o m m a n d sf o rd e l e t i n go rr e p l a c i n gs i n g l ec h a r a c t e r s ,s i n g l eo rm u l t i p l ew o r d s ,a n ds i n g l e o rm u l t i p l el i n e so ft e x t . T a b l e9 . 4s h o w ss o m ec o m m o nd e l e t ea n dr e p l a c ec o m m a n d sw i t ht h e i ra s s o c i a t e da c t i o n s . R e m e m b e ry o un e e dt ob ei nc o m m a n dm o d et ou s et h e s e . Command x r Action D e l e t eo n ec h a r a c t e ro ft e x t R e p l a c eo n ec h a r a c t e ro ft e x tw i t ht h en e x tc h a r a c t e r e n t e r e d d w d d D D e l e t ee n t i r ew o r d( 3 d wd e l e t e s3w o r d s ) D e l e t ee n t i r el i n e( 3 d dd e l e t e s3l i n e s ) D e l e t ef r o mc u r s o rt oe n do fl i n e
20/39

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

11/26/13

Linux & Shell Script

s c w c c C

S w i t c ht oi n s e r tm o d ea f t e rd e l e t i n gc u r r e n tc h a r a c t e r D e l e t ee n t i r ew o r da n ds w i t c ht oi n s e r tm o d e D e l e t ee n t i r el i n ea n ds w i t c ht oi n s e r tm o d e C h a n g e( d e l e t ea n ds w i t c ht oi n s e r tm o d e )f r o mc u r s o r p o s i t i o nt oe n do fl i n e

T a b l e9 . 4 :D e l e t eo rr e p l a c et e x tc o m m a n d s Searching for Text Strings T h ev ie d i t o ra l l o w st h eu s e rt os e a r c hf o rat e x ts t r i n ge i t h e rf o r w a r d( d o w n )i nt h ef i l eo rb a c k w a r d( u p ) . I t a l s oa l l o w sas h o r t c u tf o rr e p e a t i n gt h es e a r c h . s e a r c hc o m m a n d sa n dt h e i ra s s o c i a t e da c t i o n s . Command / t e x t ? t e x t % Action S e a r c hf o r w a r di nt h ef i l ef o rt e x t S e a r c hb a c k w a r d( u p )i nt h ef i l ef o rt e x t W i t ht h ec u r s o ro nap a r e n t h e s e s ,b r a c k e t ,o rb r a c e c h a r a c t e r ,y o uc a np r e s st h e%k e yt om o v et h ec u r s o rt o i t sm a t c h i n go p e no rc l o s ec h a r a c t e r As p e c i a ls e a r c hc a p a b i l i t yt h a tc o m e si nh a n d yw h e nw r i t i n g s h e l ls c r i p t si st h ea b i l i t yt os e a r c hf o rm a t c h i n gp a r e n t h e s e s ,b r a c k e t s ,a n db r a c e s . T a b l e9 . 5b e l o ws h o w ss o m e

T a b l e9 . 5 :S e a r c hc o m m a n d sa n dt h e i ra s s o c i a t e da c t i o n s Cutting, Copying, and Pasting Text A n yo ft h et e x td e l e t i n gc o m m a n d sp r e s e n t e de a r l i e rw o r ks i m i l a r l yt ot h ec u tf e a t u r eo fW i n d o w si nt h a tt h e yp l a c e t h ed e l e t e dt e x ti nab u f f e ra r e af o rp o t e n t i a lr e t r i e v a la tal a t e rt i m e .I nW i n d o w s ,t h eb u f f e ri sr e f e r r e dt oa s t h ec l i p b o a r d . I nv it h e r ei sau n n a m e dd e f a u l tb u f f e ra n d2 6s p e c i f i c a l l yr e f e r e n c e db u f f e r s ,e a c hi d e n t i f i e db yo n eo ft h e l e t t e r so ft h ea l p h a b e t( a ,b ,c ,d ,e t c . ) . I no r d e rt or e f e r e n c eo n eo ft h en a m e db u f f e r s ,t h eb u f f e ri d e n t i f i e r c h a r a c t e ri sp r e c e d e dw i t has i n g l eo p e nq u o t a t i o n . S o , ar e f e r st ob u f f e ra , br e f e r st ob u f f e rb ,a n ds oo n . W h e no n eo ft h ed e l e t ec o m m a n d si su s e d ,t h et e x ti sc u tf r o mt h ed o c u m e n ta n dp l a c e di nt h ed e f a u l tb u f f e r . T o r e t r i e v et e x tf r o mt h ed e f a u l tb u f f e r ,t h eu p p e rc a s ePc o m m a n dc a nb eu s e dt op a s t et h ed e f a u l tb u f f e rb e f o r et h e c u r r e n tc u r s o rl i n e ,o rt h el o w e rc a s epc o m m a n dc a nb eu s e dt op a s t et h ec o n t e n t so ft h eb u f f e ra f t e rt h ec u r r e n t l i n e . T h e r e f o r e ,a5 d dc o m m a n df o l l o w e db yac u r s o rm o v e m e n ta n daPc o m m a n dw o u l dc u tf i v el i n e so ft e x ta n d p l a c et h e mb e f o r et h el i n ew h e r et h ec u r s o rw a sm o v e d . I n s t e a do fc u t t i n go rd e l e t i n gt e x t ,i ti sa l s op o s s i b l et oc o p yt e x tf r o maf i l eu s i n gt h ey a n k( y y )c o m m a n d . T h e y a n kc o m m a n dp r e s e n t st h eo p t i o no fc o p y i n gt e x tt oo n eo ft h es p e c i f i cn a m e db u f f e r s . W h e r ey yw o u l dc o p yt h e c u r r e n tl i n et ot h eu n n a m e dd e f a u l t( u n n a m e d ) , c y yw o u l dc o p yt h ec u r r e n tl i n et ot h eb u f f e rn a m e dc . T h ei s s u a n c eo fm u l t i p l ey a n kc o m m a n d st ot h es a m eb u f f e rw i t h o u ti n t e r v e n i n gp a s t ec o m m a n d sw i l lr e s u l ti nb u f f e r o v e r w r i t e s . I no t h e rw o r d s ,t h eu s e rc a n n o ty a n kl i n ef i v et ob u f f e ra ,t h e ny a n kl i n es e v e nt ob u f f e raa n d e x p e c tt ob ea b l et op a s t eb o t hl i n e sf i v ea n ds e v e ns o m e w h e r e . W h e nau s e ry a n k sl i n ef i v e ,i ti sp l a c e di n b u f f e raa sr e q u e s t e d ,b u tw h e nac o m m a n dt oy a n kl i n e7t ob u f f e raf o l l o w s ,l i n e7w i l lo v e r w r i t el i n ef i v e , w h i c hi ss i t t i n gi nt h eb u f f e r . T h i si so n eo ft h er e a s o n sf o rp r o v i d i n gm u l t i p l en a m e db u f f e r st ou s ef o r
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 21/39

11/26/13

Linux & Shell Script

m u l t i p l es u c c e s s i v ey a n k s . T a b l e9 . 6s h o w sc o p ya n dp a s t ec o m m a n d sa n dt h e i ra s s o c i a t e da c t i o n s . Command y y Action C o p y( y a n k )t h ec u r r e n tl i n eo ft e x ti n t ot h ed e f a u l t ( u n n a m e d )b u f f e r b y y C o p y( y a n k )t h ec u r r e n tl i n eo ft e x ti n t ot h eb u f f e r n a m e db 5 y y p P b P C o p yf i v el i n e so ft e x tt ot h ed e f a u l tb u f f e r P a s t et h ed e f a u l tb u f f e ra f t e rt h ec u r r e n tc u r s o rl i n e P a s t et h ed e f a u l tb u f f e rb e f o r et h ec u r r e n tc u r s o rl i n e P a s t et h ec o n t e n t so fn a m e db u f f e rbb e f o r et h ec u r r e n t c u r s o rl i n e

T a b l e9 . 6 :C o p ya n dp a s t ec o m m a n d sa n dt h e i ra c t i o n s Undo and Other Useful Commands T a b l e9 . 7s h o w ss o m ea d d i t i o n a lm i s c e l l a n e o u sc o m m a n d sa n dt h e i ra s s o c i a t ea c t i o n s . M o s ti m p o r t a n tm a yb et h eu c o m m a n dw h i c hw i l lu n d ot h el a s tc h a n g et h a tw a sm a d e . I nm o s tv ie d i t o r sy o uc a nu n d os e v e r a lo ft h em o s tr e c e n t c o m m a n d s . Command J Action J o i nt h ec u r r e n tc u r s o rl i n ew i t ht h en e x tl i n ei nt h e f i l e E n t e r S p l i tt h ec u r r e n tl i n ea tt h ec u r s o rp o s i t i o nw h e ni n i n s e r tm o d e . u U : rf i l e n a m e U n d ot h el a s tc h a n g et h a tw a sm a d e U n d oa n yc h a n g e sm a d et ot h ec u r r e n tc u r s o rl i n e R e a dt h ef i l en a m e df i l e n a m ea n di n s e r ti tb e l o wt h e c u r r e n tc u r s o rl i n e

T a b l e9 . 7 :M i s c e l l a n e o u sc o m m a n d sa n dt h e i ra s s o c i a t e da c t i o n s vi Reference F o ry o u rc o n v e n i e n c ew eh a v ec o m p i l e dt h et a b l e so fv ic o m m a n d st o g e t h e rf o rq u i c kr e f e r e n c e . Command a i o Action A p p e n dt e x tt ot h er i g h to ft h ec u r s o r I n s e r tt e x tt ot h el e f to ft h ec u r s o r I n s e r tan e wl i n eb e l o wt h ec u r r e n tl i n e


22/39

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

11/26/13

Linux & Shell Script

A I O

A p p e n dt e x tt ot h ee n do ft h ec u r r e n tl i n e I n s e r tt e x ta tt h eb e g i n n i n go ft h ec u r r e n tl i n e I n s e r tan e wl i n ea b o v et h ec u r r e n tl i n e

Insert Commands T or e t u r nt oc o m m a n dm o d ef r o mi n s e r tm o d eu s et h ee s c a p ek e y . Command : w : w q < s h i f t > Z Z : w !n e w f i l e Action W r i t et h ef i l et od i s k W r i t et h ef i l et od i s ka n dq u i tt h ee d i t o r S a m ea s: w q W r i t et h ef i l et oan e wd i s kf i l ec a l l e dn e w f i l e

W r i t eC o m m a n d s : C o m m a n d A c t i o n h M o v ec u r s o ro n ep o s i t i o nt ot h el e f t( l e f ta r r o w ) j M o v ec u r s o ro n el i n ed o w n( d o w na r r o w ) k M o v ec u r s o ro n el i n eu p( u pa r r o w ) l M o v ec u r s o ro n ep o s i t i o nt ot h er i g h t( r i g h ta r r o w ) ^ M o v et ot h eb e g i n n i n go ft h ec u r r e n tl i n e $ M o v ec u r s o rt ot h ee n do ft h ec u r r e n tl i n e b M o v et ob e g i n n i n go fp r e v i o u sw o r d w M o v et ob e g i n n i n go fn e x tw o r d
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 23/39

11/26/13

Linux & Shell Script

e M o v et oe n do fn e x tw o r d G M o v et oe n do ft h ef i l e : n M o v et ol i n en E n t e r M o v et ot h ef i r s tw o r do n et h en e x tl i n e c t r l + b P a g eb a c k w a r d( u p ) c t r l + f P a g ef o r w a r d( d o w n ) C u r s o rM o v e m e n t :

C o m m a n d A c t i o n x D e l e t eo n ec h a r a c t e ro ft e x t r R e p l a c eo n ec h a r a c t e ro ft e x tw i t ht h en e x tc h a r a c t e re n t e r e d d w D e l e t ee n t i r ew o r d( 3 d wd e l e t e s3w o r d s ) d d D e l e t ee n t i r el i n e( 3 d dd e l e t e s3l i n e s ) D D e l e t ef r o mc u r s o rt oe n do fl i n e s S w i t c ht oi n s e r tm o d ea f t e rd e l e t i n gc u r r e n tc h a r a c t e r c w

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

24/39

11/26/13

Linux & Shell Script

D e l e t ee n t i r ew o r da n ds w i t c ht oi n s e r tm o d e c c D e l e t ee n t i r el i n ea n ds w i t c ht oi n s e r tm o d e C C h a n g e( d e l e t ea n ds w i t c ht oi n s e r tm o d e )f r o mc u r s o rp o s i t i o nt oe n do fl i n e D e l e t ea n dR e p l a c eC o m m a n d s C o m m a n d A c t i o n / t e x t S e a r c hf o r w a r di nt h ef i l ef o rt e x t ? t e x t S e a r c hb a c k w a r d( u p )i nt h ef i l ef o rt e x t % W i t ht h ec u r s o ro nap a r e n t h e s e s ,b r a c k e t ,o rb r a c ec h a r a c t e r ,y o uc a np r e s st h e%k e yt om o v et h ec u r s o rt oi t s m a t c h i n go p e no rc l o s ec h a r a c t e r S e a r c hC o m m a n d s C o m m a n d A c t i o n y y C o p y( y a n k )t h ec u r r e n tl i n eo ft e x ti n t ot h ed e f a u l tb u f f e r b y y C o p y( y a n k )t h ec u r r e n tl i n eo ft e x ti n t ot h eb u f f e rn a m e db 5 y y C o p yf i v el i n e so ft e x tt ot h ed e f a u l tb u f f e r p P a s t et h ed e f a u l tb u f f e ra f t e rt h ec u r r e n tc u r s o rl i n e P P a s t et h ed e f a u l tb u f f e rb e f o r et h ec u r r e n tc u r s o rl i n e b P P a s t et h ec o n t e n t so fn a m e db u f f e rbb e f o r et h ec u r r e n tc u r s o rl i n e C o p ya n dP a s t eC o m m a n d s


oracle-12c.blogspot.in/2012/03/linux-shell-script.html 25/39

11/26/13

Linux & Shell Script

C o m m a n d A c t i o n J J o i nt h ec u r r e n tc u r s o rl i n ew i t ht h en e x tl i n ei nt h ef i l e E n t e r S p l i tt h ec u r r e n tl i n ea tt h ec u r s o rp o s i t i o nw h e ni ni n s e r tm o d e . u U n d ot h el a s tc h a n g et h a tw a sm a d e U U n d oa n yc h a n g e sm a d et ot h ec u r r e n tc u r s o rl i n e : rf i l e n a m e R e a dt h ef i l en a m e df i l e n a m ea n di n s e r ti tb e l o wt h ec u r r e n tc u r s o rl i n e U n d oa n dM i s c e l l a n e o u sC o m m a n d s

c r o n t a bO p t i o n s

O p t i o n P u r p o s e

e d i tt h ec u r r e n tc r o n t a bf i l eu s i n gt h et e x te d i t o rs p e c i f i e db yt h eE D I T O Re n v i r o n m e n tv a r i a b l eo rt h e

V I S U A Le n v i r o n m e n tv a r i a b l e

l i s tt h ec u r r e n tc r o n t a bf i l e

r e m o v et h ec u r r e n tc r o n t a bf i l e

s p e c i f y st h eu s e r sc r o n t a bt ob em a n i p u l a t e d .T h i si su s u a l l yu s e db yr o o tt om a n i p u l a t et h ec r o n t a bo f

o t h e ru s e r so rc a nb eu s e db yy o ut oc o r r e c t l yi d e n t i f yt h ec r o n t a bt ob em a n i p u l a t e di fy o uh a v eu s e dt h es u c o m m a n dt oa s s u m ea n o t h e ri d e n t i t y .

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

26/39

11/26/13

Linux & Shell Script

F i e l d M i n u t e H o u r

V a l i dv a l u e s 0 5 9 0 2 3

D a yo fM o n t h 1 3 1 M o n t h D a yo fW e e k 1 1 2 0 7

E x a m p l e s: # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #R u nt h eW e e k l yf i l ec l e a n u pt a s ka t6 : 0 0 A Me v e r yM o n d a y a n ds e n da n yo u t p u tt oaf i l ec a l l e dc l e a n u p . l s ti nt h e / t m pd i r e c t o r y # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 0 00 6**1/ h o m e / t e r r y / c l e a n u p . k s h>/ t m p / c l e a n u p . l s t # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #R u nt h eW e e k l yM a n a g e m e n tR e p o r te v e r yM o n d a ya t7 : 0 0A M #a n ds a v eac o p yo ft h er e p o r ti nm y/ h o m ed i r e c t o r y # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 0 00 7**1/ h o m e / t e r r y / w e e k l y _ m g m t _ r p t . k s hw p r d>/ h o m e / t e r r y / w e e k l y _ m g m t _ r p t . l s t

# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #W e e k l yF u l lB a c k u p-r u ne v e r yS u n d a ya t1 : 3 0 A M # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 3 00 1**0/ h o m e / t e r r y / f u l l _ b a c k u p . k s hw p r d>/ t m p / f u l l _ b a c k u p . l s t # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #N i g h t l yI n c r e m e n t a lB a c k u p-r u nM o n d a y S a t u r d a ya t1 : 3 0 A M # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 3 00 1**1 6/ h o m e / t e r r y / i n c r _ b a c k u p . k s h >/ t m p / i n c r _ b a c k u p . l s t # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


oracle-12c.blogspot.in/2012/03/linux-shell-script.html 27/39

11/26/13

Linux & Shell Script

#L o wd i s ks p a c ea l e r t. . .r u ne v e r y1 5m i n u t e s ,s e n d i n g #a l e r t st ok e yi n d i v i d u a l sv i ae m a i l # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 0 0 , 1 5 , 3 0 , 4 5****/ h o m e / t e r r y / f r e e _ s p a c e . k s h>/ t m p / f r e e _ s p a c e . l s t # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #L u n c hT i m eN o t i f i c a t i o n-r u nM o n d a y F r i d a ya tN o o n#s e n d sam e s s a g et oa l lu s e r si n d i c a t i n gi t ' sl u n c ht i m e # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 0 01 2**1 5/ h o m e / t e r r y / l u n c h _ t i m e . k s hw p r d>/ t m p / l u n c h _ t i m e . l s t

F i e l d

V a l i dE n t r i e s( c a s ei n s e n s i t i v e )

D a y so ft h ew e e k

s u n ,m o n ,t u e ,w e d ,t h u ,f r i ,s a t S U N ,M O N ,T U E ,W E D ,T H U ,F R I ,S A T

M o n t h so fy e a r

j a n ,f e b ,m a r ,a p r ,m a y ,j u n ,j u l ,a u g ,s e p ,o c t ,n o v ,d e c J A N ,F E B ,M A R ,A P R ,M A Y ,J U N ,J U L ,A U G ,S E P ,O C T ,N O V ,D E C

i n i tc o m m a n d s

*0 :U s e dt oh a l tt h es y s t e m

*1 :S i n g l e u s e rm o d ef o rp e r f o r m i n ga d m i n i s t r a t i v et a s k s

*2 :M u l t i u s e rm o d e ,w i t h o u tn e t w o r k i n g

*3 :M u l t i u s e rm o d e ,w i t hn e t w o r k i n g

*4 :C u r r e n t l yu n u s e d

*5 :M u l t i u s e rm o d ew i t hg r a p h i c a lu s e ri n t e r f a c e( G U I ) ,u s u a l l yt h ed e f a u l tr u n l e v e l

*6 :U s e dt or e b o o tt h es y s t e m

P sc o m m a n d $p s e f
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 28/39

11/26/13

Linux & Shell Script

U I D t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y t e r r y . . .

P I D P P I D CS T I M ET T Y 3 6 9 61 8 5 8 8 01 8 : 1 0? 4 0 5 4 2 5 8 1 2 1 1 4 6 7 1 3 0 2 1 1 5 1 9 4 0 2 9 2 1 4 6 2 1 01 8 : 1 0? 1 01 8 : 1 0? 1 01 8 : 1 0? 1 01 8 : 1 0? 1 01 8 : 1 0? 1 01 8 : 1 0? 1 01 8 : 1 0?

T I M EC M D 0 0 : 0 0 : 0 1g n o m e s e s s i o n 0 0 : 0 0 : 0 1/ u s r / l i b / g c o n f d 21 1 0 0 : 0 0 : 0 0/ u s r / l i b / b o n o b o a c t i v a t i o n s e r v e 0 0 : 0 0 : 0 0g n o m e s m p r o x ys m c l i e n t i dd e f 0 0 : 0 0 : 0 0g n o m e s e t t i n g s d a e m o no a f a c t i 0 0 : 0 0 : 0 0x s c r e e n s a v e rn o s p l a s h 0 0 : 0 0 : 1 1/ u s r / b i n / m e t a c i t ys m c l i e n t i d 0 0 : 0 0 : 1 1g n o m e p a n e ls m c l i e n t i dd e f a u 0 0 : 0 0 : 0 0n a u t i l u sn o d e f a u l t w i n d o ws 0 0 : 0 0 : 0 0/ u s r / l i b / n o t i f i c a t i o n a r e a a p p l e 0 0 : 0 0 : 0 0p a m p a n e l i c o ns m c l i e n t i dd e 0 0 : 0 0 : 1 3k w r i t e 0 0 : 0 0 : 0 0k d e i n i t :R u n n i n g . . . 0 0 : 0 0 : 0 0k d e i n i t :d c o p s e r v e rn o s i ds u 0 0 : 0 0 : 0 0k d e i n i t :k l a u n c h e r 0 0 : 0 0 : 0 1k d e i n i t :k d e d 0 0 : 0 0 : 0 0k d e i n i t :k i o _ f i l ef i l e/ t m p / k s o c 0 0 : 0 0 : 0 1/ u s r / b i n / g n o m e t e r m i n a l 0 0 : 0 0 : 0 0[ g n o m e p t y h e l p e ] 0 0 : 0 0 : 0 0b a s h 0 0 : 0 0 : 0 0p s e f

2 2 1 62 5 6 0 9 01 8 : 1 0? 1 8 7 8 5 3 0 9 9 9 8 4 9 4 4 8 9 0 1 6 7 9 6 2 9 5 9 0 6 5 1 3 1 01 8 : 1 0? 1 01 8 : 1 0? 1 01 8 : 5 5? 1 01 8 : 5 5? 1 01 8 : 5 5? 1 01 8 : 5 5? 1 01 8 : 5 5?

2 3 5 8 3 4 8 9 0 02 0 : 3 7? 2 1 2 3 4 12 12 0 : 5 5?

1 7 2 6 32 1 2 3 4 02 0 : 5 5? 1 4 2 4 12 1 2 3 4 22 0 : 5 5p t s / 0 1 8 5 0 41 4 2 4 1 02 0 : 5 5p t s / 0

T h ec o m m a n dp s e fw i l lo u t p u tl o t so fi n f o r m a t i o na b o u ta l lt h er u n n i n gc o m m a n d so nt h es y s t e m . H e r e ' saq u i c k e x p l a n a t i o no fw h a tt h i so u t p u tm e a n s :

C o l u m n

D e s c r i p t i o n
29/39

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

11/26/13

Linux & Shell Script

U I D

U s e r n a m eo ft h ep r o c e s so w n e r

P I D

P r o c e s sI Dn u m b e ro ft h i sp r o c e s s

P P I D

P r o c e s sI Do ft h ep r o c e s sw h i c hs t a r t e dt h i so n e( p a r e n t )

C P Uu t i l i z a t i o no ft h i sp r o c e s s

S T I M E

S t a r tt i m e( l i s t e da sm o n t ha n dd a yi fo l d e rt h a n1d a y )

T T Y

T h et e r m i n a l( i fa n y )t h ep r o c e s sw a ss t a r t e df r o m

T I M E

T h ea m o u n to fC P Ut i m et h i sp r o c e s sh a sc o n s u m e d

C M D

T h ec o m m a n dw h i c hw a se x e c u t e d( l o n gc o m m a n d sa r et r u n c a t e d )

uo p t i o nt os h o wp r o c e s s e so w n e db yas p e c i f i cu s e r . T h ef o l l o w i n gd i s p l a yi sf o rt h el pu s e r :

$p sul p

P I DT T Y 2 2 2 3 3? 2 8 6 8 8? 3 0 9 7 0? 7 5 9 3? 1 0 8 3 3?

T I M EC M D 0 0 : 0 0 : 0 7f o o m a t i c r i p 0 0 : 0 0 : 0 0f o o m a t i c r i p 0 0 : 0 0 : 0 0f o o m a t i c r i p 0 0 : 0 0 : 0 0s h 0 0 : 0 0 : 0 0s h

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

30/39

11/26/13

Linux & Shell Script

2 0 0 5? 3 2 2 6 7? 2 6 2 2 6? 6 9 3 0?

0 0 : 0 0 : 0 0p e r l 0 0 : 0 0 : 0 3g s 0 0 : 0 0 : 0 0s h 0 0 : 0 0 : 0 0c a t

t os e eo n l yt h o s ep r o c e s s e so w n e db yas p e c i f i cu s e ri st h e uo p t i o n .T h ef o l l o w i n ga r et h ep i d sf o rt h el pu s e r :

$p g r e p ul p

s e et h ep r o c e s sI D sf o rp r o c e s s e so w n e db yt h eu s e rl pw h i c hm a t c ht h ep a t t e r nf o o m a t i c .

$p g r e p ul pf o o m a t i c 2 2 2 3 3 2 8 6 8 8 3 0 9 7 0 S e r v e rm o n i t o r i n gc o m m a n d s S o m ep o p u l a rc o m m a n d s / u t i l i t i e sf o rm o n i t o r i n gs y s t e mr e s o u r c e sa n dt a s k sm a n a g e db yt h eL i n u xk e r n e la r ea s f o l l o w s :

*t o p :P r o v i d e sad y n a m i cr e a l t i m ev i e wo far u n n i n gs y s t e m ,i n c l u d i n gi n f o r m a t i o na b o u ts y s t e mr e s o u r c eu s a g ea n d ac o n s t a n t l yu p d a t e dl i s to ft h ep r o c e s s e sw h i c ha r ec o n s u m i n gt h em o s tr e s o u r c e s . B e c a u s ei ti ss ou s e f u lf o r a d m i n i s t r a t i o nw ew i l lt a l kq u i t eab i ta b o u tt o pi nc h a p t e r8 .

*m p s t a t :R e p o r t sa c t i v i t i e sf o re a c ha v a i l a b l ep r o c e s s o r ,p r o c e s s o rz e r ob e i n gt h ef i r s to n er e p o r t e d . G l o b a l a v e r a g ea c t i v i t i e sa c r o s sa l lp r o c e s s o r sa r ea l s or e p o r t e d .

*i o s t a t :U s e df o rm o n i t o r i n gt h el o a do ns y s t e mi n p u t / o u t p u td e v i c e sb yo b s e r v i n gt h et i m et h ed e v i c e sa r ea c t i v e c o m p a r e dt ot h ea v e r a g et r a n s f e rr a t eo ft h ed e v i c e .

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

31/39

11/26/13

Linux & Shell Script

*v m s t a t :D i s p l a y si n f o r m a t i o na b o u tp r o c e s s e s ,m e m o r y ,p a g i n g ,b l o c kI O ,a n dd i f f e r e n tl e v e l so fC P Ua c t i v i t y C P UR e l a t e dI n f o r m a t i o n

#c a t/ p r o c / c p u i n f o

D i s p l a yt h eN u m b e ro fP r o c e s s o r si nt h eS e r v e r

#c a t/ p r o c / c p u i n f o|g r e pp r o c e s s o r|w c l

D i s p l a y i n gt h eT o t a lR A Mo nt h eL i n u xs y s t e m

#c a t/ p r o c / m e m i n f o

f r e ek

T o pM e m o r ya n dC P UU s e r s

#p su

D i s p l a yT o pC P UU s e r :

#p sa u x|s o r t n+ 2|t a i l1

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

32/39

11/26/13

Linux & Shell Script

D i s p l a yT o pM e m o r yU s e r :

#p sa u x|s o r tn+ 3|t a i l1

P a g i n ga n dS w a p p i n gD e v i c e s #c a t/ p r o c / s w a p s

# s w a p o ns

D i s p l a y i n gM u l t i P r o c e s s o rS t a t i s t i c s

$m p s t a t35

L i n u x2 . 6 . 5 1 . 3 5 8( D e l l L i n u x ) 1 0 / 1 8 / 2 0 0 4 1 0 : 3 3 : 2 6P M C P U 1 0 : 3 3 : 2 9P M a l l 1 0 : 3 3 : 3 2P M a l l 1 0 : 3 3 : 3 5P M a l l 1 0 : 3 3 : 3 8P M a l l 1 0 : 3 3 : 4 1P M a l l A v e r a g e : a l l % u s e r 1 . 0 0 0 . 3 3 0 . 6 7 0 . 6 6 0 . 6 7 0 . 6 7 % n i c e% s y s t e m% i o w a i t 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 0 . 3 3 0 . 3 3 0 . 3 3 0 . 3 3 0 . 3 3 0 . 3 3 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 % i r q 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 % s o f t 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 0 . 0 0 % i d l e 9 8 . 6 7 9 9 . 3 3 9 9 . 0 0 9 9 . 0 0 9 9 . 0 0 9 9 . 0 0 i n t r / s 1 0 0 1 . 9 9 1 0 0 7 . 0 2 1 0 0 2 . 6 7 1 0 0 0 . 3 3 1 0 0 5 . 6 7 1 0 0 3 . 5 3

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

33/39

11/26/13

Linux & Shell Script

T h ec o l u m n si nt h er e p o r tg e n e r a t e db yt h em p s t a tc o m m a n da r ed e f i n e da sf o l l o w s :

*C P U :E i t h e rt h ep r o c e s s o rn u m b e ro rt h ek e y w o r da l l ,w h i c hi n d i c a t e st h a ts t a t i s t i c sa r ec a l c u l a t e da sa v e r a g e s a m o n ga l lp r o c e s s o r so rt h a tt h e r ei so n l yo n ep r o c e s s o ri nt h es e r v e r

*% u s e r :T h ep e r c e n t a g eo fC P Uu s e db yu s e ra p p l i c a t i o n s

*% n i c e :T h ep e r c e n t a g eo fC P Uu t i l i z a t i o na tt h eu s e rl e v e lw i t hn i c ep r i o r i t y

*% s y s t e m :T h ep e r c e n t a g eo fC P Uu s e db yt h es y s t e m .T h i sd o e sn o ti n c l u d et h et i m es p e n ts e r v i c i n gi n t e r r u p t so r s o f t i r q s .As o f t i r qi sas o f t w a r ei n t e r r u p t ,o n eo fu pt o3 2s o f t w a r ei n t e r r u p t sw h i c hc a nr u no nm u l t i p l eC P U s s i m u l t a n e o u s l y .

*% i o w a i t :T h ep e r c e n t a g eo ft i m et h es y s t e mh a dap e n d i n gd i s kI / Or e q u e s t

*% i r q :T h ep e r c e n t a g eo ft i m es p e n tb yt h eC P U ss e r v i c i n gi n t e r r u p t s

*% s o f t :T h ep e r c e n t a g eo ft i m et h ep r o c e s s o r ss p e n ts e r v i c i n gs o f t i r q s .

*% i d l e :T h ep e r c e n t a g eo ft i m et h a tt h ep r o c e s s o r sw e r ei d l ea n dt h es y s t e md i dn o th a v eap e n d i n gd i s kI / O r e q u e s t .

*i n t r / s :T h et o t a ln u m b e ro fi n t e r r u p t sp e rs e c o n dr e c e i v e db yt h ep r o c e s s o r ( s )

D i s p l a y i n gI / OS t a t i s t i c s

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

34/39

11/26/13

Linux & Shell Script

$i o s t a t35

L i n u x2 . 6 . 5 1 . 3 5 8( D e l l L i n u x ) 1 0 / 1 8 / 2 0 0 4

a v g c p u : % u s e r 0 . 5 1

% n i c e 0 . 1 4

% s y s% i o w a i t 0 . 2 2 0 . 2 6

% i d l e 9 8 . 8 6

D e v i c e : h d a h d f

t p s 0 . 0 0 0 . 9 9

B l k _ r e a d / s 0 . 0 2 2 0 . 8 3

B l k _ w r t n / s 0 . 0 0 5 . 3 3

B l k _ r e a d 1 1 9 2 1 4 0 5 1 8 6

B l k _ w r t n 3 8 3 5 9 6 1 6

a v g c p u : % u s e r 0 . 6 7

% n i c e 0 . 0 0

% s y s% i o w a i t 0 . 3 3 0 . 0 0

% i d l e 9 9 . 0 0

D e v i c e : h d a h d f

t p s 0 . 0 0 0 . 0 0

B l k _ r e a d / s 0 . 0 0 0 . 0 0

B l k _ w r t n / s 0 . 0 0 0 . 0 0

B l k _ r e a d 0 0

B l k _ w r t n 0 0

a v g c p u : % u s e r 0 . 6 7

% n i c e 0 . 0 0

% s y s% i o w a i t 0 . 3 3 0 . 0 0

% i d l e 9 9 . 0 0

D e v i c e : h d a

t p s 0 . 0 0

B l k _ r e a d / s 0 . 0 0

B l k _ w r t n / s 0 . 0 0

B l k _ r e a d 0

B l k _ w r t n 0

F o rt h ea v e r a g eC P Ur e p o r t ,% u s e r ,% n i c e ,% i o w a i t ,a n d% i d l ea r ed e f i n e dt h es a m ea st h e yw e r ei nt h em p s t a t c o m m a n do u t p u t . O n er e m a i n i n gp i e c eo fi n f o r m a t i o ni sd e f i n e da s :

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

35/39

11/26/13

Linux & Shell Script

*% s y s :T h ep e r c e n t a g eo fp r o c e s s o ru t i l i z a t i o no c c u r r i n ga tt h es y s t e mk e r n e ll e v e l .

F o rt h ed e v i c eu t i l i z a t i o nr e p o r t :

*d e v i c e :T h ed e v i c en a m ea sl i s t e di nt h e/ d e vd i r e c t o r yi sd i s p l a y e d . T h e s ed e v i c en a m e sa r em a p p e dt om o u n t p o i n t si nt h ef i l e/ e t c / f s t a ba n da r ea l s ol i s t e di nt h eo u t p u to ft h ed fc o m m a n d .

*t p s :T h en u m b e ro ft r a n s f e r s( I / Or e q u e s t s )p e rs e c o n di s s u e dt ot h ed e v i c e .

*b l k _ r e a d / s :T h en u m b e ro fb l o c k sp e rs e c o n dr e a df r o mt h ed e v i c e .

*b l k _ w r t n / s :T h en u m b e ro fb l o c k sp e rs e c o n dw r i t t e nt ot h ed e v i c e .

*b l k _ r e a d :T h et o t a ln u m b e ro fb l o c k sr e a d .

*b l k _ w r t n :T h et o t a ln u m b e ro fb l o c k sw r i t t e n .

T h i si n f o r m a t i o nc a na s s i s ti nt h ed e t e r m i n a t i o no fw h i c hd e v i c e sa r em o r eh e a v i l yu s e dt h a no t h e r sa n dp e r h a p s h e l pw i t ht h ed e t e r m i n a t i o no fh o wt ob e t t e rd i s t r i b u t ed a t at ob a l a n c et h ew o r k l o a d .

D i s p l a y i n gV i r t u a lM e m o r yS t a t i s t i c s

T h ev m s t a tc o m m a n dd i s p l a y si n f o r m a t i o na b o u tp r o c e s s e s ,m e m o r y ,p a g i n g ,b l o c kI O ,a n dd i f f e r e n tl e v e l so fC P U a c t i v i t y .A sw i t hi o s t a t ,t h ef i r s td e t a i ll i n e sp r o d u c er e p o r ta v e r a g e ss i n c et h el a s tr e b o o t .S u b s e q u e n td e t a i l l i n e sr e p o r ti n f o r m a t i o nu s i n gt h ei n t e r v a ls p e c i f i e do nt h ec o m m a n dl i n e .

A sw i t ht h eo t h e rc o m m a n d si nt h i ss e c t i o n ,t h ev m s t a tc o m m a n di sd r i v e nb yd e l a ya n dc o u n to p t i o n st h a td e t e r m i n e t h et i m ei n t e r v a lb e t w e e nr e p o r tl i n e sa n dt h et o t a l sn u m b e ro fi n t e r v a l st ob er e p o r t e d .

$v m s t a t35

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

36/39

11/26/13

Linux & Shell Script

p r o c sm e m o r y -s w a p -i o -s y s t e m -c p u r b 0 0 0 0 0 0 0 0 0 0 s w p d f r e e b u f f c a c h e s i 0 0 0 0 0 s o 0 0 0 0 0 b i 8 0 0 0 0 b o i n c su ss yi dw a 2 9 1 09 9 0 2 5 1 09 9 0 2 4 1 09 9 0 2 1 0 09 9 0 2 2 1 09 9 0

0 6 3 4 9 2 9 4 8 5 6 2 4 9 9 6 0 6 3 4 9 2 9 4 8 5 6 2 4 9 9 6 0 6 3 4 9 2 9 4 8 6 0 2 4 9 9 6 0 6 3 4 9 2 9 4 8 6 0 2 4 9 9 6 0 6 3 4 9 2 9 4 8 6 4 2 4 9 9 6

3 4 8 4 01 0 0 5 1 31 0 0 5 01 0 0 2 41 0 0 3

T h eL i n u xm a np a g ef o rv m s t a td e f i n e st h ef i e l d sd i s p l a y e da sf o l l o w s :

*p r o c s

*r :T h en u m b e ro fp r o c e s s e sw a i t i n gf o rr u nt i m e

*b :T h en u m b e ro fp r o c e s s e si nu n i n t e r r u p t i b l es l e e p ,w h i c hm e a n st h e ya r ew a i t i n go nar e s o u r c e

*m e m o r y

*s w p d :V i r t u a lm e m o r yu s e d

*f r e e :I d l em e m o r y

*b u f f :A m o u n to fm e m o r yu s e da sb u f f e r s

*c a c h e :C u r r e n tm e m o r yu s e da sc a c h e

*s w a p

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

37/39

11/26/13

Linux & Shell Script

*s i :M e m o r ys w a p p e di np e rs e c o n df r o md i s k

*s o :M e m o r ys w a p p e do u tp e rs e c o n dt od i s k

*i o

*b i :B l o c k sp e rs e c o n dr e c e i v e df r o mab l o c kd e v i c e

*b o :B l o c k sp e rs e c o n ds e n tt oab l o c kd e v i c e

*s y s t e m

*i n : . N u m b e ro fi n t e r r u p t sp e rs e c o n d ,i n c l u d i n gt h ec l o c k

*c s :N u m b e ro fc o n t e x ts w i t c h e sp e rs e c o n d

*c p u :T h e s es t a t i s t i c sa r ep e r c e n t a g e so ft o t a lC P Ut i m e :

*u s :U s e rt i m es p e n tr u n n i n gn o n k e r n e lc o d e ,i n c l u d e sn i c et i m e

*s y :S y s t e mt i m es p e n tr u n n i n gk e r n e lc o d e

*i d :I d l et i m e

*w a :W a i tt i m es p e n tw a i t i n gf o rI / O

T h ev m s t a ti n f o r m a t i o nc a nb ei n v a l u a b l ew h e ns t u d y i n gr e s o u r c eu t i l i z a t i o nt r e n d s . H e r ea r eaf e we x a m p l e so fh o w v m s t a to u t p u tc a nb ei n t e r p r e t e d :
oracle-12c.blogspot.in/2012/03/linux-shell-script.html 38/39

11/26/13

Linux & Shell Script

I fo v e rt i m et h er u nq u e u ev a l u e ,p r o c s r ,r e m a i n sc o n s i s t e n t l yh i g h e rt h a nt h en u m b e ro fp r o c e s s o r si nt h es e r v e r a n dC P Ui d l et i m ei sl o w ,t h es y s t e mi sC P Ub o u n da n dc a nb e n e f i tf r o mt h ea d d i t i o no fm o r ea n d / o rf a s t e r p r o c e s s o r s .A l t e r n a t i v e l yah i g hn u m b e rd i s p l a y e di nt h ep r o c s bc o l u m na l s oi n d i c a t e sab o t t l e n e c k ,b u to n ew h e r e p r o c e s s e sa r ew a i t i n go no t h e rr e s o u r c e s .

I ft h ev i r t u a lm e m o r yu s e d( m e m o r y s w p d )r e m a i n sh i g ha n dt h ef r e em e m o r y( m e m o r y f r e e )r e m a i n sl o w ,t h e nt h e s y s t e mi sm e m o r yc o n s t r a i n e da n dw i l lb e n e f i tf r o ma d d i t i o n a lR A M .

C o n s i s t e n t l yh i g hI / Or a t e sp a i r e dw i t hc o n s i s t e n t l yl o wC P Uu t i l i z a t i o n( c p u u s )i n d i c a t e sa nI / Ob o u n ds y s t e m t h a tc o u l db e n e f i tf r o mah i g h l yb u f f e r e dd i s ka r r a yo rp o s s i b l ys o l i d s t a t ed i s k .

h t t p : / / w w w . d b a o r a c l e . c o m / l i n u x / f i n d _ p r o c e s s e s _ b y _ p a t t e r n . h t m[http://www.dba-

oracle.com/linux/find_processes_by_pattern.htm]
h t t p : / / w w w . o r a c l e . c o m / t e c h n e t w o r k / a r t i c l e s / l i n u x / p a r t 2 0 8 5 1 7 9 . h t m l

[http://www.oracle.com/technetwork/articles/linux/part2-085179.html] h t t p : / / w w w . o r a c l e b a s e . c o m / a r t i c l e s / l i n u x / a r t i c l e s l i n u x . p h p[http://www.oracle-base.com/articles/linux/articleslinux.php]

Posted 24th March 2012 by Gopinathan D


0

Add a comment

Enter your comment...

Comment as:

Google Account

Publish

Preview

oracle-12c.blogspot.in/2012/03/linux-shell-script.html

39/39

Vous aimerez peut-être aussi