Sep 25, 2011

Locking windows xp/vista in command line

Found this command when i tried to lock my remote PC (xp), its useful when you need to lock your VM or remote desktops. 

rundll32.exe user32.dll, LockWorkStation


Note: this is case sensitive, otherwise will give dll errors.

May 10, 2011

Create full format Excel file from bash scripts

This post shows how I managed to create a excel output with all the bells and whistles of the MS Excel such as merging, colors on the tables and etc.
Open your excel sheet if you have already or make a template of your needed output format.
 



Save it as XML Spreadsheet 2003 .xml format in your drive.





Ignore the following pop up and hit Yes.

 


Open the saved xml with your favorite editor, in my case Notepad++.
 


Now you can see your data filled inside <Table> tag. you can simply parse the data from your real output and replce the start and end with these Tags " <Cell ss:StyleID="s62"><Data ss:Type="Number">" and "</Data></Cell>" then write the whole data in a excel file (something.xls). In my case i have parsed a file for the numbers output and replced the start and end with the xml tags.

Eg: grep "Selected Period" PV.html|sed -ne 's/^.*Selected Period\([^T]*\).*$/\1/p'| sed 's/\\//g;s/nt*//g;s/\///g;s/\&bsp;//g;s/<[^>]*>/\n/g'|sed 's/[0-9]\.//g;s/^ //g;/^$/d;/[a-z].*/d;s/^/\<Cell ss\:StyleID="s112"\>\<Data ss\:Type="Number"\>/g;s/$/\<\/Data\>\<\/Cell\>/g' > opv.dat




Hope this helps to create an excel from Bash.

Happy Scripting.
Deva.

Mar 12, 2011

Unix host disk usage HTML report

Below can provide the disk usage from multiple hosts in a HTML format report sorted with usage percentage.

Echo “From: Deva
To: someone@mail.com
MIME-Version: 1.0
Content-Type: text/html
Subject: Disk_usage" > te12
 
check_lvnodes 'df -g |sed "s/^/`hostname`_/g"' > teak;check_lvwebs 'df -g|sed "s/^/`hostname`_/g"' >> teak;
\(cat te12;echo "

";sort -nr -k4 teak |awk -F" " '$4 > 50'|head -300|sed '/Mounted/d;s/  */ /g;s/ /\&lt
\;\/td\>\/g;s/$/\<\/td\>\<\/tr\>/g;s/^/\\/')|sendmail –t    
DevtotalFreeUsedIfreeIUsedMount

Starting multiple JVMs through ssh

If you ssh auto is enabled from a central server, starting multiple jvms on several nodes is easy. Below shows for two jvms per node,


for sv in ccaita1k ccaita1l ccaita1m ccaita1n ccaita67 ccaita69 ccaita7p ccaita7q ccaita7r ccaita7x ccaita7y ccaita8k ccaita8l ccaitack; do
ssh $sv 'cd /opt/isv/WAS51/AppServer/bin; ./startServer.sh WC_THD_`hostname` -nowait; ./startServer.sh WC_THD2_`hostname` -nowait'
done