Skip to main content
Fixed timeout code to work.
Source Link
Alexis Wilke
  • 2.3k
  • 2
  • 20
  • 38

init scripts are started in order as defined by the S## numbers. Newer versions of Unix (at least on Linux) start the same ## numbers in parallel (Although you can turn that feature off...) All you have to do it use a ## that's after the network and fsmount number. Then it should work. However, if the fsmount starts in the background, the easiest is probably to probe for files on the mounted drive. Something like this:

while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
done

This will wait until the file appears. If not there yet, sleep for a second then try again.

To avoid the potential problem of someone creating the file you are testing on the local computer, you may instead want to use the mountpoint command line as in:

while ! mountpoint -q /mnt/over-there
do
    sleep 1
done

(From comment below.) The -q is to make the command quiet.

--- Update: timeout after 30 attempts

In shell script you can also count and test numbers:

count=0
while ! test -f /mnt/over-there/this/file/here -a $count -lt 30
do
    sleep 1
    count=`expr $count + 1`
    if test $count -eq 30
    then
        echo "timed out!"
        exit 1
    fi
done

This will stop if count reaches 30 (30 seconds of sleep plus the time it takes to check whether the file is available or not) after which it prints the error message "timed out!".

--- Update: in case you were to switch to systemd

With systemd, the Unit section supports:

ConditionPathIsMountPoint=/mnt/over-there

which does the same thing as the above script, without the timeout. This statement prevents starting your command until the mount exists.

init scripts are started in order as defined by the S## numbers. Newer versions of Unix (at least on Linux) start the same ## numbers in parallel (Although you can turn that feature off...) All you have to do it use a ## that's after the network and fsmount number. Then it should work. However, if the fsmount starts in the background, the easiest is probably to probe for files on the mounted drive. Something like this:

while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
done

This will wait until the file appears. If not there yet, sleep for a second then try again.

To avoid the potential problem of someone creating the file you are testing on the local computer, you may instead want to use the mountpoint command line as in:

while ! mountpoint -q /mnt/over-there
do
    sleep 1
done

(From comment below.) The -q is to make the command quiet.

--- Update: timeout after 30 attempts

In shell script you can also count and test numbers:

count=0
while ! test -f /mnt/over-there/this/file/here -a $count -lt 30
do
    sleep 1
    count=`expr $count + 1`
    if test $count -eq 30
    then
        echo "timed out!"
        exit 1
    fi
done

This will stop if count reaches 30 (30 seconds of sleep plus the time it takes to check whether the file is available or not) after which it prints the error message "timed out!".

--- Update: in case you were to switch to systemd

With systemd, the Unit section supports:

ConditionPathIsMountPoint=/mnt/over-there

which does the same thing as the above script, without the timeout. This statement prevents starting your command until the mount exists.

init scripts are started in order as defined by the S## numbers. Newer versions of Unix (at least on Linux) start the same ## numbers in parallel (Although you can turn that feature off...) All you have to do it use a ## that's after the network and fsmount number. Then it should work. However, if the fsmount starts in the background, the easiest is probably to probe for files on the mounted drive. Something like this:

while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
done

This will wait until the file appears. If not there yet, sleep for a second then try again.

To avoid the potential problem of someone creating the file you are testing on the local computer, you may instead want to use the mountpoint command line as in:

while ! mountpoint -q /mnt/over-there
do
    sleep 1
done

(From comment below.) The -q is to make the command quiet.

--- Update: timeout after 30 attempts

In shell script you can also count and test numbers:

count=0
while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
    count=`expr $count + 1`
    if test $count -eq 30
    then
        echo "timed out!"
        exit 1
    fi
done

This will stop if count reaches 30 (30 seconds of sleep plus the time it takes to check whether the file is available or not) after which it prints the error message "timed out!".

--- Update: in case you were to switch to systemd

With systemd, the Unit section supports:

ConditionPathIsMountPoint=/mnt/over-there

which does the same thing as the above script, without the timeout. This statement prevents starting your command until the mount exists.

