/var/www/cgi-bin/hello.sh
#!/bin/Bashecho"content-type:text/html"Echo""Echo''Echo''Echo'<meta http-equiv= "Content-type" content= "text/html; charset=utf-8" >'Echo'<title>hello world</title>'Echo''Echo'<body>'Echo'Hello World'Echo'</body>'Echo''Exit0
View Code
Give Execute permission:
chmod +x/var/www/cgi-bin/hello.sh
If you use SELinux, you must execute the following command: chcon-t httpd_sys_content_t/var/www/cgi-bin/hello.sh
Access:
http://ip/cgi-bin/hello.sh
Similarly:
/var/www/cgi-bin/uptime.sh
#!/bin/Bashecho"content-type:text/html"Echo""Echo''Echo''Echo'<meta http-equiv= "Content-type" content= "text/html; charset=utf-8" >'Echo'<link rel= "SHORTCUT ICON" href= "Http://www.megacorp.com/favicon.ico" >'Echo'<link rel= "stylesheet" href= "Http://www.megacorp.com/style.css " type= "Text/css" >'PATH="/bin:/usr/bin:/usr/ucb:/usr/opt/bin"Export $PATHecho'<title>system uptime</title>'Echo''Echo'<body>'Echo''Hostnameecho''Uptimeecho'</body>'Echo''Exit0
View Code
http://192.168.1.112/cgi-bin/uptime.sh
/var/www/cgi-bin/env.sh
#!/bin/Bashecho"content-type:text/html"Echo""Echo''Echo''Echo'<meta http-equiv= "Content-type" content= "text/html; charset=utf-8" >'Echo'<title>environment variables</title>'Echo''Echo'<body>'Echo'Environment Variables:'Echo'<pre>'/usr/bin/Envecho'</pre>'Echo'</body>'Echo''Exit0
View Code
Http://192.168.1.112/cgi-bin/env.sh?namex=valuex&namey=valuey&namez=valuez
Reference:
Http://www.yolinux.com/TUTORIALS/BashShellCgi.html
Using the shell to write CGI (HTTPD) in a Linux environment