Jump to content

Can my script become more lightweight and bulletproof?


aphesia
 Share

Recommended Posts

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
Link to comment
Share on other sites

+ 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 ...
 

Link to comment
Share on other sites

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 ...
 

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

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
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...