init scripts are started in order as defined by the S## numbers. Newer versions of Unix (at least on Linux) start the same ## numbers in parallel (Although you can turn that feature off...) All you have to do it use a ## that's after the network and fsmount number. Then it should work. However, if the fsmount starts in the background, the easiest is probably to probe for files on the mounted drive. Something like this:

while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
done

This will wait until the file appears. If not there yet, sleep for a second then try again.

To avoid the potential problem of someone creating the file you are testing on the local computer, you may instead want to use the mountpoint command line as in:

while ! mountpoint -q /mnt/over-there
do
    sleep 1
done

(From comment below.) The -q is to make the command quiet.

--- Update: timeout after 30 attempts

In shell script you can also count and test numbers:

count=0
while ! test -f /mnt/over-there/this/file/here -a $count -lt 30
do
    sleep 1
    count=`expr $count + 1`
done
    if test $count -eq 30
    then
        echo "timed out!"
        exit 1
    fi
done

This will stop if count reaches 30 (30 seconds of sleep plus the time it takes to check whether the file is available or not) after which it prints the error message "timed out!".

--- Update: in case you were to switch to systemd

With systemd, the Unit section supports:

ConditionPathIsMountPoint=/mnt/over-there

which does the same thing as the above script, without the timeout. This statement prevents starting your command until the mount exists.

init scripts are started in order as defined by the S## numbers. Newer versions of Unix (at least on Linux) start the same ## numbers in parallel (Although you can turn that feature off...) All you have to do it use a ## that's after the network and fsmount number. Then it should work. However, if the fsmount starts in the background, the easiest is probably to probe for files on the mounted drive. Something like this:

while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
done

This will wait until the file appears. If not there yet, sleep for a second then try again.

To avoid the potential problem of someone creating the file you are testing on the local computer, you may instead want to use the mountpoint command line as in:

while ! mountpoint -q /mnt/over-there
do
    sleep 1
done

(From comment below.) The -q is to make the command quiet.

--- Update: timeout after 30 attempts

In shell script you can also count and test numbers:

count=0
while ! test -f /mnt/over-there/this/file/here -a $count -lt 30
do
    sleep 1
    count=`expr $count + 1`
done
if test $count -eq 30
then
    echo "timed out!"
    exit 1
fi

This will stop if count reaches 30 (30 seconds of sleep plus the time it takes to check whether the file is available or not) after which it prints the error message "timed out!".

--- Update: in case you were to switch to systemd

With systemd, the Unit section supports:

ConditionPathIsMountPoint=/mnt/over-there

which does the same thing as the above script, without the timeout. This statement prevents starting your command until the mount exists.

init scripts are started in order as defined by the S## numbers. Newer versions of Unix (at least on Linux) start the same ## numbers in parallel (Although you can turn that feature off...) All you have to do it use a ## that's after the network and fsmount number. Then it should work. However, if the fsmount starts in the background, the easiest is probably to probe for files on the mounted drive. Something like this:

while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
done

This will wait until the file appears. If not there yet, sleep for a second then try again.

To avoid the potential problem of someone creating the file you are testing on the local computer, you may instead want to use the mountpoint command line as in:

while ! mountpoint -q /mnt/over-there
do
    sleep 1
done

(From comment below.) The -q is to make the command quiet.

--- Update: timeout after 30 attempts

In shell script you can also count and test numbers:

count=0
while ! test -f /mnt/over-there/this/file/here -a $count -lt 30
do
    sleep 1
    count=`expr $count + 1`
    if test $count -eq 30
    then
        echo "timed out!"
        exit 1
    fi
done

This will stop if count reaches 30 (30 seconds of sleep plus the time it takes to check whether the file is available or not) after which it prints the error message "timed out!".

--- Update: in case you were to switch to systemd

With systemd, the Unit section supports:

ConditionPathIsMountPoint=/mnt/over-there

which does the same thing as the above script, without the timeout. This statement prevents starting your command until the mount exists.

Fixed the mountpoint path. Added a paragraph about systemd.
Source Link
Alexis Wilke
  • 2.3k
  • 2
  • 20
  • 38

