在elif比较中找不到命令>庆典

时间:2016-08-25 18:51:34

标签: bash unix

由于某种原因,在第一个if语句之后命令没有运行。 " /usr/local//backup.sh:sleep:not found"例如......

第一个if语句如下:

if [ "$command" == "start -c" ]; then
echo -e "${ORANGE}Starting website backup...${E}"
sleep 1
DT=`date +%Y-%m-%d`
echo -e "${ORANGE}Started backup at $DT ${E}"
sleep 1
tar -zcvf web-$DT.tar.gz /usr/local/www/nginx
echo -e "${ORANGE}Compatced files, moving to backup directory${E}"
sleep 1
mv web-$DT.tar.gz $PATH/web-$DT.tar.gz
echo -e "${CYAN}Moved to backups ($PATH/web-$DT.tar.gz)\nDo you want to upload to ftp?${E}\n${CYAN} 'y' or 'n'?${E}"
read answer
if [ "$answer" == "y" ]; then
    echo -e "${ORANGE}Uploading to ftp server...${E}"
    sleep 1
    if ftp -in -u ftp://$USER:$PASS@$HOST/Backups/f $PATH/web-$DT.tar.gz; then
        echo -e "${GREEN}Uploaded! Bye!${E}"
    else
        echo -e "${ORANGE}Couldn't upload with ftp command, trying with curl...${E}"
        sleep 1
        curl -T "$PATH/web-$DT.tar.gz" -u $USER:$PASS ftp://$HOST/Backups/f/
        echo -e "${GREEN}Uploaded! Bye!${E}"
    fi
else
    echo -e "${GREEN}Bye!${E}"
fi

在这个陈述中,一切都运作正常,然而,在elif同情之后,它只是没有。

这是有问题的代码:

elif [ "$command" == "start -d" ]; then
echo -e "${ORANGE}Starting database backup...${E}"
sleep 1
DT=`date +%Y-%m-%d`
echo -e "${ORANGE}Started backup at $DT ${E}"
sleep 1
umask 177
echo -e "${ORANGE}Dumping database 'account'\n${E}"
mysqldump --user=$DBUSER --password=$DBPASS --host=$HOST account > $PATH/account-$DT.sql
sleep 1
echo -e "${ORANGE}Dumping database 'game'\n${E}"
mysqldump --user=$DBUSER --password=$DBPASS --host=$HOST game > $PATH/game-$DT.sql
sleep 1
echo -e "${ORANGE}Dumping database 'forum'\n${E}"
mysqldump --user=$DBUSER --password=$DBPASS --host=$HOST forum > $PATH/forum-$DT.sql
sleep 1
echo -e "${CYAN}Moved to backups ($PATH/<database-date>.sql)\nDo you want to upload to ftp?${E}\n${CYAN} 'y' or 'n'?${E}"
read answer
if [ "$answer" == "y" ]; then
    echo -e "${ORANGE}Uploading to ftp server...${E}"
    sleep 1
    curl -T "$PATH/account-$DT.sql" -u $USER:$PASS ftp://$HOST/Backups/f/Databases/
    curl -T "$PATH/game-$DT.sql" -u $USER:$PASS ftp://$HOST/Backups/f/Databases/
    curl -T "$PATH/forum-$DT.sql" -u $USER:$PASS ftp://$HOST/Backups/f/Databases/
    sleep 1
    echo -e "${GREEN}Uploaded! Bye!${E}"
else
    echo -e "${GREEN}Bye!${E}"
fi

然后我就结束了..

else
    echo -e "${RED}Sorry! Not found${E}"
fi

正如你可以看到if语句中的所有空格以及所有这些空格,那么这有什么问题?

我也是#!/ bin / bash up top,所有变量也都存在。

1 个答案:

答案 0 :(得分:3)

您似乎在代码中的某个位置覆盖了PATH变量的值。 shell需要该变量才能知道在哪里找到像sleep这样的程序(因此“找不到”错误)。将路径变量命名为其他内容。