Oct 12, 2011

malformed header from script. - CGI Bash

A CGI bash script will throw error as malformed header from script. in the web server error log when the content is not spaced, To eliminate this error give a empty line/newline after content.

#!/bin/bash
echo "Content-type: text/html"
echo
the log may look like this,
[Tue Oct 11 14:09:42 2011] [error] [client 172.16.32.215] malformed header from script. Bad header=TEST: test.html

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