네트워크 마운트 지점 스크립트 파일을 편집하고 있습니다. 변수가 어셈블링되면 정보가 포함되지만 언로드되면 빈 것으로 나타나고 스크립트에 어셈블링이 필요한 경우 변수 내용이 업데이트되지 않습니다.
VARIABLE=$(df -h | awk '{print $1}'| grep //user@IP/path/user)
제거 시:
echo $VARIABLE
비어 있음(명령을 사용하여 설치하는 경우):
open smb://user:passwd@IP/path/user
입력하는 df -h | awk '{print $1}' | grep //user@IP/path/user
것 같지만 //user@IP/path/user
확인 명령을 내리면 에코가 $VARIABLE
비어 있는 것 같습니다.
누구든지 나를 도와줄 수 있나요?
답변1
감사해요! ! ! 문제는 변수가 동적이라는 것입니다. CHECK를 호출하는 또 다른 변수를 생성했는데, 내 코드가 예쁘지 않습니다. 돌아가서 코드 줄 수를 줄이기 위해 해당 변수가 설치되어 있는지 확인하시기 바랍니다. 내 코드 셸 스크립트를 따르세요.
#!/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"