scp Commands not executing via cgi script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scp Commands not executing via cgi script
# 1  
Old 10-17-2016
scp Commands not executing via cgi script

Hi,

I have a CGI script, which includes a python custom header file. The cgi script calls a few functions.

Py file.

Code:
#resourcemanager creation

def make_rm(rmip,nip,nport):
    fp = open("temp1.txt",mode="w")
    fp.write('<?xml version="1.0"?>\n<!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file.-->\n\n<configuration>\n\n<!-- Site specific YARN configuration properties -->\n\n<property>\n<name>yarn.resourcemanager.resource-tracker.address</name>\n<value>'+rmip+':8025</value>\n</property>\n\n<property>\n<name>yarn.resourcemanager.scheduler.address</name>\n<value>'+rmip+':8030</value>\n</property>\n\n</configuration>')
    fp.close()
    commands.getstatusoutput("sshpass -p redhat scp temp1.txt "+rmip+":/hadoop2/etc/hadoop/yarn-site.xml")

    fp = open("temp2.txt",mode="w")
    fp.write('<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?>\n<!--  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file.-->\n\n<!-- Put site-specific property overrides in this file. -->\n\n <configuration>\n\n<property>\n <name>fs.default.name</name>\n<value>'+nip+':' +nport+ '</value>\n</property>\n</configuration>\n')
    fp.close()
    commands.getstatusoutput("sshpass -p redhat scp temp2.txt "+rmip+":/hadoop2/etc/hadoop/core-site.xml")
    # print("Resourcemanager setup.\n")

    commands.getstatusoutput("sshpass -p redhat ssh -o StrictHostKeyChecking=no root@"+rmip+" yarn-daemon.sh start resourcemanager")

    a = commands.getstatusoutput("sshpass -p redhat ssh -o StrictHostKeyChecking=no root@"+rmip+" /usr/java/jdk1.7.0_79/bin/jps | grep 'ResourceManager' | awk '{print $2}'")

    if a[1] == "ResourceManager":
        print("ResourceManager setup complete!")

Now, when i call this function throught the cgi script via the browser, the scp command doesn't work. But it works fine if i run the cgi script through the terminal as " python autoip.cgi ". This executes the scp command and everything works well.

I would appreciate any help available on this.

Last edited by adi.6194; 10-17-2016 at 05:55 PM..
# 2  
Old 10-18-2016
This might be a permissions issue. Remember that the webserver account (often Apache) will be the one that calls your code. What do you have in the error logs?

Can you run any cgi-script through your webserver, e.g. just a simple Hello display. That way we can check that you have the code in the right place too.



Robin
# 3  
Old 10-18-2016
I'm not sure about that. It runs all the other commands in the function apart from the one that involves scp.

Yes, I can run cgi-script through the browser. It does give me an output, but it doesn't copy the temp file into the appropriate location on the other VM. So i can't setup my cluster.

The cgi-sript if it helps:

Code:
#!/usr/bin/python

import cgi
import cgitb
import os
import commands
import base2
cgitb.enable()

print "content-type:text/html"
print ""

dn_iplist=[]

base2.ipscanner();
base2.freemem();
base2.procno();
base2.freehd();

dn_iplist = sorted(base2.spacedict, key=lambda x: float(base2.spacedict[x][:-1]), reverse=True)[:2]

masterdict = base2.memdict.copy()

for key in dn_iplist:
	if key in masterdict: 	
		del masterdict[key]

#print masterdict

#####################Resource Manager IP
rmip = max(masterdict, key=lambda key: int(masterdict[key]))
del masterdict [rmip]
#####################Namenode IP
nnip = max(masterdict, key=lambda key: int(masterdict[key]))
del masterdict[nnip]
#####################Client IP
cip = max(masterdict, key=lambda key: int(masterdict[key]))

print """
<html>
<head>
	<title>Hadoop Cluster Services - Create and Manage your Hadoop clusters</title>
	<link rel="stylesheet" type="text/css" href="/css/style1.css">
</head>

<body>
		<br><b>
		<div class="drop">
		<ul class="drop_menu">
			<li><a href="home.html">HOME</a></li>
			<li><a href="create.cgi">CLUSTER</a>
				<ul>
					<li><a href="/loader.html">Create Cluster</a></li>
					<li><a href="#">Manage Cluster</a></li>	
				</ul>
			</li>
			<li><a href="#">SERVICES</a>
				<ul>
					<li><a href="#">Shell</a></li>
					<li><a href="#">Create Cluster</a></li>	
					<li><a href="#">System Admin</a></li>	
				</ul>
			</li>
		</ul>	
		</div>

	<br><br><br><br><br>
	<div id="autoips">
		Resource Manager IP: """ 
