top command output not runnibg in html page (1459 Views)
Reply
Regular Advisor
Aamir14
Posts: 116
Registered: ‎07-04-2011
Message 1 of 11 (1,459 Views)

top command output not runnibg in html page

Hi,
 
I want to run top command in html page
and i created script all command run in html page but
top command and sasmgr not running
 
This is my script:-----------------
 
#!/usr/bin/sh
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"
echo "<h1>General system information for host $(hostname -s)</h1>"
echo "<form action="/cgi-bin/top">
  <p style="margin: 2em 20%;">
    <input type="submit" value="DATE" >
  </p>
 </form>"
echo "<button type="button" onclick="/cgi-bin/top">Click Me!</button>"
echo "<h1>Memory Info</h1>"
echo "<pre> $(machinfo) </pre>"
echo "<h1>Disk Info:</h1>"
echo "<pre> $(bdf) </pre>"
print "`top -d 1 > top4.txt`\n";
echo "<pre> $(more top4.txt)</pre>"
echo "<pre> $(tail -1000000 /var/adm/syslog/syslog.log |grep error) </pre>"
echo "<pre> $(tail -1000000 /var/adm/syslog/syslog.log |grep Warning) </pre>"
echo "<pre> $(tail -1000000 /var/adm/syslog/syslog.log |grep CRITICAL) </pre>"
echo "<pre> $(tail -1000000 /var/adm/syslog/syslog.log |grep MAJOR) </pre>"
echo "<pre> $(tail -1000000 /var/adm/syslog/syslog.log |grep failed) </pre>"
echo "<pre> $(tail -1000000 /var/adm/syslog/syslog.log |grep NOTICE) </pre>"
echo "<pre> $(sasmgr get_info -D /dev/sasd0 -q raid |grep /dev/rdsk |awk '{print $5}') </pre>"
echo "<pre> '$(sasmgr get_info -D /dev/sasd0 -q raid |grep /dev/rdsk |awk '{print $5}')' </pre>"
echo "<pre> $(sasmgr get_info -D /dev/sasd0 -q raid > disk.txt) </pre>"
echo "<pre> $(more  disk.txt) </pre>"
 
echo "<pre> $(top -d 1) </pre>
#sasmgr get_info -D /dev/sasd0 -q raid | sleep 2
echo "<pre> $( sasmgr get_info -D /dev/sasd0 -q raid ) </pre>"
 
echo "<center>Information generated on $(date)</center>"
echo "</body></html>"
 
How can we run top and sasmgr command on html page
 
Thanks
aamir
Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 2 of 11 (1,454 Views)

Re: top command output not running in html page

[ Edited ]

In order to get the text formatted top output, you must use the -f option to send it to a file.

echo "<pre> $(top -d 1 -f top-file; cat top-file; rm -f top-file) </pre>

 

>print "`top -d 1 > top4.txt`\n";
>echo "<pre> $(more top4.txt)</pre>"
 
You would need -f here too.  And not use more(1).

 

>echo "<pre> $(more  disk.txt) </pre>"

 

You should also replace more(1) by cat or:

echo "<pre> $(<  disk.txt) </pre>"

Regular Advisor
Aamir14
Posts: 116
Registered: ‎07-04-2011
Message 3 of 11 (1,446 Views)

Re: top command output not running in html page

Hello

 

when i run my script1 on shell its run 

but when i run (or refresh) on html page its not run

 

my question is that 

when i run script1 every single command  run properly is on the script1 and its output shown in html page

 

 

but top command output not shown in the html page  .

 

This is the html output :----------------------------------------------------------------

 

 

General system information for host

Click Me!

Firmware info

 Firmware info:
   Firmware revision:  04.32
   FP SWA driver revision: 1.18
   IPMI is supported on this system.
   BMC firmware revision: 5.26 

Platform info

 Platform info:
   Model:                  "ia64 hp server rx3600"
   Machine ID number:      27220f96-383d-11de-ad39-ef4b35b5d5c9
   Machine serial number:  SGH4913M52 

OS info

 OS info:
   Nodename:  billdev1
   Release:   HP-UX B.11.31
   Version:   U (unlimited-user license)
   Machine:   ia64
   ID Number: 0656543638
   vmunix _release_version:               
