Tuesday 21 November 2017

bash shell script to html

Hi All,

I have searched so many website for linux command output to html out put and I didn't get much finally I got one small samble and i made that with required command output to html. 

Here I have put the details in below.

#echo "<html><head><title>Chain-Sys</title><style>body{font-family:arial;font-size:13px;background:#f8f8f8;margin:0;padding:0}body h1:first-child{text-align:center;font-size:28px;background:#fff;border-bottom:#eee 1px solid;padding:20px;color:#09c;box-shadow:0 1px 2px #e8e8e8}h1{font-weight:400;font-size:18px;padding:0 20px}pre{background:#f2f2f2;padding:20px;margin:20px;border-radius:5px;border:1px solid #e8e8e8;font-family:Courier New,arial}</style></head><body>"
echo "<h1>Informations of host  - `hostname`</h1>"
echo ""
echo "<h1>Server Details</h1>"
echo "<pre>`hostname -i && date && uptime` </pre>"
echo "<h1>top process list</h1>"
echo "<pre> `ps aux | sort -nrk 3,3 | head -n 5` </pre>"
echo "<h1>CPU utilization on current server</h1>"
echo "<pre> `top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }'` </pre>"
echo "<h1>List of iptables rule</h1>"
echo "<pre> `iptables -L` </pre>"
echo "<h1>Memory Info</h1>"
echo "<pre> `free -m` </pre>"
echo "<h1>Disk Info:</h1>"
echo "<pre> `df -h` </pre>"
echo "<h1>Active Connections</h1>"
echo "<pre> `ss -s` </pre>"
echo "<h1>Logged in users</h1>"
echo "<pre> `last | tail -10` </pre>"
echo "<h1>I/N Connection</h1>"
echo "<pre> `/opt/trial/sh.sh` </pre>"
echo "<h1>Number of Process</h1>"
echo "<pre> `cat /proc/stat | grep proc*` </pre>"
echo "<h1>NFS Mount Status</h1>"
echo "<pre> `mount -l -t nfs` </pre>"
echo "<h1>Crond Status</h1>"
echo "<pre> `crontab -l` </pre>"
echo "<h1>Failed Login Attempts</h1>"
echo "<pre> `less /var/log/secure | grep Failed` </pre>"
echo "<center>Information generated on `date`</center>"
echo "</body></html>"

 

For I/N connection I have add a sh file with below script.

if ping -q -c 1 -W 1 google.com >/dev/null; then
echo "I/N is Available"
else
echo "I/N is Unavailable"
fi

 

save this script as ss.sh and put same place of this script.

Just save the file as sh and run like below and check it will work 100%.

save as sample.sh  and run

./sample.sh > sample.html

open the output in browser.  

If you have any better idea please share me the knowledge I'm having knowledge thirst or any suggestion please reply as command. 

Thanks for viewing.

No comments:

Post a Comment

Permanent hostname setup for RHEL7

Step 1 Set the host name on NMTUI tool like following nmtui set host name   then save and exit Step 2 add the following l...