Bash check if user failed

I am writing a script to transfer some files via sftp. I wanted to make the transfer as a local transfer by setting the directory using sshfs, because it greatly simplifies creating the required directory structure. The problem I am facing is that I am not sure how to deal with a situation where you do not have a network connection. Basically I need a way to determine if the sshfs command worked. Any ideas on how to get a script to execute a bail if the remote directory cannot be installed?

+3
source share
2 answers

Just check if sshfs0 returns (success):

sshfs user@host:dir mountpoint || exit 1

, bash || . , , :

if !( sshfs user@host:dir mountpoint ); then
  echo "Mounting failed!"
  exit 1
fi

Edit:

, . - Sparr 1

. : 0 . , , 0 true false. , ( ).

+5

, mount sshfs. :

if !( mountpoint -q /my/dir ); then
    echo "/my/dir is not a mountpoint"
else
    echo "/my/dir is a mountpoint"
fi

: -bash: !( mountpoint -q /my/dir ): No such file or directory

:

if (! mountpoint -q /my/dir ); then
    echo "/my/dir is not a mountpoint"
else
    echo "/my/dir is a mountpoint"
fi
+2

Source: https://habr.com/ru/post/1708613/


All Articles