1
我對bash非常新鮮,所以任何提示/改進/密碼都是受歡迎的。我非常想提高我的技能。繼續/跳出一個循環,繼續執行
我遇到的問題是選擇了一次選項,無論選擇塊下面的代碼是否被執行。我嘗試了幾個選擇,但顯然我錯過了一些東西。
#!/bin/bash
PROJECT="$1"
USER=sgosselin
LOCAL_DIR=/mnt/
REMOTE_PROJECTS_PATH=/var/test_www
REMOTE_HOST="test-sandbox-01.dev1.in.example.com"
WEB_USER=www-data
declare -A projects
projects=([proj1]=proj1_dir [proj2]=proj2_dir [quit]=quit)
PROJECT_LIST="proj1 proj2 quit"
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run with sudo." 1>&2
exit 1
fi
# Should not have anything to change below
echo "/nSelect project you wish to rsync\n\n"
select PROJECT in $PROJECT_LIST
do
if [ "$PROJECT" = "quit" ]; then
echo
echo "Quitting $0"
echo
exit
fi
for k in "${!projects[@]}"
do
if [ "$k" = "$PROJECT" ]
then
PROJECTDIR=${projects[$k]}
continue
fi
done
echo "Rsynching $PROJECT from $REMOTE_HOST into" $LOCAL_DIR$PROJECTDIR
rsync -azrP [email protected]$REMOTE_HOST:$REMOTE_PROJECTS_PATH/$PROJECT/files/ $LOCAL_DIR$PROJECTDIR
# Switch to files dir, chown to web user
cd $LOCAL_DIR
chown -R $WEB_USER:$WEB_USER . $PROJECTDIR
break
done
# This never gets executed!
echo "Rsync done."
exit
我想你的腳本(我'USER'和'REMOTE_HOST')和它的作品。我看到'Rsync完成了.'。你可以放置更多的'echo'(在所有的命令之後)找到問題的確切位置。或者你可以刪除一些命令來進行測試 - 例如,用rsync刪除行 - 也許你在'Rsync done.'之前被拋出。 – furas
用'set -vx'運行腳本並檢查輸出 –