Sponsored Content
Top Forums Shell Programming and Scripting Linux: Writing a tricky script to check connectivity Post 302284991 by fimblo on Friday 6th of February 2009 05:58:30 PM
Old 02-06-2009
I had some similar code at home, heres a slightly modified version for you.

Note that there are two reset functions included, depending on if you will ssh or telnet. And you'll prolly need to read a few man-pages to get things right.

---------------------------------------
#!/usr/bin/env bash

MY_MODEM_IP=123.12.1.1
HOST_TO_CHECK=www.comcast.net
SOME_TIME=$(( 5 * 60 )) # seconds

ping_fails () {
# check your ping manpage for flags so that it
# o sends one ping then quits
# o waits only a second or so for the pong
! ping -XXX $HOST_TO_CHECK > /dev/null 2>&1
}

reset_modem_ssh () {
# Make sure you've made a public and private key if you're going
# with ssh.
{
echo 'reset';
} | ssh $MY_MODEM_IP
}

reset_modem_telnet () {
# If you go with telnet, dont forget to echo your password. I've
# noticed that some applications are a little slow, adding sleeps
# is a simple workaround.
{
sleep 0.2
echo "yourpassword"
sleep 0.2
echo "reset"
} | telnet $MY_MODEM_IP
}


while sleep $SOME_TIME ; do
ping_fails && reset_modem_ssh
done

------------------------------------
And to be on the safe side, specify the ping host with its ip address, not its hostname.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to check connectivity

I want to write a script to check if a unix box say abc.tdc.cin.net can be connected or not on certain port say 22. right know i have to telnet them manually from DOS prompt and if it is successful then isay it is connected. Also to check Database connectivity I am using tnsping From DOS prompt.... (3 Replies)
Discussion started by: kukretiabhi13
3 Replies

2. Shell Programming and Scripting

Check connectivity script

This past weekend I had some issues with my ISP. So for future purpose I'm going to have some logging on my internet so I'm able to attach log files to my complaint email if this issue reoccurs. Decided to do a simple ping script that runs every 5 or 10 min with crontab if ping fail write date... (5 Replies)
Discussion started by: chipmunken
5 Replies

3. Shell Programming and Scripting

Help writing a script check log not update.

:wall:Dear All.:p How to check log size every 10min. by script (not crontab) if log size not change with alert "Log not update" My Path :: /usr/home/logical/mono/log/tplink/ My Log :: mono11_tplink.log , mono12_tplink.log , etc I want oup put. EX. if log not update. . . . Fri Jan ... (1 Reply)
Discussion started by: ooilinlove
1 Replies

4. IP Networking

Connectivity check.

How to check connectivity with an external server if I know the IP. Please note traceroute is not working for me, as it is saying command not found. (6 Replies)
Discussion started by: nixhead
6 Replies

5. Shell Programming and Scripting

How to check if a script is writing to a log

Hello, I have various scripts that writes to logs ( >> ) in different directories. I have create a script to automatically check different direcories for different errrors. However I do not want to remove logs if a script is still writing to a log. Is the log file opened for writing when the... (7 Replies)
Discussion started by: drbiloukos
7 Replies

6. Solaris

Sybase Connectivity Check through Shell Script

Hi, I need to check the sysbase database connectivity through the Unix Shell Script. Can you help me on the how to write the script to test the sysbase database connection. Thanks in Advance Nandha (0 Replies)
Discussion started by: nandha2387
0 Replies

7. Shell Programming and Scripting

Writing a script to run weekly/monthly - check for weekday or day-of-the-month

Hi all, I currently have a UNIX file maintenance script that runs daily as a cron job. Now I want to change the script and create functions/sub inside it that runs on a weekly or monthly basis. To run all the scripts' daily maintenance, I want to schedule it in cron as simply maint.sh... (1 Reply)
Discussion started by: newbie_01
1 Replies

8. Shell Programming and Scripting

Check the connectivity of the DB through script, exit if no connection

check the connectivity of the DBs through script, script should exit if no connection and display the output as below. connectivity for DB1 is OK connectivity for DB2 is OK connectivity for DB3 is FAILED for DB in 1 2 3 do (sqlplus -s... (5 Replies)
Discussion started by: only4satish
5 Replies

9. Shell Programming and Scripting

Help with shell script to check the tcp network connectivity between server

Hello, I have a requirement to check the tcp network connectivity between server it's running on and the list of host's and ports combination. i have written the below code but it doesn't work, but when i execute the nc command outside the script it works fine. please help me where i am... (8 Replies)
Discussion started by: sknovice
8 Replies

10. Shell Programming and Scripting

Check connectivity with multiple hosts - BASH script available here

Hi everyone! Some time ago, I had to check connectivity with a big list of hosts, using different formats (protocol://server:port/path/, server:port, ....). I developed a script that checks the connectivity using different commands (ping, telnet, nc, curl). It worked for me so I'm sharing it... (9 Replies)
Discussion started by: Fr3dY
9 Replies
dnetcat(1)							   User Commands							dnetcat(1)

NAME
dnetcat - opens a DECnet connection SYNOPSIS
dnetcat {-h|--help} dnetcat [-v] [-z] node[::|[::] ]object dnetcat [-v] [-f] -l object DESCRIPTION
dnetcat is a netcat(1) like tool that opens a DECnet connection and copies all data between the standard input/output to/from the socket. OPTIONS
-v Be verbose. Prints useful (debug) messages. -z Zero IO mode. In this mode a connection is dropped directly after it is opened. This can be used to scan if the remote side listens on the given address and object. -l Listen mode. In this mode dnetcat accepts connections on the given object. -f Fork on new connection. This let netcat accept multiple connections in listen mode. This is ignored if -l is not given. --help, -h Prints a small help. EXAMPLES
This program can be used as 'ProxyCommand' for ssh(1). You may use it via command line like this: ssh -o 'ProxyCommand dnetcat %h ssh' [...] mynode or you may use it in your ~/.ssh/config like this: Host *:: ProxyCommand dnetcat %h ssh This will enable you to connect to any DECnet node by adding "::" at the end of the node name like this: ssh mynode:: For more information on ssh(1) see it's manpage. SEE ALSO
ssh(1), netcat(1). AUTHORS
This program is written by Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>. dntools September 2008 dnetcat(1)
All times are GMT -4. The time now is 04:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy