Jump to content

Recommended Posts

Posted (edited)

Hi there, I am working on a script for my homeserver which:

Checks if the SSH-Tunnel (Putty) is still active (e.g. if the network time outs, the SSH-Tunnel / Putty will exit)

If it is not active anymore, check it the network connection is availabe

If not, wait until network is back running

Then connect to the SSH-Tunnel again

This script should run 24/7 and be as lightweight as possible. I wonder if I could improve it somehow?

Opt("TrayMenuMode", 0)
TraySetIcon("anOFF.ico")
While 1

    If WinExists("SSH-Tunnel") Then
        TraySetIcon("anON.ico")
        WinWaitClose("SSH-Tunnel")
        TraySetIcon("anOFF.ico")
        If Ping("google.at", 250) = 0 Then
            For $i = 1 to 99999999999999999999999999999999 Step 1
                If Ping("google.at", 250) = 0 Then
                    sleep(5000)
                Else
                run("C:SSH-Tunnel.exe")
                ExitLoop
                EndIf
            Next
        Else
        run("C:SSH-Tunnel.exe")
        EndIf
    EndIf
WEnd

Thanks

@edit: I will continue working on the script. I have more ideas/features I want to include. If there are any suggestion so far please let me know ;P

Edited by aphesia
Posted

+ no check if "Run("C:SSH-Tunnel.exe")" was actual successful (bulletproof!)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Posted

As soon as SSH-Tunnel.exe runs, the window "SSH-Tunnel" will be active. As long as this window isn't active, ssh-tunnel.exe didn't run ?

Posted

Well that seems awesome Posted Image

but isn't the ping-sleep-ping again code more lightweight than "while not ping" ?

Thanks

While Not Ping("google.at") ; pings every 4 seconds as long as ping fails. If ping is successful, loop is terminated.

WEnd

App: Au3toCmd              UDF: _SingleScript()                             

Posted

As long as this window isn't active, ssh-tunnel.exe didn't run ?

Yep. (more or less)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

  • 2 weeks later...
Posted

For some reason after a wakeup, the script will run another "SSH-Tunnel.exe" although the original one is still there and active. Any idea on how to fix this?

Posted

Change WinExists("SSH-Tunnel") To ProcessExists("SSH-Tunnel.exe"), maybe that'll do the trick.

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Posted

nope because the process is called putty.exe :P

and i might have multiple putty.exe's open so I renamed the ssh-tunnel-putty.exe window title :/

but I guess I could re-name putty.exe and save it manually somewhere instead of using the installed putty.exe

Posted

hmm the "if ping not possible, do not run .exe" loop doesn't seem to work either. When my network goes offline the script just spams the run ssh-tunnel.exe

Posted (edited)

I haven't really changed your version:

Opt("TrayMenuMode", 0)
TraySetIcon("anOFF.ico")


$path4 = "C:whatever"

While Sleep(5000)
If Not WinExists("SSH-Tunnel") Then
TraySetIcon("anOFF.ico")
While Not Ping("my-server-domain.com")
WEnd
Run($path4 & "ssh-tunnel.exe")
TraySetIcon("anON.ico")
Else
TraySetIcon("anON.ico")
EndIf
WEnd
Edited by aphesia

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
  • Recently Browsing   0 members

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