LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-10-2018, 04:11 PM   #1
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Rep: Reputation: 57
Faster ways to test if a network share is available or not without waiting 15 seconds


Got a network share mounted on directory /mnt/share. If the server where it is located is switched off and a script tries to access a certain file in the share, it fails of course but it fails after 15 seconds. What are some faster ways to test if the share is up and running before trying to access the file, and do so repetitively in a script every second?

Distro: peppermintOS on all systems, based on ubuntu.

Last edited by Ulysses_; 09-10-2018 at 05:02 PM.
 
Old 09-10-2018, 08:37 PM   #2
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Ping the server for a response perhaps? If it is a samba share, maybe a broadcast using 'smbtree -b'? (Maybe not every second though.)

Last edited by ferrari; 09-10-2018 at 08:42 PM.
 
Old 09-11-2018, 06:42 AM   #3
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
Just found smbtree -b still shows the same output after the server is disconnected, even minutes later. Ping looks more promising as you control the time it waits. Any test for the existence of the share?
 
Old 09-11-2018, 10:05 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,093

Rep: Reputation: 7135Reputation: 7135Reputation: 7135Reputation: 7135Reputation: 7135Reputation: 7135Reputation: 7135Reputation: 7135Reputation: 7135Reputation: 7135Reputation: 7135
probably you can configure timeout settings.
 
Old 09-11-2018, 11:45 AM   #5
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,023
Blog Entries: 6

Rep: Reputation: 1795Reputation: 1795Reputation: 1795Reputation: 1795Reputation: 1795Reputation: 1795Reputation: 1795Reputation: 1795Reputation: 1795Reputation: 1795Reputation: 1795
Quote:
What are some faster ways to test if the share is up and running before trying to access the file, and do so repetitively in a script every second?
Example, check for machine, if up do something, else not.
Code:
#Check for machine up every 5 seconds
while :; do
    ping -c1 172.16.0.13 &> /dev/null
    if [ $? -eq 0 ]; then 
        echo "Machine is up"
        else echo "Machine is down"
    fi
    sleep 5
done
 
1 members found this post helpful.
Old 09-11-2018, 12:29 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,995

Rep: Reputation: 5682Reputation: 5682Reputation: 5682Reputation: 5682Reputation: 5682Reputation: 5682Reputation: 5682Reputation: 5682Reputation: 5682Reputation: 5682Reputation: 5682
You never posted what type of share or how it is mounted i.e. via your script or fstab etc. From post #3 we assume it is CIFS. Since you are using peppermint why not nfs or maybe sshfs or maybe use autofs or systemd automount.

Depends on the distribution but you can test to see if the share is available using smblient or maybe avahi-browse. Typically one might assume that if the server is powered on that the samba will automatically start?
 
Old 09-11-2018, 02:29 PM   #7
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
Using CIFS only because it's preconfigured in the distro. I mount it with fstab, and if the server is down and "ls /mnt/shared" fails, and then the server is powered on, then "ls /mnt/shared" works. Might the other options report unavailability of the share faster?

Anyway, ping as in teckk's code is probably less wasteful of bandwidth. And it can have -W 2 added to give up waiting for a response after 2 seconds when the server is down. Tried avahi-browse -a and it does not exit, is this normal? Turning off the server, and running avahi-browse -a again reports exactly the same lines.
 
Old 09-11-2018, 02:40 PM   #8
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
Is there an easy way for the server to tell other systems that a file in the share has changed so they do not need to poll every second?
 
Old 09-11-2018, 02:50 PM   #9
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Quote:
Tried avahi-browse -a and it does not exit, is this normal? Turning off the server, and running avahi-browse -a again reports exactly the same lines.
The avahi-daemon employs caching. AFAIU, only restarting the daemon will flush the cache.
 
Old 09-11-2018, 02:55 PM   #10
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Quote:
Is there an easy way for the server to tell other systems that a file in the share has changed so they do not need to poll every second?
Not that I'm aware of.
 
Old 09-12-2018, 12:41 PM   #11
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
Maybe the process that changes the file could send a UDP packet that a process on the other side is listening for? Is there a command that listens on a port and executes a script when a packet arrives?

EDIT: There is indeed, with short messages instead of UDP packets:

socat -u tcp-l:7777,fork system:./getmsg.sh

where getmsg.sh is the script to execute when a message arrives on port 7777:

#!/bin/sh
read MESSAGE
echo "$MESSAGE"

And now the process (actually a script of mine) that changes the file can notify the other side like this:

echo "hello" | netcat 10.0.0.3 7777

where 10.0.0.3 is the IP of the listening side.

Last edited by Ulysses_; 09-12-2018 at 01:28 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SendSMTPCommand: Timeout waiting for response after 15 seconds lq_win Linux - Newbie 2 02-02-2017 08:39 PM
LXer: 9 ways to make your IT department move faster LXer Syndicated Linux News 0 09-23-2015 07:35 AM
[SOLVED] testing the seven ways to reboot tbodine88 Linux - Kernel 1 08-15-2012 04:43 PM
Ways to make RH linux faster sluge Linux - Software 8 06-21-2012 09:18 AM
[SOLVED] Reboot/shutdown problem: net.eth0 waiting for localmount (50 seconds) linuxNewbie. Gentoo 1 10-21-2011 12:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration