Thursday, June 25, 2015

python print without newline suppress newline

#Only for use in Python 2.6.0a2 and later
from __future__ import print_function
This allows you to use the Python 3.0 style print function without having to hand-edit all occurrences of print :)
On python 2.x 
simply add   ","  i,e   print  "var1",
>>> for i in range(11):
...     print i,
...
0 1 2 3 4 5 6 7 8 9 10
print() is function in python 3.x
print "xxxx" is statement in python 2.x

Tuesday, June 23, 2015

bash script summary

echo -e "\nServer :" `uptime`; echo "Apache :" `service httpd status | grep -i uptime`; echo "MySQL  :" `echo "status;" | mysql | grep -i uptime`;echo -e "\t" `mysqladmin status`;echo -e "\nType\t Used\t\t Percent"; df -h | sed -n '2,2p' | awk '{print "Disk:\t",$3,"\t\t",$5}';df -i | sed -n '2,2p' | awk '{print "Inodes:\t",$3,"\t",$5,"\n"}';netstat -plan |awk '/.*[0-9]+.[0-9]+.[0-9]+.[0-9].*/{gsub(/::ffff:/,"",$0);print $4"\t" $5}'|cut -sd. -f 1->netstat.log;echo "Netstat report";echo;echo "Number of Connections to each port:";cat netstat.log |awk {'print $1'}|cut -d: -f 2|sort|uniq -c|sort -nk 1|tail;echo;echo "Number of connections from each IP:";cat netstat.log |awk {'print $2'}|cut -d: -f 1|sort|uniq -c|sort -nk 1|tail;echo;echo "The number of instances of a particular IP connecting to particular port";cat netstat.log |awk {'print $1 "\t" $2'}|cut -d: -f 2|sort|uniq -c|sort -nk 1|tail;