0
#Variable with date
Now_date=`date +%Y%m%d`
#adding source for an original configuration file
source=/home/bin/custome.conf
#adding varibale to create a copy of original file with date stamp and coping it
customize="$source-$Now_date"
cp -af -- "$source" "$customize"
#Adding massive with folders 
folders=( "Accounts" "Salary" "Taxes" "Review" "Data")
#Launching script by folderds
for group in ${folders[@]}; do
#That a variable for a string we replace
    DIR_INCOMING_REMOTE="/incoming/deltas-${Now_date}/${folders}"
#replacing configuration string in the file /home/bin/custome.conf
    sed -i "/DIR_INCOMING_REMOTE/s|.*|export DIR_INCOMING_REMOTE='${DIR_INCOMING_REMOTE}'|g;" "$customize"
#Launching external script which processing $customize.conf file(now it looks like customize.conf-20200206) and checking for ok message
    ./external_script.sh "$customize" && { echo "exiting fine"; continue; } || { echo "failed"; break; }
done

But i dont know how to add next condition to run the script for every folder only in case if folder exists and the folders are on the remote server:

if ssh 192.168.101.10 '[ -d /home/incoming/deltas-${Now_date}/${folders} ]' 
then
{
   # perform directory check exist for /home/incoming/deltas-20200206/Salary and than run script. the same for other folders, if folder not exists, just skip folder upload. It will run in cron and check for folder creation and than execute script for a next folder.

}
fi

Kwaker
  • 45
  • 9

2 Answers2

1

This construction may help

ssh HOST "[[ -d TESTING_DIR ]] || exit 1" && echo ok || echo fail

Update based on @tripleee comment

ssh HOST test -d "TESTING_DIR" && echo ok || echo fail
Ivan
  • 6,188
  • 1
  • 16
  • 23
  • 1
    The `|| exit 1` is quite unnecessary; `ssh` will already return the exit code from the remote shell. But you should quote the directory name if it contains variable interpolations. And maybe switch to `[` since there is no particular benefit from `[[` here and you can't know if the remote shell is Bash. – tripleee Feb 06 '20 at 13:51
0

You can run it as nested-command; then check the return like THis:

$(ssh dc1 [ -d /some/path ] )
if [ $? -eq 0 ]; then 
    # The path exists
    # more stuff ....
fi;