Jump to content

Remote execution Script


Guest jano bermudes
 Share

Recommended Posts

Guest jano bermudes

Hi there,

(please see bottom for code)

As I've no operational control over our web hosting environement(I do design as opposed to operations), I have to deploy everything out remotly via the SSH infrastrucure which means no interactive winwait commands.

My dilema is this: I have an update patch to apply to an application which runs in a command window. Once executed it runs various tasks then in the same window gives you a menu of options to choose from (Option 1,2 or 3 etc). I can tell where it is in the routine using an autoit function which monitors a log file for certain words or phrases and sends key strokes to the dos window when it finds the words (or sleeps if not).

This works fine interactivly but keels over when deployed out via ssh and executed via a plink session. I know this is becuase I am using WinTitleMatchMode 3 but am not sure how to upgrade it to option 4(cant get it to work).

These are what I see as the main issues:

1. the ssh runs in a command shell so I cant seem to diffrentiate between the first and the second cmd process.

2. I cant seem to get a handle on the cmd process.

Please review my code below and advise. Any feedback welcome as this is due to go out pretty soon.

Many Thanks

Jano

;global variables

global $CURRPATH = EnvGet("CURRPATH") ; 'e:\temp'

global $CUSTOMFILESPATH = EnvGet("CUSTOMFILESPATH") ;'patch4'

global $rundir = "e:\temp\patch4\"

global $mplacelog = "e:\temp\patch4\install.log"

DirCopy($CURRPATH & "\" & $CUSTOMFILESPATH & "\patch4", "e:\temp", 1)

$PATH = $CURRPATH & '\' & $CUSTOMFILESPATH & '\'

;MsgBox(0, "AutoIt Example", "this is currpath" & $PATH)

AutoItSetOption("WinTitleMatchMode", 3)

Run ( $rundir & 'cmd.exe' )

sleep (1000)

;browse to rundir

ControlSend("e:\temp\patch4\cmd.exe", "", "", "e:" )

ControlSend("e:\temp\patch4\cmd.exe", "", "", "{ENTER}" )

ControlSend("e:\temp\patch4\cmd.exe", "", "", "cd\" )

ControlSend("e:\temp\patch4\cmd.exe", "", "", "{ENTER}" )

ControlSend("e:\temp\patch4\cmd.exe", "", "", "cd e:\temp\patch4" )

ControlSend("e:\temp\patch4\cmd.exe", "", "", "{ENTER}" )

RunWait("e:\temp\patch4\netstop.cmd", "e:\temp\patch4", @SW_HIDE)

;ControlSend("e:\temp\patch4\cmd.exe", "", "", "netstop.cmd" )

;ControlSend("e:\temp\patch4\cmd.exe", "", "", "{ENTER}" )

sleep(2000)

;start upgrade routine

ControlSend("e:\temp\patch4\cmd.exe", "", "", "e:\temp\patch4\install.exe" )

ControlSend("e:\temp\patch4\cmd.exe", "", "", "{ENTER}" )

; ----------------------------------------------------------------------------

; Script Start: Search/Sleep --- 1

; ----------------------------------------------------------------------------

checklog("consistency", "1")

; ----------------------------------------------------------------------------

; Script End: earch/Sleep ---1

; ----------------------------------------------------------------------------

; ----------------------------------------------------------------------------

; Script Start: Search/Sleep --- 2

; ----------------------------------------------------------------------------

checklog("compatibility", "2")

; ----------------------------------------------------------------------------

; Script End: earch/Sleep ---2

; ----------------------------------------------------------------------------

; ----------------------------------------------------------------------------

; Script Start: Search/Sleep --- 3

; ----------------------------------------------------------------------------

checklog("higher", "3")

; ----------------------------------------------------------------------------

; Script End: earch/Sleep ---3

; ----------------------------------------------------------------------------

sleep(3000);just a humane pause

;******

ControlSend("e:\temp\patch4\cmd.exe - e:\temp\patch4\install.exe", "", "", "4" )

ControlSend("e:\temp\patch4\cmd.exe - e:\temp\patch4\install.exe", "", "", "{ENTER}" )

; ----------------------------------------------------------------------------

; Func Start: Search/Sleep

; ----------------------------------------------------------------------------

Func checklog($substr, $command)

$file = FileOpen($mplacelog, 0)

; Check if file opened for reading OK

If $file = -1 Then

Exit

EndIf

; Read in 1 character at a time until the EOF is reached

While 1

$strLog = FileRead($file, 10000)

If @error = -1 Then ExitLoop

;MsgBox(0, "Char read:", $strLog)

$strstr = StringInStr($strLog , $substr, 0 )

Wend

If $strstr = 0 then

;MsgBox(0, "is 0", "hahaha")

FileClose($file)

sleep (5000)

checklog($substr, $command)

Else

ControlSend("e:\temp\patch4\cmd.exe - e:\temp\patch4\install.exe", "", "", $command )

ControlSend("e:\temp\patch4\cmd.exe - e:\temp\patch4\install.exe", "", "", "{ENTER}" )

EndIf

EndFunc

; ----------------------------------------------------------------------------

; Script End: Search/Sleep

; ----------------------------------------------------------------------------

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...