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.