Bash script help for dummy. need to monitor and restore my adsl connection
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bash script help for dummy. need to monitor and restore my adsl connection
Hi
Can someone please help me here, I administer a couple of small firewalls that are on an adsl connection but they are about 100kms away from me.
When the connection goes down I have no way of bringing it back up.
I assume it will only need a simple bash type script to do the following things.
check the connection is up
if connection is up, is it active (not timed out or frozen) (perhaps ping to another server)
if active then exit
if not active then clear existing connection and start new connection
I could then put this in a cron job about every 5 or 10 mins
Please forgive me as I have no programming Knowledge.
If anyone has the time to help out it would be greatly appreciated.
The unary ! negates the following statement.
Read NOT( $? == 0 )
$? is a bash-variable, and contains the exit
status of the previous command, in our case
of the ping. If the status of a command is
success $? will contain 0, otherwise a non-zero
value.
In human-readable form:
if the previous command was unsuccessful, say ooops ,
otherwise all is well.
Your help and explanation is a great inspiration.
I will indeed check those links from your last post.
I put that script in place last night and tested it.
All went well, But I just have to add the command to bring the vpn back up as I realized this morning that it dies with the connection. That is quite simple though.
The thing that had me stumped in the begining was gathering the results of the ping and using the answer to decide whether to exit or execute the restart.
Now that I have a working script I can study up my bash scripting and make it a bit more fancy later on.When I do I
will post the results up for others to use.
Originally posted by default
Thanks Again Tinkster,
Again, my pleasure :)
Quote:
The thing that had me stumped in the begining
was gathering the results of the ping and using
the answer to decide whether to exit or execute the restart.
isn't meant to gather anything, it's to ping-probe, and the
assignment to dump only prevents ping-output, it's a
beautifying measure, so to speak :} ... the $? is the key
to analysing the result.
Quote:
Now that I have a working script I can study up my
bash scripting and make it a bit more fancy later on.
When I do I will post the results up for others to use.
Kindest Regards,
Dave
All I can say is that I'm glad I got you started, and that
I'm very happy to see you enthusiastic about scripting.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.