Hello,
I want to run this script on my CentOS 6 via browser :
________________________________________________________________________________________________
#!/bin/sh
echo Username?
read MY_NAME
echo Provisional file name?
read MY_FILE
echo File NAME you want to save?
read MY_FILE2
cat /opt/SUNWappserver/nodeagents/ins1/logs/* | grep $MY_NAME > $MY_FILE.txt
sed 's/INFO.*;|//g' $MY_FILE.txt > $MY_FILE2.txt
________________________________________________________________________________________________
For that I have created 2 files : /var/www/html/test.html
and / var/www/cgi-bin/script.sh
:
- I have created one file
test.html
________________________________________________________________________________________________
<HTML>
<TITLE>LOGS</TITLE>
<BODY>
<b>LOGs Instacne</b><p>
<form action="cgi-bin/script.sh" method="post">
<br>
<input type="submit" value="LOG Button">
</form>
</BODY>
</HTML>
- And
/var/ww/cgi-bin/script.sh
#!/bin/sh -f
echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Inscance LOGs</title>'
#Step 1
echo "<form method=GET action=\"${SCRIPT}\">"\
'<table nowrap>'\
'<tr><td>UserName</TD><TD><input type="text" name="val_x" size=12></td></tr>'\
'</tr></table>'
#Step 2
echo "<form method=GET action=\"${SCRIPT}\">"\
'<table nowrap>'\
'<tr><td>File Name not cleaned?</TD><TD><input type="text" name="val_y" size=12></td></tr>'\
'</tr></table>'
#Step 3
echo "<form method=GET action=\"${SCRIPT}\">"\
'<table nowrap>'\
'<tr><td>File NAME cleaned</TD><TD><input type="text" name="val_a" size=12></td></tr>'\
'</tr></table>'
echo '<br><input type="submit" value="Search">'\
'<input type="reset" value="Reset"></form>'
if [ -z "$QUERY_STRING" ]; then
exit 0
else
XX=`echo "$QUERY_STRING" | sed -n 's/^.*val_x=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
YY=`echo "$QUERY_STRING" | sed -n 's/^.*val_y=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
AA=`echo "$QUERY_STRING" | sed -n 's/^.*val_a=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
echo "UserName: " $XX
echo '<br>'
echo "File Not_Cleaned: " $YY
echo '<br>'
echo "File Cleaned: " $AA
echo '<br>'
echo "cat /opt/SUNWappserver/nodeagents/ins1/logs/*" | grep $XX > $YY.txt
browser="`echo $XX | cut -d\ -f1`"
echo '<br>'
echo "Browser: " $browser
BB="`echo $browser | sed 's/INFO.*;|//g' $YY.txt > $AA.txt`"
echo '<br>'
echo '<br>'
echo "Result: " $BB
echo '<br>'
fi
echo '</body>'
echo '</html>'
exit 0
________________________________________________________________________________________________
When I open in browser: localhost/test.html
click on button "LOG Button" it redirects me on localhost/cgi-bin/script.sh
.
I fill in the required fields and click on the search button to show the data, but the cat dhe sed command is not executed ( echo "cat /opt/SUNWappserver/nodeagents/ins1/logs/*" | grep $XX > $YY.txt) and (sed 's/INFO.*;|//g' $YY.txt > $AA.txt
).
Can you give me any suggestions to execute the script shell above in the browser and if i have chosen the wrong way how can i execute this script?
Regards,
Juta2020