有谁知道为什么这个脚本不起作用?
filename: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
并进入远程机器没有问题。谢谢!
答案 0 :(得分:3)
问题是你的脚本中的这样的行:
PATH='/var/www/vhosts/staging\.example\.com'
您将保留路径env variable PATH
设置为其他内容,并从/bin, /usr/bin, /sbin, /usr/sbin, /usr/local/bin
中删除PATH
等,这是运行sed, awk, grep, find
等核心unix二进制文件所需的内容。< / p>
最好使用PATH
以外的其他变量名称,如:
MYPATH='/var/www/vhosts/staging\.example\.com'