Forum Stats

  • 3,769,583 Users
  • 2,252,984 Discussions
  • 7,875,103 Comments

Discussions

Unable to ssh to a remote machine while calling the script through web

User771294-Oracle
User771294-Oracle Member Posts: 3
edited Jun 1, 2015 2:09PM in Python

I have a Linux machine where I have created a cgi script (JarPatch.cgi), the code of which looks like this:

<span class="com" style="color: #808080;">#!/usr/bin/perl</span><span class="pln" style="color: #000000;"><br/></span><span class="kwd" style="color: #00008b;">use</span><span class="pln" style="color: #000000;"> warnings</span><span class="pun" style="color: #000000;">;</span><span class="pln" style="color: #000000;"><br/></span><span class="kwd" style="color: #00008b;">print</span><span class="pln" style="color: #000000;"> </span><span class="str" style="color: #800000;">"Content-type: text/html\n\n"</span><span class="pun" style="color: #000000;">;</span><span class="pln" style="color: #000000;"><br/>system </span><span class="pun" style="color: #000000;">(</span><span class="str" style="color: #800000;">"sh JarPatch.sh"</span><span class="pun" style="color: #000000;">);</span>



The code of JarPatch.sh looks like this:

<span class="com" style="color: #808080;">#!/bin/bash</span><span class="pln" style="color: #000000;"><br/><br/>echo </span><span class="str" style="color: #800000;">"Inside jar patching tool"</span><span class="pun" style="color: #000000;">;</span><span class="pln" style="color: #000000;"><br/><br/>PJS_DEV</span><span class="pun" style="color: #000000;">=</span><span class="pln" style="color: #000000;">[email protected]</span><span class="pun" style="color: #000000;">.</span><span class="pln" style="color: #000000;">us</span><span class="pun" style="color: #000000;">.</span><span class="pln" style="color: #000000;">oracle</span><span class="pun" style="color: #000000;">.</span><span class="pln" style="color: #000000;">com</span><span class="pun" style="color: #000000;">;</span><span class="pln" style="color: #000000;"><br/>ssh </span><span class="pun" style="color: #000000;">-</span><span class="pln" style="color: #000000;">f $PJS_DEV  </span><span class="str" style="color: #800000;">"cd /slot/ems4915/appmgr/tmp; echo stopping server ; ./find_stop_servers.sh;"</span><span class="pln" style="color: #000000;"><br/><br/>  echo </span><span class="str" style="color: #800000;">"Exit jar patching tool"</span><span class="pun" style="color: #000000;">;</span>


This script will basically shut down a server running on the remote machine

Problem statement is this: When I execute this cgi script through Linux terminal, I can see that the ssh commands are getting executed and as a result server is shut down.

When I access the cgi script through a  browser, the shell script is invoked but ssh seems not to be working.

Can any one give me a pointer to resolve this issue please? I am new to perl/shell integration. So might be missing something small as well. Thanks

Answers

This discussion has been closed.