コマンドメモ
・centOsのバージョン確認
cat /etc/redhat-release
ps -aef|grep ruby |grep -v grep | awk '{print $1 $2 $8}'
ps aux | grep redis | grep -v grep
○psの実行結果を並び替えする
ps -ae -o pid,pcpu,rss,time,cmdps -ae -o pid,pcpu,rss,time,cmd | sort -nr -k 2
○仮想メモリを繰り返し表示
vmstat -n 2
swap:仮想メモリ。ここが増えて、Swapのsi soが頻繁に値が変わるような状態だとメモリ不足が考えられる。
○サーバの死活監視
ping -c 1 wwww.example.com > /dev/null 2>&1 || (echo "no response from www.example.jp" | mail -s ping_alert foo@example.jp)
[ || ]は最初の左に書かれている処理が失敗した場合は右の動作をするということ
○容量チェック
du -s
○プロセス数をカウントする
netstat -an | grep ESTABLISH|grep :80|wc -l
○find
find . -name "*.rb" | xargs grep encrypt
find log -name test*.log -ctime -3 -type f
=>
- ctime はファイルのステータスが最後に変更されて日を示す。
-mtimeはファイルの内容が変更された日を示す。 上の例だと3日前にファイルステータスが変わったものをさす
type f はファイルのタイプをさす。-type d だとディレクトリ
for x in lists; do hohoohogege; done
○xargs
41 echo a b c | xargs -n1 echo
- >
入力しを一つずつ受け取っる。
find /usr/local/project/testApp/log -ctime +3 | xargs rm