aphesia Posted September 2, 2012 Share Posted September 2, 2012 (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 September 2, 2012 by aphesia Link to comment Share on other sites More sharing options...
Exit Posted September 2, 2012 Share Posted September 2, 2012 Opt("TrayMenuMode", 0) TraySetIcon("anON.ico") While Sleep(5000) If Not WinExists("SSH-Tunnel") Then TraySetIcon("anOFF.ico") While Not Ping("google.at") WEnd Run("C:SSH-Tunnel.exe") TraySetIcon("anON.ico") EndIf WEnd App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
aphesia Posted September 2, 2012 Author Share Posted September 2, 2012 Well that seems awesome but isn't the ping-sleep-ping again code more lightweight than "while not ping" ? Thanks Link to comment Share on other sites More sharing options...
MvGulik Posted September 2, 2012 Share Posted September 2, 2012 + 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 More sharing options...
aphesia Posted September 2, 2012 Author Share Posted September 2, 2012 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 ? Link to comment Share on other sites More sharing options...
Exit Posted September 2, 2012 Share Posted September 2, 2012 Well that seems awesome 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() Link to comment Share on other sites More sharing options...
MvGulik Posted September 2, 2012 Share Posted September 2, 2012 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 More sharing options...
aphesia Posted September 3, 2012 Author Share Posted September 3, 2012 @Exit: thanks ! @MvGulik: So I have my check if "Run("C:SSH-Tunnel.exe")" was actual successful Link to comment Share on other sites More sharing options...
aphesia Posted September 16, 2012 Author Share Posted September 16, 2012 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? Link to comment Share on other sites More sharing options...
Exit Posted September 16, 2012 Share Posted September 16, 2012 Explain what you mean with "Wakeup" App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
aphesia Posted September 16, 2012 Author Share Posted September 16, 2012 Well, I put the laptop into sleep mode and then i wake it up ;P Link to comment Share on other sites More sharing options...
dany Posted September 16, 2012 Share Posted September 16, 2012 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 Link to comment Share on other sites More sharing options...
aphesia Posted September 17, 2012 Author Share Posted September 17, 2012 nope because the process is called putty.exe 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 More sharing options...
aphesia Posted September 17, 2012 Author Share Posted September 17, 2012 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 Link to comment Share on other sites More sharing options...
Exit Posted September 17, 2012 Share Posted September 17, 2012 Show us your last version of the script. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
aphesia Posted September 17, 2012 Author Share Posted September 17, 2012 (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 September 18, 2012 by aphesia Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now