09-09-2008
Invoke shell script in cgi script
Hi,
I just tried to call a simple shell script from a cgi script writing in c programming.But,it is not working.i will be grateful if anyone can show me the problems going on as i m new to c and oso shell script.Thanks.
-Here is my shell script of call the 'pc shut down' system command in ubuntu linux:-
shellscript name:myscript
#!/bin/sh/
echo "Type 'y' to shutdown,or any other ket to cancel"
read INPUT
if["$INPUT="y"];then
shutdown -h now
else exit
fi
-Below is my cgi script:-
#include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>
// Required by for routine
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
void HandleSubmit();
void ShowForm();
int cgiMain() {
cgiHeaderContentType("text/html");
/* Top of the page */
fprintf(cgiOut, "<HTML><HEAD>\n");
fprintf(cgiOut, "<TITLE>demo</TITLE></HEAD>\n");
fprintf(cgiOut, "<BODY bgcolor=\"#c0c0c0\">\n");
/* If a submit button has already been clicked, act on the
submission of the form. */
if ((cgiFormSubmitClicked("shutdown") == cgiFormSuccess))
HandleSubmit();
/* Now show the form */
else{
ShowForm();
}
/* Finish up the page */
fprintf(cgiOut, "</BODY></HTML>\n");
return 0;
}
void HandleSubmit()
{
int pid = -1;
pid = fork();
if(pid ==0){
//child process
fprintf(cgiOut, "This is child process<br/>");
char *args[] = {"/sbin/shutdown", "-h", "now", "2>&1", (char*)0};
if(execv("/sbin/shutdown -h", args)==-1)
fprintf(cgiOut, "<br/>execv failed");
}
else{
fprintf(cgiOut, "<strong><font color=\"#000066\">Operating system is shutting down......<br/>\n");
fprintf(cgiOut, "Please close your web broswer</font></strong>");
exec("myscript");
int status;
waitpid(pid, &status, WNOHANG);
}
}
void ShowForm()
{
fprintf(cgiOut, "<!-- 2.0: multipart/form-data is required for file uploads. -->");
fprintf(cgiOut, "<strong><font color=\"red\">Notice:<br/></font>\n");
fprintf(cgiOut, "By clicking the \"Shutdown\" button, the server operating system<br/>\n");
fprintf(cgiOut, "< will be shutting down/strong><br/>\n");
fprintf(cgiOut, "<form method=\"POST\" enctype=\"multipart/form-data\" ");
fprintf(cgiOut, " action=\"");
cgiValueEscape(cgiScriptName);
fprintf(cgiOut, "\">\n");
fprintf(cgiOut, "<input type=\"submit\" name=\"shutdown\" value=\"Shutdown\">\n");
fprintf(cgiOut, "</form>\n");
}
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi everybody,
i learning unix now only.Can u pls guide me in invoking a shell script.Actually i need to know how to write the command for invoking the shell script.Suppose the shell file name is count , then how i will write the command.
thanks (1 Reply)
Discussion started by: gopa_mani
1 Replies
2. Shell Programming and Scripting
Bourne: How to invoke an alias from within a shell script
If I type in the alias in the command line, it runs
If I insert that same alias into my shell script and run the shell script, the alias is not invoked.
Help please. (2 Replies)
Discussion started by: techshots
2 Replies
3. UNIX for Dummies Questions & Answers
hi all,
forgive me if this question is not relevant to this section.
i have a shell file that will automatically deploy the files that are necessary and will compile them. i need to automate this management process through cruise control, for this i need to know whether it is possible for me to... (2 Replies)
Discussion started by: sais
2 Replies
4. Shell Programming and Scripting
Hi,
I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input.
I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies
5. Shell Programming and Scripting
Hi all,
I have a shell script which does db shutdown ..the script snippet which does this is as follows:
function call_sql_plus {
${SQLPLUS:-sqlplus} -s /nolog <<EOF
EXIT;
EOF
if
then
echo "Error occurred while calling sqlplus "
... (3 Replies)
Discussion started by: KrishnaSaran
3 Replies
6. Shell Programming and Scripting
Hi All ,
i am trying to switch user (from unix1 to unix 2 ) The user will give me the input and also the password . also how can i login into with the password . itried several attempts . no luck
Can any one help on this !!! (4 Replies)
Discussion started by: raghav1982
4 Replies
7. Shell Programming and Scripting
i have a script which has 2 options.
a
b
And a has 6 sub options.
i want to write a script which will call the parent script and give options automatically.
examle:
linasplg11:/opt/ss/kk/01.00/bin # startup.sh
/opt/ss/rdm/01.00
Please select the component to... (2 Replies)
Discussion started by: Aditya.Gurgaon
2 Replies
8. Shell Programming and Scripting
hi,,
i have perl scipt with line :
system('./try.sh $t $d $m');
in shell scipt try.sh i have the line:
echo $1
its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies
9. UNIX for Dummies Questions & Answers
Hello all,
Is there a way I can invoke a shell script when ever a new mail is delivered to my account in solaris? Something like .forward file, instead of forwarding it to another email id, I want the email to be passed onto some shell script.
Basically I want to extract the envelop... (3 Replies)
Discussion started by: atukuri
3 Replies
10. Shell Programming and Scripting
Hi,
I have create a Shell Script, with one function.
I want to call the script file in Java Program.
It working fine. but the problem is the function in the Shell Script is not executed.
Please suggest me,
Regards,
Nanthagopal A (2 Replies)
Discussion started by: nanthagopal
2 Replies