LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 05-18-2012, 03:07 AM   #1
rajib_145
LQ Newbie
 
Registered: May 2012
Posts: 12

Rep: Reputation: Disabled
Question CGI-Shell Script runs ok in command prompt but not through the webpage


Hi Linux Gods,
I am a newbie and need your kind help.
On my Linux machine i have installed apache and was successfull in completing the initial steps like, managed to run it as different user with administrative rights(adding the user to Wheel group), also with the help of this forum i was able to create the webpage and call cgi scripts.
Now the problem is:

The cgi shell script seems to be ok according to my best knowledge as it runs perfectly alright while running fron my shell, but it doesnot work from the website.

By the way:

The Script goes like this:

#!/bin/bash
#Taking the arguments from a html page
host=`echo $QUERY_STRING | awk -F'=' '{ print $3 }'`
user=`echo $QUERY_STRING | awk -F'[= &]' '{ print $2 }'`


echo 'Content-type: text/html'
echo ''
echo '<html>'

entry="$user $host=ALL"

if `sudo ssh "$hostname" "echo "$entry" >> /etc/sudoers"`
then
echo "Sudo permission Given for $user on $host" > /path
else
echo "Sudo permission for $user on $host is not Successfull" > /path
fi

echo '</body>'
echo '</html>'




I am really getting confused where i am getting wrong.

Last edited by rajib_145; 05-18-2012 at 03:17 AM. Reason: bad english
 
Old 05-18-2012, 03:09 AM   #2
rajib_145
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Kindly let me know for any other information, I really need to know this as i have gone a long distance and just because of this problem, i am stuck in the middle of sea. Please help me!!!!
 
Old 05-18-2012, 03:37 AM   #3
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,143

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
have you got any error messages?
 
Old 05-18-2012, 03:45 AM   #4
rajib_145
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thanks for the reply.

There is no error msg displayed on webpage.

And in the below path:
/var/www/error
there are many files with .var extension.
Iam sorry im really new to this, kindly accept my appology if i am not able to provide you any information which is very simple for others.
 
Old 05-18-2012, 03:49 AM   #5
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,143

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
you can put some logging into that script:
Code:
#!/bin/bash
set -xv
exec 2>/tmp/logfile.txt
...
and after test you can check that logfile. Without any error message we cannot give you a solution.
 
Old 05-18-2012, 03:51 AM   #6
rajib_145
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
I checked the below file:

/var/log/httpd

and found these below three lines:

[Fri May 18 01:43:13 2012] [error] [client IP-address] sudo: , referer: http://ip-address/webpage.html
[Fri May 18 01:43:13 2012] [error] [client IP-address] sorry, you must have a tty to run sudo, referer: http://ip-address/webpage.html
[Fri May 18 01:43:13 2012] [error] [client IP-address] , referer: http://ip-address/webpage.html

Kindly let me know if this is ok..
 
Old 05-18-2012, 03:57 AM   #7
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,143

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
see this
http://www.question-defense.com/2009...ty-to-run-sudo
 
Old 05-18-2012, 03:58 AM   #8
rajib_145
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Hi All, this is the o/p that i got:


$ cat /tmp/logfile1.txt



entry="$user $host=ALL"
+ entry='user wipwab59=ALL'

if `sudo ssh wipwab59 "echo "$entry" >> /etc/sudoers"`
then
echo "Sudo permission Given for $user on $host" > /local/administrativescripts/reports/sudo
else
echo "Sudo permission for $user on $host is not Successfull" > /local/administrativescripts/reports/sudo
fi
sudo ssh wipwab59 "echo "$entry" >> /etc/sudoers"
++ sudo ssh wipwab59 'echo user' 'wipwab59=ALL >> /etc/sudoers'
sudo: sorry, you must have a tty to run sudo
+ echo 'Sudo permission for user on wipwab59 is not Successfull'


#sudo /local/administrativescripts/sudopermission_apache.sh wipwab59 rahul
#/local/administrativescripts/sudopermission_apache.sh $host $user
#sudo /local/administrativescripts/sudopermission_apache.sh $host $user


cat /local/administrativescripts/reports/sudo
+ cat /local/administrativescripts/reports/sudo

echo '</body>'
+ echo '</body>'
echo '</html>'
+ echo '</html>'
 
Old 05-18-2012, 04:00 AM   #9
rajib_145
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thanks i will read this and get back to you... Thanks you again..
 
Old 05-18-2012, 04:03 AM   #10
rajib_145
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thank you so much sir, thank you thank you thank you...Its working smoothly... Thanks for your help sir..
 
Old 05-18-2012, 04:46 AM   #11
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,143

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
great, I'm glad it helped





_________________________________
Happy with solution ... mark as SOLVED
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash][awk] command runs from shell, not from script JohnyDRipper Programming 2 03-09-2012 06:01 AM
help with a shell script that runs 'dos2unix' command on files in a directory, keerti Linux - Newbie 6 01-30-2012 11:06 AM
Run My CGI Script from Webpage mykolg Linux - Server 6 01-17-2011 03:17 AM
command runs at prompt not in script newbie_m Linux - Newbie 2 01-20-2005 03:12 PM
CGI script problem: Send/Expect command echo on webpage rajatgarg Programming 2 07-11-2004 05:38 PM


All times are GMT -5. The time now is 12:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration