{"id":921,"date":"2012-08-02T16:18:19","date_gmt":"2012-08-02T08:18:19","guid":{"rendered":"http:\/\/rmohan.com\/?p=921"},"modified":"2012-08-02T16:18:34","modified_gmt":"2012-08-02T08:18:34","slug":"linux-commands-not-usual","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=921","title":{"rendered":"Linux Commands &#8211; Not Usual"},"content":{"rendered":"<h3><strong>Check Validity of a Certificate File (PEM File)<br \/>\n<\/strong><\/h3>\n<h3 id=\"sites-page-title-header\" align=\"left\"><strong># openssl x509 -in Certificates.pem -inform PEM -text -noout -enddate<\/strong><\/h3>\n<h3 id=\"sites-page-title-header\" align=\"left\"><strong>\u00a0\u00a0\u00a0<\/strong><\/h3>\n<h3 align=\"left\"><strong>\u00a0\u00a0\u00a0 Certificate:<br \/>\nData:<\/strong><\/h3>\n<p>Version: 3 (0x2)<\/p>\n<p>Serial Number:<\/p>\n<p>5b:84:3e:8f:d3:1e:fc:67<\/p>\n<p>Signature Algorithm: sha1WithRSAEncryption<\/p>\n<p>Issuer: C=US, O=Sabe Inc., OU=Sabe Relations, CN=Sabe Certification Authority<\/p>\n<p>Validity<\/p>\n<p>Not Before: Oct\u00a0 1 11:56:10 2011 GMT<br \/>\nNot After : Sep 30 11:56:10 2012 GMT<\/p>\n<h3><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td>\n<div><strong>Sometime Apache process, keeps on execution (Seems like Hangs), so\u00a0generally trying to get the exact PHP file that is running by Apache Process, So here is my Try.<\/strong><\/div>\n<div><strong><br \/>\n<\/strong><\/div>\n<div><strong>I used Strace to get the opened files by the apache process. (Get PID of\u00a0<\/strong><\/div>\n<div><strong>Apache process that is taking time, though you can also get it From top \u00a0command)<\/strong><\/div>\n<div><strong><br \/>\n<\/strong><\/div>\n<div><strong>#\u00a0pstree -p -n | grep http<\/strong><\/div>\n<div><strong>(This will show each files that is being processed by that Apache Proc)<\/strong><\/div>\n<div><strong><br \/>\n<\/strong><\/div>\n<div><strong># strace -p &lt;PID of Apache&gt;<\/strong><\/div>\n<div><strong>The list of files could also be get using lsof, but that could not be of full use, as you need the files\u00a0continuusly\u00a0\u00a0using by Apache Process<\/strong><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong> <\/strong><br \/>\n<strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td><strong>Create many Files Sequentially<\/strong><\/p>\n<div><strong><em># <\/em>seq -w 1 30 | xargs -i -t zcat in_Feb2011\/in_Files-{}May2011.gz | grep -E &#8216;name.html?secsid=3304847|name.html?secsid=30780899&#8217; <\/strong><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td><strong>Delete Empty Directories<\/strong><\/p>\n<div><strong># find folder\/ -type d -empty | xargs -i -t rm -rf {} <\/strong><\/div>\n<div><strong>or <\/strong><\/div>\n<div><strong># find folder\/ -type d -empty -delete\u00a0<\/strong><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td><strong>Tail, Vmstat and Date \u00a0in Loop, Output every 10 Sec<\/strong><\/p>\n<div><strong># vmstat 1 1;for ((;;));do date; vmstat 10 2 | tail -n1;done<\/strong><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td><strong>Real Time Monitoring on Linux <\/strong><br \/>\n<strong># watch -n1 &#8211;difference &#8220;echo &#8220;Uptime&#8221;; uptime; echo \\n ; ps -eo pcpu,pid,args | sort -k 1 -r |grep -v watch | head -10; echo &#8220;\\n&#8221; ; tail \/var\/log\/cron | grep &#8220;check_load&#8221;<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td><strong>Find files based and sorted on Size<\/strong><br \/>\n<strong># find \/ -type f -size +20000k -exec ls -lh {} \\; 2&gt; \/dev\/null | awk &#8216;{ print $NF &#8220;: &#8221; $5 }&#8217;\u00a0 | sort -nrk 2,2<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td>\n<div><strong>Check Memory Fault <\/strong><\/div>\n<div><strong># dd if=\/dev\/urandom bs=768304 of=\/tmp\/memtest count=1050<\/strong><\/div>\n<div><strong># md5sum \/tmp\/memtest; md5sum \/tmp\/memtest; md5sum \/tmp\/memtest<\/strong><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td>Repair Mysql MYISAM File<br \/>\n# myisamchk &#8211;force &#8211;sort_buffer_size=64M &#8211;key_buffer_size=16M &#8211;read_buffer_size=8M &#8211;write_buffer_size=8M ..\/data\/phplists\/phplist_linktrack.MYI<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td>\n<div>DELETE mail Que from Qmail<\/div>\n<div>Steps:<\/div>\n<div># qmail stop<\/div>\n<div># find \/var\/qmail\/queue\/mess -type f -exec rm {} \\;<\/div>\n<div># find \/var\/qmail\/queue\/info -type f -exec rm {} \\;<\/div>\n<div># find \/var\/qmail\/queue\/local -type f -exec rm {} \\;<\/div>\n<div># find \/var\/qmail\/queue\/intd -type f -exec rm {} \\;<\/div>\n<div># find \/var\/qmail\/queue\/todo -type f -exec rm {} \\;<\/div>\n<div># find \/var\/qmail\/queue\/remote -type f -exec rm {} \\;<\/div>\n<div># qmail start<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td>Display sorted process taking most CPU in descending order<br \/>\n# ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td>\n<div>Download FTP files Recursivly using ncftpget<\/div>\n<div>Syntax:<\/div>\n<div><em>ncftpget -R -v -u &#8220;&lt;username&gt;&#8221; -p &#8220;&lt;password&gt;&#8221; &lt;servername not IP&gt;\u00a0\u00a0 &lt;local Path to store \/temp&gt;&lt;destination FTP Server file Path \/www.domain.com\/2009_Feb\/*&gt;<\/em><\/div>\n<div><em>\u00a0<\/em><\/div>\n<div># ncftpget -R -v -u &#8220;ibnlive&#8221; -p &#8220;ibn123&#8221; ftpserver \/temp\/ \/www.domain.com\/2009_Feb\/*<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td>\n<div>Command to make Services off in Defined Level on Linux<\/div>\n<div># chkconfig &#8211;list | awk &#8216;{print $1}&#8217; | cut -d: -f1 | grep -vE &#8216;^crond|^network|^sshd|^syslog|^iptables&#8217; | awk &#8216;{print $1}&#8217; | while read line; do chkconfig\u00a0 &#8211;level 3 $line off; count=`expr $count + 1`; echo $count $line;done<\/div>\n<div><\/div>\n<div>or Use this&#8230; One lineer<\/div>\n<div># chkconfig &#8211;list | awk &#8216;{print $1}&#8217;| grep -vE &#8216;^crond|^network|^sshd|^syslog|^iptables&#8217; | xargs -i chkconfig &#8211;level 3 {} off<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><br \/>\n<\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td>\n<div>Counting Hits from Web Server Access log<\/div>\n<div># awk &#8216;{print $1}&#8217; \/opt\/indian.com\/access_log | grep -vE &#8216;^:|^common|^-&#8216; | sort | uniq -c | sort -nr &gt; \/var\/www\/reports\/ips\/indian.txt<\/div>\n<div><\/div>\n<div>or\u00a0 # awk &#8216;$1&gt;10000 {print $1}&#8217; \/opt\/indian.com\/access_log | uniq -c | sort -nr\u00a0 &gt; \/var\/www\/reports\/ips\/indian.txt<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong><strong><br \/>\n<\/strong><\/strong><\/h3>\n<table border=\"2\">\n<tbody>\n<tr>\n<td>PERL Search and Replace Text Pattern using Perl On linux Platform<br \/>\n# find . -type f -name &#8220;*.html&#8221; | xargs perl -pi~ -e &#8216;s\/\\\/js\\\/active18\\\/\/\\\/read\\\/js\\\/active18\\\/\/&#8217;Killing processes in one Line<br \/>\n# kill -9 `ps -ef | grep rsync| grep -v grep| awk &#8216;{print $2}&#8217;`<\/p>\n<p>Check CPU Temperature<br \/>\n# echo `date +%b-%d-%H:%M:%S` | tr -d &#8216;\\ 012&#8217; ; echo -n &#8216; &#8216;; sensors | awk &#8216;\/CPU Temp:\/{ print $3 }&#8217;<br \/>\nCheck those commands which have been used most<br \/>\n# history|awk &#8216;{print $2}&#8217; |awk &#8216;{print $1}&#8217; | sort | uniq -c | sort -rn | head -10<br \/>\nMount \/ partition in &#8220;Repair Mode&#8221;<code> Repair filesystem <\/code><br \/>\n<code># mount -w -o remount \/<\/code><\/p>\n<p>Free Memory\u00a0 on Linux at Runtime<br \/>\n# sync<\/p>\n<div># echo 3 &gt; \/proc\/sys\/vm\/drop_caches<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Check Validity of a Certificate File (PEM File) # openssl x509 -in Certificates.pem -inform PEM -text -noout -enddate Certificate: Data: <\/p>\n<p>Version: 3 (0x2)<\/p>\n<p>Serial Number:<\/p>\n<p>5b:84:3e:8f:d3:1e:fc:67<\/p>\n<p>Signature Algorithm: sha1WithRSAEncryption<\/p>\n<p>Issuer: C=US, O=Sabe Inc., OU=Sabe Relations, CN=Sabe Certification Authority<\/p>\n<p>Validity<\/p>\n<p>Not Before: Oct 1 11:56:10 2011 GMT Not After : Sep 30 11:56:10 2012 GMT<\/p>\n<p> Sometime [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/921"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=921"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/921\/revisions"}],"predecessor-version":[{"id":923,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/921\/revisions\/923"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}