Tuesday, January 25, 2011

Linux : 1-liners needed by a DBA

1. Convert variable data from upper/lowercase to lower/uppercase:

   STRING=ExaMple
   echo $STRING | tr '[:lower:]' '[:upper:]'  ==> EXAMPLE
   echo $STRING | tr '[:upper:]' '[:lower:]'  ==> example

   Another example (shell script : test.sh)  :-
   #!/bin/bash
   ############################################################
   #      Example : Convert case of a string                  #
   ############################################################
   HOSTNAME=`hostname|awk -F\. '{print $1}'|tr '[:lower:]' '[:upper:]'`
   echo "Upper case HOSTNAME : ${HOSTNAME}"
   HOSTNAME=`hostname|awk -F\. '{print $1}'|tr '[:upper:]' '[:lower:]'`
   echo "Lower case HOSTNAME : ${HOSTNAME}"

2.  Top 10 memory consuming processes
     ps uax --sort=-rss|head -10

3.  Top 10 CPU intensive processes
     ps uax --sort=-pcpu|head -10