WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: ping during bootlocal.sh  (Read 2129 times)

Offline ambaum01

  • Newbie
  • *
  • Posts: 17
ping during bootlocal.sh
« on: January 24, 2013, 12:04:44 PM »
Hello all,
I'm trying to boot tiny core and scp a file to a server as soon as a network connection is established.  My scp code is in a script in bootlocal.sh.  If I let that scp code execute too early, it kicks back an error about not being connected to the server and quits the scp.  Currently, I have hacked in a sleep 5 to ensure that the connection is made, but I'd rather run a script before the scp script that will ensure there is network connectivity before I try the scp and reduce the time it takes to run.  So far, I have written this:
Quote
#!/bin/sh
#Pinging the server until it responds

unreachable=1;

while [ $unreachable -ne 0 ]; do
  echo are you there?
  ping  -c 1 -w 1 SERVER &> /dev/null
  unreachable=$?
  echo sleeping
done
echo awake
The problem I am having is that the ping -w 1 doesn't seem to be working.  When I unplug the network cable, it runs through the while loop about every 20 seconds instead of every 1 second like I would expect.  I would have thought that with a network cable unplugged, ping would immediately throw and error and exit.  Am I incorrect in that assumption?  Thanks for all the help.
-Aaron

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: ping during bootlocal.sh
« Reply #1 on: January 24, 2013, 12:22:28 PM »
This what I call from bootlocal.sh when I need to be sure the network is up.

tc@box:/opt$ cat waitip
SEC=60
while [ $SEC -gt 0 ] ; do
   ifconfig | grep "inet addr:" | grep -qv "127.0.0.1" && break
   echo -ne "Waiting for IP $(( SEC--))  \r"
   sleep 1
done
echo

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: ping during bootlocal.sh
« Reply #2 on: January 24, 2013, 12:28:52 PM »
You could also look at the script that I have in /etc/init.d/settime.sh to set time for machines (arm) with no RTC,
10+ Years Contributing to Linux Open Source Projects.

Offline ambaum01

  • Newbie
  • *
  • Posts: 17
Re: ping during bootlocal.sh
« Reply #3 on: January 24, 2013, 01:01:59 PM »
You could also look at the script that I have in /etc/init.d/settime.sh to set time for machines (arm) with no RTC,
This is exactly what I needed.  Thanks so much!
-Aaron