atualizar conteúdo variável

atualizar conteúdo variável

estou editando o arquivo de script do ponto de montagem da rede. Quando a variável é montada, ela contém informações, mas quando é desmontada aparece vazia, e se o script pedir para montar, o conteúdo da variável não é atualizado.

VARIABLE=$(df -h | awk '{print $1}'| grep //user@IP/path/user)

Quando desmontado: echo $VARIABLEvazio, se eu montar com o comando:

open smb://user:passwd@IP/path/user

e digite df -h | awk '{print $1}' | grep //user@IP/path/user parece //user@IP/path/user , mas se eu der o comando de verificação, echo $VARIABLEparece vazio

Alguém pode me ajudar?

Responder1

Obrigado!!! Eu realmente sei que a variável é dinâmica era o problema. Consegui gerar outra chamada de variável CHECK, meu código não está bonito, queria que voltasse para verificar se está montado, para diminuir linhas de código. Siga o meu script de shell de código

#!/bin/sh
#Thunderbird Backup Script by VPN in MAC OS X

#Variables description
SOURCE=/Users/username/Library/Thunderbird/Profiles/tsg0o7yk.default-release
TARGET=/Volumes/username
MOUNTED=$(df -h | awk '{print $1}' | grep //[email protected]/BackupThunderbird/username)
PATHDST='//[email protected]/BackupThunderbird/username'
SUCCESS='echo "YOUR BACKUP THUNDERBIRD WAS MADE!"'
ERROR='echo "COULD NOT PERFORM THUNDERBIRD BACKUP, CHECK LAN/WAN CONNECTIVITY AND AVALIABILITY OF THE UNIT STORAGE REMOTE STATUS"'
DATE=`date +%d/%m/%Y-%H-%M-%S`

#Connection test, if to fail will connect TunnelBlick
ping -c2 192.168.0.123 > /dev/null

if [ $? -eq 0 ];
    then
        echo "Connection OK time wait 30s for disconnect mount for test!"
    else
        echo "Disconected Tunnelblick, wait to connect..."
        osascript -e "tell application \"/Applications/Tunnelblick.app\"" -e "connect \"QNAP-MYVPN\"" -e "end tell" #call OpenVPN Tunnelblick MAC OS
        sleep 30
fi

backup () {
    echo "Please don't disconnect or unmount 192.168.0.123, running proccess backup..."
    rsync -rltpDhu $SOURCE/abook.* $TARGET 2> $TARGET/abook.log
    rsync -rltpDhu $SOURCE/history.* $TARGET 2> $TARGET/history.log
    rsync -rltpDhu --stats --delete-after $SOURCE/ImapMail/email-ssl.com.br $TARGET | mail -s "Report Thunderbird Backup" myemail@provider
sleep 30
    $SUCCESS | mail -s "$DATE - VPN Thunderbird Backup" username@localhost -c myemail@provider
    diskutil unmount /Volumes/username
}

no_backup () {
    echo "BACKUP COULD NOT BE PERFORMED, CONTACT YOUR ADMINISTRATOR"
    $ERROR | mail -s "$DATE - ERROR VPN Thunderbird Backup" username@localhost
} 


mount_function () {
    open smb://username:[email protected]/BackupThunderbird/username    # user remote unit storage 
    sleep 60
}

mounted () {
echo $MOUNTED
if [ $MOUNTED ]
    then
        echo "Mounted Unit"     
        backup  # call backup function
        exit
    elif [ !$MOUNTED ]
        then    
            echo "Unmounted Unit, mounting..."          
            mount_function  # call mount function
fi

CHECK=$(df -h | awk '{print $1}' | grep $PATHDST)
echo $CHECK
    
if [ $CHECK ]
    then
        backup
        echo "Script Verification when successfully"
    else
        no_backup
        echo "Script verification no successfully"
fi      
}
mounted
    
# Tunnelblick disconnecting
echo "Tunnelblick connection disconnecting"
osascript -e "tell application \"/Applications/Tunnelblick.app\"" -e "disconnect \"QNAP-MYVPN\"" -e "end tell"

informação relacionada