Send commands to unix server from client application

Serge

New Member
Hi All,

I don't know if it's possible but I'm trying to send some commands to a UNIX machine from a progress GUI client application (.w) running on my PC.

Can this be realised in some way? There is a NetTerm software installed to make a telnet connection to the UNIX server. Maybe by loading an OCX into my window??

Anyone experience with this kind of things?

I would appreciate any help.

Thanks in advance ...
 

Cecil

19+ years progress programming and still learning.
Hi All,

I don't know if it's possible but I'm trying to send some commands to a UNIX machine from a progress GUI client application (.w) running on my PC.

Can this be realized in some way? There is a NetTerm software installed to make a telnet connection to the UNIX server. Maybe by loading an OCX into my window??

Anyone experience with this kind of things?

I would appreciate any help.

Thanks in advance ...

Hi.

The easiest way from progress (slap hand.. OpenEdge), would to use an AppServer. Progress Win32 client connected to Unix/Linux Progress AppsServer. Simple.

However if there are many Unix/Linux servers to connect to issue commands, try the more complex path of using sockets and connecting to the telnet port. Then there could be an issue of security and LONG development time to deliver.

Also try using a rsh/ssh executable for Windows. Shell out to the Windows OS and run the executable. i.e. rsh unixserver -l usernam command

Code:
def var cOSCommand as character no-undo.
def var cRemoteOSCommand as character no-undo.

Asssign
   cRemoteOSCommand = 'df -h':U
   cOSCommand = substitute('rsh &1 -l &2 &3':U,
                                        'unixserver', /* Host name or IP address of server */
                                        'username' /* Linux/Unix user name*/
                                        cRemoteOSCommand).  /* Linux/Unix OS commnad*/
                                      

os-command value(cOSCommand).

OR

define stream sIOInput.
define var cImportLine.

input stream sIOInput through value(cOSCommand) no-echo no-convert.

repeat:

  cImportLine = ''.

  import stream sIOInput cImportLine unformatted.

  display cImportLine.

  pause 0.

end.

input stream sIOInput close.

P.S. This code could be very dangerous as it will not stop bad commands i.e. rm -R.
 

Serge

New Member
Thanks a lot Cecil for the quick respons.

I didn't know it would really be that simple :)!

Cheers!
 

Serge

New Member
For most of the servers this is working ... but for some of them not due to next error: "SERVER02: Permission denied" when executing the cOSCommand.

Perhaps it is a setting on the server but I can't find it ...

Somebody an idea? I'm not a UNIX expert :eek:

Would appreciate any help.

Thanks in advance ...
 

syddie

New Member
You could look running your os commands via sudo if there are permission problems with some commands.
sudo allows you to run defined commands/programs or scripts as another user (ie root). Your administrator would need to allow whatever it is you are running.

regards
Ken
 

sphipp

Member
You probably won't like this solution, but ...

If you want a quick, easy but totally unsecure solution then use this batch file:

telnet.vbs:
Code:
Dim WshShell, fso, inpfile, inpstream, objArgs
Set WshShell = WScript.CreateObject ("WSCript.shell")
 
Set objArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set inpfile = fso.GetFile(objArgs(0))
Set ts = inpfile.OpenAsTextStream(1, 0)
MyRun = ts.ReadLine
MyServer = ts.ReadLine
LogonName = ts.ReadLine
LogonPassword = ts.ReadLine
MyProgram = ts.ReadLine
ts.Close
 
MyCommand = objArgs(1)
 
WshShell.run """" & MyRun & """ " & MyServer
WScript.Sleep 5000
WshShell.AppActivate MyProgram
WScript.Sleep 1000
WshShell.SendKeys LogonName & "{ENTER}"
WScript.Sleep 5000
WshShell.SendKeys LogonPassword & "{ENTER}"
WScript.Sleep 5000
WshShell.SendKeys MyCommand & " ; exit " & "{ENTER}"

telnet.txt:
Code:
c:\windows\system32\telnet.exe
MyServer
MyLogin
MyPassword
telnet MyServer

You call it with
Code:
c:\telnet.vbs c:\info\telnet.txt 
/usr/scripts/myscript.sh

You can turn it into straight Progress Code fairly easily. This means that you can store the commands, logins and passwords in a database, making them hard to get at and you can control the logon more easily.

I would have several dummy logins set up that automatically execute certain scripts. You could even FTP an INI file across, or copy it to a shared directory, then the script reads the INI file and processes commands.

The advantages of this are that it is easy to configure and set up, doesn't need much in the way of permissions and uses standard Unix login functionality.

The disadvantages are that it is not secure as it just opens up a telnet session and then exits, the commands are visible on screen, it is fairly inflexible and fairly slow and there isn't a lot you can do with error-trapping or logging to show you have carried out the commands. It might also fall foul of any restrictions you have in place for running of scripts.

It all depends on what you want to use the unix commands for and how secure you want the connection.

As a Progress Program:


Code:
DEF VAR hwshshell AS COM-HANDLE NO-UNDO.
DEF VAR cExecutable AS CHAR NO-UNDO.
DEF VAR cServer AS CHAR NO-UNDO.
DEF VAR cLogon AS CHAR NO-UNDO.
DEF VAR cPassword AS CHAR NO-UNDO.
DEF VAR cConnectCommand AS CHAR NO-UNDO.
DEF VAR c_enter AS CHAR NO-UNDO.
DEF VAR cUnixCommand AS CHAR NO-UNDO.
 
/* Assign login information - 
you can get this from a database table or as input parameters or whatever */
 
ASSIGN
    c_enter = "~{ENTER}"
    cExecutable = "C:\windows\system32\telnet.exe" /* Or wherever */
    cServer = "MyServer" /* Server Name */
    cLogon = "MyLogin" /* Unix User Name */
    cPassword = "MyPassword"  /* Unix Password */
    cConnectCommand = "telnet " + cServer /* This may vary according to your setup */
    cUnixCommand = "ls -l |more". /* Or whatever command/script you want */
 
CREATE "WScript.Shell" hwshshell NO-ERROR.
 
IF VALID-HANDLE(hwshshell) THEN DO:
    hwshshell:run ("cmd /C " + CHR(34) + cExecutable + " " + cServer,2).
    RUN ip_pause (2).
    hwshshell:AppActivate (cConnectCommand).
    RUN ip_pause (1).
    RUN ip_sendkeys(cLogon + c_enter,1).
    RUN ip_sendkeys(cPassword + c_enter,1)
    RUN ip_sendkeys(cUnixCommand + " ; exit " + c_enter,1).
END.

RELEASE OBJECT hwshshell NO-ERROR.
 
PROCEDURE ip_sendkeys:
    DEF INPUT PARAM pi_cSend AS CHAR NO-UNDO.
    DEF INPUT PARAM pi_ipause AS INT NO-UNDO.
    hwshshell:SendKeys (cPassword + c_enter).
    RUN ip_pause (pi_ipause).
END PROCEDURE.
 
PROCEDURE ip_pause:
    /* Use ip_pause because PAUSE n is unreliable when using SendKeys */
    DEF INPUT PARAM pi_isecs AS INT NO-UNDO.
    DEF VAR iStartTime AS INT NO-UNDO.
    DEF VAR iEndTime AS INT NO-UNDO.
 
    ASSIGN iStartTime = TIME
    iEndTime = iStartTime + pi_isecs + 1.
    _PAUSE:
    REPEAT:
        PAUSE 1 NO-MESSAGE.
        IF TIME >= iEndTime THEN LEAVE _PAUSE.
    END.
END PROCEDURE.
 
Top