@(#) $Revision: vmunix:    B.11.31_LR FLAVOR=perf  

CPU info

 CPU info:
  1 Intel(R) Itanium 2 9100 series processor (1.67 GHz, 18 MB)
          666 MT/s bus, CPU version A1
          2 logical processors (2 per socket) 

/Memory

 Memory: 8161 MB (7.97 GB) 
 
 

Disk Info:

 Filesystem          kbytes    used   avail %used Mounted on
/dev/vg00/lvol3    2097152  274320 1808688   13% /
/dev/vg00/lvol1    3145728  312248 2811432   10% /stand
/dev/vg00/lvol8    25690112 2189912 23316688    9% /var
/dev/vg00/lvol7    5210112 3261024 1933920   63% /usr
/dev/vg00/lvol6    3145728  669744 2456784   21% /tmp
/dev/vg00/lvol5    10485760 6616760 3838784   63% /opt
/dev/vg00/lvol4    1048576   52424  988496    5% /home
appsdev2:/backupserver/appsdev1
                   235929600 131457725 98131283   57% /share 
 
 Nov 22 00:30:13 billdev1 sshd[15224]: error: PAM: Authentication failed for root from 192.168.29.9
Dec  4 13:32:48 billdev1 sshd[5885]: error: PAM: Authentication failed for root from 192.168.10.60
Dec  4 13:32:54 billdev1 sshd[5885]: error: PAM: Authentication failed for root from 192.168.10.60
Dec  5 17:03:40 billdev1 sshd[18427]: error: setsockopt SO_KEEPALIVE: Invalid argument 
 
 
 
 Nov 22 00:30:13 billdev1 sshd[15224]: error: PAM: Authentication failed for root from 192.168.29.9
Dec  4 13:32:48 billdev1 sshd[5885]: error: PAM: Authentication failed for root from 192.168.10.60
Dec  4 13:32:54 billdev1 sshd[5885]: error: PAM: Authentication failed for root from 192.168.10.60 
 Nov 10 15:30:16 billdev1 vmunix: NOTICE: nfs_client_pv3_install(): nfs3 File system was registered at index 10.
Nov 10 15:30:16 billdev1 vmunix: NOTICE: nfs_client_pv4_install(): nfs4 File system was registered at index 11.
Nov 10 15:30:16 billdev1 vmunix: NOTICE: cachefsc_install: cachefs File system was registered at index 13. 
 
 '' 

 

please suggest me how can do this

 

Thanks

Aamir

Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 4 of 11 (1,443 Views)

Re: top command output not running in html page

>please suggest me how can do this

 

I did.  Did you try -f top-file?

Regular Advisor
Aamir14
Posts: 116
Registered: ‎07-04-2011
Message 5 of 11 (1,437 Views)

Re: top command output not running in html page

yes i done that.

 

see it.

 

echo "<pre> $(top -d 1 -f top-file; < top-file) </pre>"
echo "<pre> $(more top-file)</pre>"
 
 
but cant run on html page.
 
 

Thanks

aamir

Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 6 of 11 (1,434 Views)

Re: top command output not running in html page

[ Edited ]

>echo "<pre> $(more top-file)</pre>"

 

No need for that more(1) line, the cat on previous should do it.

 

What's in top-file?  You may need to capture stderr:

echo "<pre> $(top -d 1 -f top-file 2>> top-file; cat top-file) </pre>"

Regular Advisor
Aamir14
Posts: 116
Registered: ‎07-04-2011
Message 7 of 11 (1,426 Views)

Re: top command output not running in html page

hello

 

i already ran on sh shell 

but when i refresh html page on browser it shown older entry.

 

I already run the command on shell 

 

i want to  refresh command output on every single click(refresh) in browser.

 

 

Thanks

aamir

 

 

 

Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 8 of 11 (1,412 Views)

Re: top command output not running in html page

>i want to  refresh command output on every single click(refresh) in browser.

 

Are the other (non-top) values changing?  Make sure you remove that output file.

Regular Advisor
Aamir14
Posts: 116
Registered: ‎07-04-2011
Message 9 of 11 (1,405 Views)

Re: top command output not running in html page

Hi,

 

This is my file:-----------------------------------

 

#!/usr/bin/sh
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"
echo "<h1>General system information for host $(hostname -s)</h1>"
echo "<pre> $(top -d 1 -f top-file 2> top-file; cat top-file) </pre>"
echo "<center>Information generated on $(date)</center>"
echo "</body></html>"
 
and this is my html output:-----------------------------
----------------------------------------------------------------------------------
 
General system information for host
 
Information generated on Tue Dec 31 11:45:53 IST 2013
 
 
Please suggest me what is a problem ?
 
Thanks
aamir
 
 
 
 
 
 
 
 
Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 10 of 11 (1,394 Views)

Re: top command output not running in html page

>Please suggest me what is a problem?

 

What's in top-file?  Also "2>" should probably be "2>>".

 

What happens when you invoke:

top -d 1 -f top-file 2> top-file; cat top-file

Honored Contributor
Laurent Menase
Posts: 1,079
Registered: ‎11-06-2003
Message 11 of 11 (1,377 Views)

Re: top command output not running in html page

Are you sure the cgi bin as access right on current dir? try to put the file on /tmp

echo "<pre> $(top -s 1 -d 1 -f /tmp/top-file_$$ >/tmp/top-fileout$$ 2>&1; cat /tmp/top-file_$$ ; rm -f /tmp/top-fileout$$  /tmp/top-file_$$ ) </pre>"

Are you sure your web server don't timeout?

may be try

echo "<pre> $(top -s 1 -d 1 -f /tmp/top-file_$$ >/tmp/top-fileout$$ 2>&1; cat /tmp/top-file_$$ ; rm -f /tmp/top-fileout$$  /tmp/top-file_$$ ) </pre>"

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.