print rmip
print "<br><br>Namenode IP: "
nport = "9001"
print nnip + ":" + nport 
print "<br><br>Client IP: "
print cip
print "<br><br>Datanodes/NodeManagers: "
for k in dn_iplist:
	print k + ","
#print """<br><br><input type="submit" value="Accept"> """

print "<br><br><br> BUILDING CLUSTER"

print"""		
	
	</div>

</body>

</html>
"""

base2.make_rm(rmip,nnip,nport)
print "<br>"
base2.make_nn(nnip,nport)
print "<br>"
base2.make_client(nnip,nport,rmip,cip)
print "<br>"
for dnip in dn_iplist:
	print dnip	
	base2.make_dnnm(nnip,nport,rmip,dnip)
	print "<br>"


I've attached a screenshot of the output.
The last line should be similar to the one above it. But it isn't cuz the file isn't copied. The one above displays that because it still has the files from a previous manual execution.
scp Commands not executing via cgi script-screenshot-2016-10-17-00-04-45png
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Commands not executing after FTP in shell script

Hello In the shell script we have a FTP command like below ftp -n -v -q winftp.principal.com >/infa/datafiles/GRP/Scripts/ftp_from_infa_dvcn.log<<END_SCRIPT   quote USER $FTP_USER quote PASS $FTP_PASS ascii lcd $FTP_LOCALDIR cd $FTP_FLDR put $FTP_FILE   bye exit If i... (1 Reply)
Discussion started by: Pratik4891
1 Replies

2. Shell Programming and Scripting

Run SCP in backgroung using Perl CGI

Hi I am Run Perl CGI Script. In which i am running SCP Command. But I want that command to be run into background and exit the script. But Still Web page waiting for Finish the script. I m doing like : system ("scp -r machinename:/path/to/file/for/copy/ /path/for/ destination/directory/ &");... (3 Replies)
Discussion started by: Navrattan Bansa
3 Replies

3. Shell Programming and Scripting

Execution problem unix commands in Perl CGI

I am trying to run SSH , mkdir and other unix commands using Perl CGI. But i am not able to Execute these commands. Please help me out !!!! SSH and mkdir is necessity for me. I will be thankful to you...!!!!! I am trying like: In perl CGI file i am writing like: @list = `ssh... (28 Replies)
Discussion started by: Navrattan Bansa
28 Replies

4. Shell Programming and Scripting

Executing a shell script containing awk commands

Hi All, I am trying to execute a shell script containg awk commands. But unable to do so. Below is my script. Please help. The name of the script is scan.sh and I have tried executing it using the command sh scan.sh It is giving an error which reads like: awk:syntax error near line 7... (3 Replies)
Discussion started by: misb
3 Replies

5. Web Development

cgi script and external UNIX commands (like swadm)

Hi, I am trying to implement a server monitoring dashboard using cgi scripting. I am planning to run the necessary unix scripts from the web page using cgi. This method works fine for standard unix commands but I am unable to run some external unix commands (like swadm show_processes, swadm... (9 Replies)
Discussion started by: jofinjoseph
9 Replies

6. Solaris

executing cgi programs in solaris(B89) needed urgent help,pls!

Hi all, I am trying to execute cgi scripts on solaris, but everytime i get a internal server error... The syntax of my .cgi script is correct as ive checked.. Steps i followed 1.started apache 2.The UNIX and Linux Forums - Learn UNIX and Linux from Experts (in opera) 3.places my cgi scripts... (7 Replies)
Discussion started by: wrapster
7 Replies

7. Shell Programming and Scripting

Executing TL1 commands through script

HI , I have to write a script for some testing , which will telnet to a device and execute some TL1 commands.. Does any one knows how to execute TL1 commands through a script Thanks in advance Binu (1 Reply)
Discussion started by: msbinu
1 Replies

8. Shell Programming and Scripting

Doubt on Executing unix commands in script

How can I execute the unix command "cd - Change directory" command, so that my command prompt should be reflected for that change. Example : Now you are in your home directory i.e /home/naresh and you have some sub directory called unixinfo in your home directory. i want to write a script,so... (2 Replies)
Discussion started by: Naresh Kumar
2 Replies

9. Shell Programming and Scripting

Executing ksh script from cgi

Hi all, I'm developing a system which requires me to run a ksh script from within a cgi script. What sort of syntax will I need to do this, I'm sure it's simple but can't find out how anywhere! Thanks. (1 Reply)
Discussion started by: hodges
1 Replies

10. Shell Programming and Scripting

CGI passing arrays/hashes to another CGI script

If I have a Perl CGI script (script01), which fills an array(s) with information and outputs a HTML page with a link to another CGI page (script02); is there anyway to pass the array(s) from "script01" to "script02" when the page visitor clicks the link? Hope that makes sense! :) (2 Replies)
Discussion started by: WIntellect
2 Replies
Login or Register to Ask a Question