有誰知道爲什麼這個腳本不起作用?變量替換sed
文件名:DB
#!/usr/local/bin/bash
if [ -z "$1" ]; then
echo "Must specify source DB environment"
echo "One of s (for Staging), p (for Production)"
exit
elif [ "$1" == "s" -o "$1" == "p" ]; then
if [ "$1" == "s" ]; then
echo "Connecting to Staging DB"
URL='staging\.example\.com'
PATH='/var/www/vhosts/staging\.example\.com'
else
echo "Connecting to Production DB"
URL='example\.com'
PATH='/var/www/vhosts/example\.com'
fi
ssh host "mysqldump -udbuser -pdbpass staging | gzip -9" | gzip -d | sed -e "s+$URL+example\.local+g" -e "s+$PATH+/Library/WebServer/Documents/example+g" | mysql -uroot -proot example_local
fi
我收到以下錯誤:
./db: line 14: ssh: command not found
./db: line 14: gzip: command not found
./db: line 14: sed: command not found
./db: line 14: mysql: command not found
注:
- 權限上
./db
是777 host
保存在.ssh/config
。我可以運行ssh host
並且無法進入遠程機器。- mysql的憑證對於遠程和本地都是正確的
- 我可以在命令行上單行運行最後的ssh。我很確定這是在sed中的變量替換,這是搞砸了。
謝謝!
對不起,我應該補充說,我正在運行...我不知道你叫什麼...... OSX上的「家庭」用戶。 @anubhava說得沒錯,我正在用腳本使用的服務器路徑覆蓋我的系統$ PATH。 –