注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

星期五

明天不上班

 
 
 

日志

 
 
关于我

一个特立独行的Java程序员,比较宅,上上网,写博客,听音乐,看电影。

网易考拉推荐

DBA Hacker’s guide to Solaris(转载)  

2010-08-12 19:37:47|  分类: Solaris |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Not just for DBAs: this is to remind anyone of syntax and options.

1.    Handy Solaris commands     HW config, swap, patches etc.
2.    Real-time performance monitoring     vmstat, iostat, mpstat etc.
3.    Unix Commands     find, awk, sed, grep etc.
4.    vi editor commands     the 22 most useful vi commands
5.    Unix file permissions explained      sounds basic, but you may learn something new here!
6.    The Solaris Name Service explained     how hostname and username lookups work

1. Handy Solaris commands

  • show hardware config (memory, CPUs etc) :

  •   /usr/platform/sun4u/sbin/prtdiag -v |more
    /usr/sbin/psrinfo
  • show kernel settings:

  •   /usr/sbin/sysdef |more
    more /etc/system

  • show list of Solaris patches:

  •   showrev -p |more
  • show software installed:

  •   pkginfo |more
  • check swap space:

  •   /usr/sbin/swap -s
  • check system load average: an uptime more than double the number of CPUs is getting a bit busy

  •   uptime
  • top CPU users:

  •   /usr/ucb/ps uax |head
  • top memory users:

  •   /usr/ucb/ps vax |head
  • check disk space:

  •   df -k   (shows all mounted filesystems -including NFS etc)
      df -lk   (shows only local filesystems)
      df -k -Fufs (shows only local Sun UFS filesystems (normal hard disks)
      df -k .   (show just the filesystem you are currently in)

2. Real-time performance monitoring:

3. Unix Commands

  • at - run a command or script once in the future

  • bash$ at 0815 tomorrow
    at> rm $HOME/zxc
    at>
    (type Control-D)
    commands will be executed using /usr/bin/bash
    job 984032100.a at Thu Mar 8 06:15:00 2001

  • awk
  • cron

  • crontab -l  to see your crontab
    crontab -e   to edit it (NB but first do EDITOR=vi (or EDITOR=emacs) ; export EDITOR )
    Remember fields are : minute hour day month day_of_week (0=Sun)
    0-59 0-23 1-31 1-12 0-6
    e.g. run a script only on Tuesdays to Fridays, at 10:12 am, 3:12pm, 4:12pm and 5:12pm
    12 10,15-17 * * 2-5/home/oracle/bin/script

  • du
  •   -show disk space usage
      du -k
      -show disk usage in kB in all subdirectories below the current one
      du -sk   -show just the total of everything below the current dir
      du -sk *   -show individual totals for each file or directory in the current dir

  • find

  • find things you can’t remember the exact name of :
      find /usr/lib -name "*socket*"
    find big files (more than 20000 blocks, ie about 10MB )
      find . -size +20000
    find files or directories modified in last day
      find . -mtime -1
    find files not accessed (read) in 45 days
      find /tmp -atime +45
    Add -ls to the end of any of the above commands to see a full ls -l listing of the files found.

    You can combine multiple options , e.g look for which big files have filled up a filesystem recently
      find . -size +20000 -mtime -1 -ls
    Or combine options using an "OR" syntax, e.g. find files which were modified either less than 1 week ago or more than 2 weeks ago
      find . \( -mtime +14 -o -mtime -7 \) -ls
    You can send the ouput of find to another command : the xargs command is ideal for this: e.g. interactively delete all core files under your $HOME
      find ~ -type f -name core |xargs rm -i
    or look for a particular word in all your .c files:
      find . -name "*.c" |xargs grep -l libsocket

  • grep   and its more flexible and faster cousins egrep and fgrep

  • Search for either of two strings in all log files:
      egrep "error|PROBLEM" *log
    case-insensitive search
      fgrep -i error *log   (will find Error, ERROR, etc.)
    just see the filenames where the search text was found
      grep -l error *log

  • sort

  • -n sorts by number instead of alphabetically
    e.g. cd /export/home; du -sk * | sort -nr lists who is using most space in their home directory

  • tar
    e.g. to copy a directory tree, preserving symlinks:
      cd fromdir; tar cf - . | (cd todir; tar xpf -)

  • tr    translate characters

  • convert lower-case to upper:
      cat myfile | tr [a-z] [A-Z]
    change colons to newlines:
      tr : "\n" < myfile > newfile
  • who  show who is currently logged on and where from
  • w  show what people are doing

other useful Unix commands for you to check out:

cut, paste , split

diff, sdiff, cmp, dircmp

head, tail, tail -f
id, groups

4. vi commands

The basic vi commands:

i insert before current character a append after current char
I insert at beginning of line A append after end of line
x delete current character X backspace-delete (deletes char to left)
dd delete current line
22dd delete 22 lines u undo the last thing you did
p paste those 22 lines below the current line
12yy copy 12 lines into the ‘clipboard’ for later pasting
<Esc> to get out of editing (insert/append) mode
:wq to save ('write') and quit (:q! to quit without writing)

vi moving-around Timesavers:

using h,j,k,l to move left,down,up and right is quicker than using the arrow keys (once you get used to it!).

w move one word forward b move back a word e go to end of word
Ctl-F move Forward a whole page Ctl-B move Back a page
0 (zero) go to beginning of line $ go to end of line
:242 go to line 242 Ctl-G see what line you are on

vi modifying things:

cw change word 3cw change 3 words C change to end-of-line
dw delete word D delete to end-of-line
cc replace current line with what you type next
r replace one character R endless replace (like over-typing)
o open/add a new line below the current one O open new line above current one
xp swap two characters (e.g. when you make a typo)
/bob search forward for 'bob' n repeat previous search ? search backwards

Probably the handiest vi command:
  .
  (dot) -repeat your last command

useful extra vi commands:
  ~    swap case of current character (capitalize or lower-case)
Ctl-L    re-draw the screen (e.g when something from a background process writes to your screen and messes up your vi window)
:set nu    show line numbers (:set nonu to remove line numbers)
:set list    show hidden characters, line endings etc. (: set nolist)

Global replace:
     :%s/old/new/g  (% means all lines)
or     :g/old/s//new/g
or     :%s/old/new/gc  (c is to confirm each replacement, type ‘y’ to accept)

5. Unix file permissions

You probably already know the basics:
Each user in Unix belongs to at least one group, each file or directory on the system belongs to one user and one group. When you do an ls -l on a file you see what permissions the file owner, group owner and everyone else (‘world’ or ‘others’) have on it
  -rwxr-xr-- 1 robins  devteam 180 Mar 8 13:50 instbb
so on the file instbb there is full access (rwx- read,write,execute) for the owner (robins), read and execute for the group devteam and read-only for everyone else.

What you may not know is that whether someone can delete that file is not determined by the file permissions, but by the permissions of the directory the file is in :
  bash$ ls -al
  total 598
drwxrwxr-x  3 robins  devteam 512 Mar 8 12:02 .
drwxr-xr-x 24 root    wheel  1024 Mar 8 12:02 ..
-rwxr-xr--  1 robins  devteam 180 Mar 8 13:50 instbb
In this case the directory (.) is group writeable, which means anyone in the group devteam can delete the file instbb. Although they can’t modify it, they could copy it to a new file in that directory, modify it, then delete the original and rename the new file as instbb. So the file isn’t as secure as it may appear..

6. Solaris Name services

Solaris provides a mechanism for getting hostnames and usernames etc from several sources (e.g DNS, NIS, or the traditional /etc/hosts file) : the file /etc/nsswitch.conf , which may contain
  hosts: files dns
this means that when you try to access a remote host by name (e.g. ping neptune) it will look for neptune first in /etc/hosts, then do an lookup in DNS (nslookup using the server specified in /etc/resolv.conf)

Similarly for usernames, you may have
  passwd: files nis
So when you run a command which refers to a username (e.g. cd ~oracle ) , it first looks in /etc/passwd then does a lookup in NIS (ypmatch oracle passwd).

However you can look up hosts and users without worrying about where they are stored, using the getent command :
  bash$ getent passwd oracle
oracle:##oracle:3008:5001:Oracle DBA:/export/home/oracle:/usr/local/bin/bash
bash$ getent hosts www.inkq.com
  192.168.245.12 www.inkq.com
bash$ getent hosts 10.0.0.91
  10.0.0.91 plop.inkq.com plop mailhost
  评论这张
 
阅读(486)| 评论(0)
推荐

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017