initinit scripts are started in order as defined by the S## numbers. Newer versions of Unix (at least on Linux) start the same ## numbers in parallel (Although you can turn that feature off...) All you have to do it use a ## that's after the network and fsmountfsmount number. Then it should work. However, if the fsmountfsmount starts in the background, the easiest is probably to probe for files on the mounted drive. Something like this:

while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
done

This will wait until the file appears. If not there yet, sleep for a second then try again.

To avoid the potential problem of someone creating the file you are testing on the local computer, you may instead want to use the mountpoint command line as in:

while ! mountpoint -q /mnt/over-there/this/file/here
do
    sleep 1
done

(From comment below.) The -q is to make the command quiet.(From comment below.) The -q is to make the command quiet.

--- Update: timeout after 30 attemptsUpdate: timeout after 30 attempts

In shell script you can also count and test numbers:

count=0
while ! test -f /mnt/over-there/this/file/here -a $count -lt 30
do
    sleep 1
    count=`expr $count + 1`
done
if test $count -eq 30
then
    echo "timed out!"
    exit 1
fi

This will stop if count reaches 30 (30 seconds of sleep plus the time it takes to check whether the file is available or not) after which it prints the error message "timed out!".

--- Update: in case you were to switch to systemd

With systemd, the Unit section supports:

ConditionPathIsMountPoint=/mnt/over-there

which does the same thing as the above script, without the timeout. This statement prevents starting your command until the mount exists.

init scripts are started in order as defined by the S## numbers. Newer versions of Unix (at least on Linux) start the same ## numbers in parallel (Although you can turn that feature off...) All you have to do it use a ## that's after the network and fsmount number. Then it should work. However, if the fsmount starts in the background, the easiest is probably to probe for files on the mounted drive. Something like this:

while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
done

This will wait until the file appears. If not there yet, sleep for a second then try again.

To avoid the potential problem of someone creating the file you are testing on the local computer, you may instead want to use the mountpoint command line as in:

while ! mountpoint -q /mnt/over-there/this/file/here
do
    sleep 1
done

(From comment below.) The -q is to make the command quiet.

--- Update: timeout after 30 attempts

In shell script you can also count and test numbers:

count=0
while ! test -f /mnt/over-there/this/file/here -a $count -lt 30
do
    sleep 1
    count=`expr $count + 1`
done
if test $count -eq 30
then
    echo "timed out!"
    exit 1
fi

This will stop if count reaches 30 (30 seconds of sleep plus the time it takes to check whether the file is available or not) after which it prints the error message "timed out!".

init scripts are started in order as defined by the S## numbers. Newer versions of Unix (at least on Linux) start the same ## numbers in parallel (Although you can turn that feature off...) All you have to do it use a ## that's after the network and fsmount number. Then it should work. However, if the fsmount starts in the background, the easiest is probably to probe for files on the mounted drive. Something like this:

while ! test -f /mnt/over-there/this/file/here
do
    sleep 1
done

This will wait until the file appears. If not there yet, sleep for a second then try again.

To avoid the potential problem of someone creating the file you are testing on the local computer, you may instead want to use the mountpoint command line as in:

while ! mountpoint -q /mnt/over-there
do
    sleep 1
done

(From comment below.) The -q is to make the command quiet.

--- Update: timeout after 30 attempts

In shell script you can also count and test numbers:

count=0
while ! test -f /mnt/over-there/this/file/here -a $count -lt 30
do
    sleep 1
    count=`expr $count + 1`
done
if test $count -eq 30
then
    echo "timed out!"
    exit 1
fi

This will stop if count reaches 30 (30 seconds of sleep plus the time it takes to check whether the file is available or not) after which it prints the error message "timed out!".

--- Update: in case you were to switch to systemd

With systemd, the Unit section supports:

ConditionPathIsMountPoint=/mnt/over-there

which does the same thing as the above script, without the timeout. This statement prevents starting your command until the mount exists.

Fixed the last paragraph, added example with mountpoint.
Source Link
Alexis Wilke
  • 2.3k
  • 2
  • 20
  • 38
Loading
Added another example with a count to timeout
Source Link
Alexis Wilke
  • 2.3k
  • 2
  • 20
  • 38
Loading
Source Link
Alexis Wilke
  • 2.3k
  • 2
  • 20
  • 38
Loading