From: Vahis on
I need to automagically run:

sshfs waxborg.servepics.com:/music /home/user/music

but only if the Internet connection is up.

It's a machine that is not necessarily connected to The Internet at
boot. So the script should check first and if there's no
connection, wait and check again.

How should I check the connection and wait till it's
up and then go on with the mount?


Vahis
--
"Sunrise 9:28am (EET), sunset 3:16pm (EET) at Espoo, Finland (5:48 hours daylight)"
http://waxborg.servepics.com
Linux 2.6.25.20-0.5-default #1 SMP 2009-08-14 01:48:11 +0200 x86_64
7:37pm up 60 days 0:38, 9 users, load average: 0.28, 0.48, 0.41
From: Rob on
Vahis <waxborg(a)gmail.com.invalid> wrote:
> I need to automagically run:
>
> sshfs waxborg.servepics.com:/music /home/user/music
>
> but only if the Internet connection is up.
>
> It's a machine that is not necessarily connected to The Internet at
> boot. So the script should check first and if there's no
> connection, wait and check again.
>
> How should I check the connection and wait till it's
> up and then go on with the mount?

while ! ping -c 3 -w 4 waxborg.servepics.com >/dev/null 2>&1
do
sleep 10
done
From: Vahis on
On 2009-12-29, Rob <nomail(a)example.com> wrote:
> Vahis <waxborg(a)gmail.com.invalid> wrote:
>> I need to automagically run:
>>
>> sshfs waxborg.servepics.com:/music /home/user/music
>>
>> but only if the Internet connection is up.
>>
>> It's a machine that is not necessarily connected to The Internet at
>> boot. So the script should check first and if there's no
>> connection, wait and check again.
>>
>> How should I check the connection and wait till it's
>> up and then go on with the mount?
>
> while ! ping -c 3 -w 4 waxborg.servepics.com >/dev/null 2>&1
> do
> sleep 10
> done

Thanks, that was simple.
I guess anything is when you know how, isn't it :)

I was experimenting with ping but I just couldn't figure it out.

Thanks again.

Vahis
--
"Sunrise 9:28am (EET), sunset 3:16pm (EET) at Espoo, FI (5:48 hours daylight)"
http://waxborg.servepics.com
Linux 2.6.25.20-0.5-default #1 SMP 2009-08-14 01:48:11 +0200 x86_64
9:38pm up 60 days 2:39, 10 users, load average: 0.44, 0.42, 0.35
From: Vahis on
On 2009-12-29, houghi <houghi(a)houghi.org.invalid> wrote:
> Vahis wrote:
<snip>
>> How should I check the connection and wait till it's
>> up and then go on with the mount?
>
> There are several things that you can do, depending on what kind of
> error you would like:
> 1) Use `ping -c 1 axborg.servepics.com` and then see if that gives you
> something back.(I am often against ping, but if you own both sides, it
> could be used)

I was shown that pinging here is maybe simplest.
I put it in use.
>
> 2) Use /sbin/ifconfig to see if eth0 is active and has an IP adress
>
> 3) Use curl
>
> This is the prefered way as you then test if you can connect to that
> server. So not only will you check if you have network connection, it
> will check if you have a correctly working DNS and if the ssh server on
> the other side is up and running
>
> #!/bin/bash
> #set -x
> TMP=`mktemp`
> SERVER=localhost
> PORT=22
> curl -s ${SERVER}:${PORT} > ${TMP}
> OK=`grep ^SSH ${TMP}`
> rm ${TMP}
> if [ -e ${OK} ]
> then
> echo "Not connected"
> else
> echo "Connected"
> fi


At a point I was trying to do it with wget:

#!/bin/bash
WGET="/usr/bin/wget"
$WGET -q --tries=10 --timeout=5 http://www.google.com -O \
/tmp/index.google &> /dev/null
if [ ! -s /tmp/index.google ];then
echo "Down"
else
echo "Up"
fi


>
> I will leave it to you to put it inside a loop. Just let us know if that
> won't work or if you can't figure it out.

Thet's where I was with it (still am)
I didn't try yours yet, but obviously it comes to the same result.
Yours is better since it checks that also the server is up, not just
google.com :)

So mine also works as long as exhoing "Up" or "Down" but I wasn't able
to figure out how to make it either wait or mount.


Vahis
--
"Sunrise 9:28am (EET), sunset 3:16pm (EET) at Espoo, FI (5:48 hours daylight)"
http://waxborg.servepics.com
Linux 2.6.25.20-0.5-default #1 SMP 2009-08-14 01:48:11 +0200 x86_64
10:08pm up 60 days 3:09, 10 users, load average: 0.30, 0.22, 0.23
From: Vahis on
On 2009-12-29, houghi <houghi(a)houghi.org.invalid> wrote:
> houghi wrote:
>> Will make a working script. brb.
>
>
> Below the script. So what does it do?

Thanks :) I'll play with it later today.
Here I had a "sleep 6 HRS", now back to work.
Not nice with all the snow we have here :(

> First you have the parameters. I asume they are obvious. I the script
> you could also add a user and edit the line with sshfs in it.
> LDIR stands for local dir. RDIR for remote directory.
>
> The it will check if the directory is already mounted. If it is, then it
> won't go on and show a message saying that it is already connected.
> There is a slight issue if it was mounted and you loose the connection
> and then want to re-run. Reconnectioning will solve this.

There is a special issue with this particular user case.
This whole mounting business is for serving some music to a certain
machine.
The machine is connected via a USB UMTS thingy, Huawei.
I'm using umtsmon there to connect.

I was first trying another, much more versatile one,
Vodafone Mobile Connect.
There is a bug though that causes "twistd" to hog processor, so it can't
be used in a low spec machine.

That's pity since this software can send SMS without disconnecting from
the Internet. It can also receive sms messages.
Exactly what I would need in this.

The case here namely is a prepaid connection which means that there is
a need to send an activating SMS to the ISP at times.
There is also a need to receive their announce of the activated period
but I guess I must live without that for now.

UMTSMON needs to disconnect before sending and that's bad in this case.
And it can not see the answer.

After sending it can be connected again.
So there will be situations where the directory is mounted and the
connection will be lost.
Or there will be too much user intervention which is not wanted.

I will need to experiment what the issues will be like before I
implement the whole thing.

<snip>

> Have fun with it.

I will, thanks :)

Vahis
--
"Sunrise 9:28am (EET), sunset 3:17pm (EET) at Espoo, FI (5:49 hours daylight)"
http://waxborg.servepics.com
Linux 2.6.25.20-0.5-default #1 SMP 2009-08-14 01:48:11 +0200 x86_64
6:03am up 60 days 11:04, 10 users, load average: 0.09, 0.19, 0.21