WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Tiny Core get router IP on boot  (Read 1564 times)

Offline nygauk

  • Newbie
  • *
  • Posts: 2
Tiny Core get router IP on boot
« on: December 17, 2023, 03:42:27 PM »
Hi
I connect to my remote network using DDNS over the Internet, SSH and Putty. I have a Tiny Core box and a broadband router on that network. Everything works well.

I would like to pause the boot process of my remote Tiny Core box which boots at the same time as the broadband router, until the latter is fully up so I can get it's public IP address which is emailed to me by the Tiny Core box.

Here are the relevant lines in my bootlocal.sh:
Code: [Select]
.
.
/opt/eth0.sh &
.
until /usr/bin/nc -z 192.168.1.1 80
do
  echo "Router is not up yet. Waiting..." >> /home/tc/mail.txt
  sleep 5
done
.
/usr/local/bin/curl ifconfig.me >> /home/tc/mail.txt
echo -n " on " >> /home/tc/mail.txt
sleep 30
date >> /home/tc/mail.txt
/usr/local/bin/curl --url smtp://<smtp server>:587 --ssl-reqd  --mail-from me@my_email.com --mail-rcpt my_email@gmx.com --upload-file /home/tc/mail.txt --user <from@my_email.com:mypass>
.
.
If I merely reboot the Tiny Core box remotely via SSH everything is fine. However, If I shut down the router and switch it on again (using an sms switch) at the same time as the Tiny Core box boots, it doesn't work, i.e. the date is not written to mail.txt and no email is sent.

I tried to use cron with the @reboot directive but that doesn't seem to do anything in Tiny Core.

Also it would be quite acceptable to get the router address after the boot up process but I can't see how to achieve this so that there is only one check soon after boot.

Any ideas would be greatly appreciated - thanks.

    [EDIT]: Added  code  tags.  Rich
« Last Edit: December 18, 2023, 09:01:10 AM by Rich »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Tiny Core get router IP on boot
« Reply #1 on: December 18, 2023, 02:09:53 AM »
Add echos to a log file between each step, to find out which step is failing to proceed. Then save that command's errors to the log file.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11695
Re: Tiny Core get router IP on boot
« Reply #2 on: December 18, 2023, 08:59:40 AM »
Hi nygauk
Welcome to the forum.

Please use  Code Tags  when posting commands and responses seen in a terminal. To use  Code Tags  click on the  #  icon
above the reply box and paste your text between the  Code Tags  as shown in this example:

Quote
[code][   36.176529] pcm512x 1-004d: Failed to get supply 'AVDD': -517
[   36.176536] pcm512x 1-004d: Failed to get supplies: -517
[   36.191753] pcm512x 1-004d: Failed to get supply 'AVDD': -517[/code]

It will appear like this in your post:
Code: [Select]
[   36.176529] pcm512x 1-004d: Failed to get supply 'AVDD': -517
[   36.176536] pcm512x 1-004d: Failed to get supplies: -517
[   36.191753] pcm512x 1-004d: Failed to get supply 'AVDD': -517

Code Tags  serve as visual markers between what you are trying to say and the information you are posting. They also preserve
spacing so column aligned data displays properly. Code tags also automatically add horizontal and or vertical scrollbars
to accommodate long lines and listings.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11695
Re: Tiny Core get router IP on boot
« Reply #3 on: December 18, 2023, 09:10:39 AM »
Hi nygauk
I suspect your problem might be here:
...
Code: [Select]
.
.
/opt/eth0.sh &
.
until /usr/bin/nc -z 192.168.1.1 80

 ----- Snip -----
...

See if waiting until your network card is up helps:
Code: [Select]
.
.
/opt/eth0.sh &

# Wait for network to come up
SEC="60"
while [ $SEC -gt 0 ]
do
        SEC=$(($SEC - 1))
        ifconfig | grep -q "Bcast:" && break
        sleep 1
done

if [ $SEC -eq 0 ]
        echo " ----- Network is not up. -----" >> /home/tc/mail.txt
fi
.
until /usr/bin/nc -z 192.168.1.1 80

 ----- Snip -----

Offline nygauk

  • Newbie
  • *
  • Posts: 2
Re: Tiny Core get router IP on boot
« Reply #4 on: December 18, 2023, 08:14:37 PM »
Hi everyone

As you indicated Rich, it did turn out to be a timing issue.

I have solved my problem by placing everything after the call to eth0.sh in bootlocal.sh into a separate script and calling this script from bootsync.sh after a sleep 300 (5 min for the router to come up). It now works fine.

Thanks for your prompt response and useful information (•‿•)