Sign in to follow this  
Followers 0
aphesia

Can my script become more lightweight and bulletproof?

16 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



Well that seems awesome :D

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

Thanks

Share this post


Link to post
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 ...
 

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

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


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
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 ...
 

Share this post


Link to post
Share on other sites

@Exit: thanks !

@MvGulik: So I have my check if "Run("C:SSH-Tunnel.exe")" was actual successful :P

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Well, I put the laptop into sleep mode and then i wake it up ;P

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#16 ·  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

Share this post


Link to post
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
Sign in to follow this  
Followers 0