0

Hi guys!

I have encountered a very strange thing today and I want to understand why it happens. I was doing it a whole day until I figured out what is happening.

So I was writing a bash script to automate building via Jenkins.

the script looks something like this:

#!/bin/bash
WORKDIR="sftp_servername"
USERNAME="someuser"
PASSWORD="somepassword"
HOST="somehost"
HTDOCS="web"

if [ ! -d "$WORKDIR" ]; then mkdir -m 744 "$WORKDIR"; fi

if !(echo "$PASSWORD" | sshfs "$USERNAME@$HOST:/" "$WORKDIR" -p 22 -o ServerAliveInterval=60,password_stdin)
then
    echo "Failed to connect to $HOST"
    exit
fi

cd $WORKDIR

>>> ls -la <<< !

if [ -d "$HTDOCS" ]
then 
    unlink "./$HTDOCS"
fi

... additional commands to link the folder to another release etc. that works just fine

now the above script DOES work ( and removes the $WORKDIR symlink ) if the ls -la is present ! How is it possible. If I remove the ls -la line, it goes with "cannot delete $WORKDIR is a directory" Does the sshfs needs a ls to "realize" that the $WORKDIR is a symlink and not a folder ?

If it's so, do you have any, more intelligent solution for it, rather than ls it ?

ononononon
  • 1,033
  • 4
  • 14
  • 25
  • It seems like you have a caching problem or a race condition. Perhaps `sshfs` is is returning before everything is ready, and the `ls` either gives it time to complete, or forces a cache update. You might try `sleep` for a few seconds instead (right after `sshfs`) and see if that does anything. I don't have a "clean" solution though.... – gilez Sep 26 '16 at 20:58
  • Yes, I tried that but it didn't work – ononononon Sep 29 '16 at 08:28

0 Answers0