S
S
sazhyk2018-12-27 09:56:46
linux
sazhyk, 2018-12-27 09:56:46

What is wrong with writing the script?

Script
#!/bin/sh

OBNAM=/usr/bin/obnam

CREDENTIALS=/root/.smbclient

BAK_SHARE1_SRC=//192.168.0.1/share1
BAK_SHARE1_DST=/mnt/share1
BAK_SHARE2_SRC=//192.168.66.4/share2
BAK_SHARE2_DST=/mnt/share2

BAK_STOR=/backup

LOCK=$BAK_SHARE2_DST/success.lock

mount -o remount,rw $BAK_STOR
mount -t cifs $BAK_SHARE1_SRC $BAK_SHARE1_DST -o ro,credentials=$CREDENTIALS
mount -t cifs $BAK_SHARE2_SRC $BAK_SHARE2_DST -o ro,credentials=$CREDENTIALS

if [ -f $LOCK ]; 
  $OBNAM backup;
elif [ ! -f $LOCK ]; then
  echo 'Lockfile not found!' >> /var/log/obnam.log;
fi

umount $BAK_SHARE2_DST
umount $BAK_SHARE1_DST
mount -o remount,ro $BAK_STOR


I think the essence of the script is clear, we mount two network folders, one of them has a $LOCK file. We check if it is, then we make a backup with the obnam program. The problem is that after executing the command, the $OBNAM backup;execution of the script continues. That is, the commands below the condition for checking the existence of a file are executed - network folders are unmounted.
Actually the question is how to make the script "wait" while the command is being executed $OBNAM backup;?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2018-12-27
@saboteur_kiev

Add "wait" command

.....
...
if [ -f $LOCK ]; 
  $OBNAM backup;
elif [ ! -f $LOCK ]; then
  echo 'Lockfile not found!' >> /var/log/obnam.log;
fi

wait
umount $BAK_SHARE2_DST
umount $BAK_SHARE1_DST
mount -o remount,ro $BAK_STOR

Well, or another option, see what exactly is inside /usr/bin/obnam - most likely this is a script in which something is called there in the background.

S
SOTVM, 2018-12-27
@sotvm

$OBNAM backup && next

S
Shoolcs, 2018-12-27
@noob1

Have a look here - https://stackoverflow.com/questions/356100/how-to-... . Run a check loop - whether the process is running and after completion, continue the script execution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question