actualizar contenido variable

actualizar contenido variable

Estoy editando el archivo de script del punto de montaje de la red. Cuando se ensambla la variable contiene información, pero cuando se desmonta aparece vacía, y si el script pide ensamblar, el contenido de la variable no se actualiza.

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

Cuando está desmontado: echo $VARIABLEvacío, si lo monto con el comando:

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

y escribo df -h | awk '{print $1}' | grep //user@IP/path/user parece //user@IP/path/user pero si doy el comando de verificación eco $VARIABLEparece vacío

¿Puede ayudarme alguien?

Respuesta1

¡¡¡Gracias!!! Realmente sé que la variable dinámica era el problema. Logré generar otra variable llamada CHECK, mi código no es bonito, quería que volvieras a comprobar si está montado, para disminuir líneas de código. Siga el script de shell de mi 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"

información relacionada