On Tue, 27 Jun 2023 11:48:16 -0600, the...@sys-concept.com wrote:

> On 6/27/23 11:04, Neil Bothwick wrote:
> > On Tue, 27 Jun 2023 10:34:22 -0600, the...@sys-concept.com wrote:
> >   
> >> I run this little script to notify me when the IP changes.  However
> >> at time to time the file: "old_ip.txt" is being populated with an
> >> empty line "no IP address"
> >>
> >> What could be causing it?
> >>
> >>
> >> #!/bin/bash
> >>
> >> # Replace "YOUR_EMAIL" with your actual email address
> >> EMAIL="your_em...@gmail.com"
> >>
> >> # File to store the old IP address
> >> IP_FILE="/home/fd/business/scripts/old_ip.txt"
> >>
> >> # Read the old IP address from the file
> >> OLD_IP=$(cat "$IP_FILE")
> >>
> >> # Function to retrieve the IP address
> >> get_ip_address() {
> >>       local ip_address
> >>       ip_address=$(curl -s https://ifconfig.me/ip)
> >>       echo "$ip_address"
> >> }
> >>
> >> # Query the API to get the current IP address
> >> NEW_IP=$(curl -s https://api.ipify.org)  
> > 
> > I found this site very slow to respond. It could be timing out with an
> > empty result. OTOH the URL used in the get_ip_address function is
> > rapid, but you don't call that function.
> >   
> >>
> >> sleep 2  
> 
> Yes, I notice it, it take upwards 10sec to get an IP and sometimes I
> get a timeout, I increases "sleep 15" hopefully it will help.

It won't because the curl command is running synchronously. All
increasing the sleep does is make you wait longer after it fails. Why not
simply switch to the other service that seems to work more reliably?


-- 
Neil Bothwick

If someone with multiple personalities threatens to kill himself, is it
considered a hostage situation?

Attachment: pgpLsmerRR4LQ.pgp
Description: OpenPGP digital signature

Reply via email to