I am trying to learn shell scripting by reading linuxcommand.org. For some reason I keep getting the error "Not Found", even though it runs all the commands.
The error codes I get are:
minecraft_backup.sh: 21: run_backup: not found
minecraft_backup.sh: 23: function: not found
Here's the script:
#!/bin/bash
#MineCraft backup script by
#Variables
APP=MineCraft
SERVICE=Minecraft_Mod.jar
APPDIR=/opt/MineCraft_Server/bin
BACKUPDIR1=/opt/MineCraft_Server/backup1
BACKUPDIR2=/opt/MineCraft_Server/backup2
#First i want to check if minecraft server is running.
if(ps ax | grep -v grep | grep $SERVICE > /dev/null)
then
echo "$APP is running"
$(run_backup)
else
echo "$APP is not running"
exit 1
fi
function run_backup
{
echo "Starting back up"
#create backup dirs of they do not exit
if [ ! -d "$BACKUPDIR1" ]
then
mkdir $BACKUPDIR1
fi
if [ ! -d "$BACKUPDIR2" ]
then
mkdir $BACKUPDIR2
echo "test"
fi
#backup save1 to save2
rsync -av --delete "$BACKUPDIR1/" "$BACKUPDIR2"
#backup running app to save 1
rsync -av --delete "$APPDIR/" "$BACKUPDIR1"
}
cat test| psp4
psp4 is an alias for prepend 4 spaces.alias psp4="sed -e 's/^/ /'"
– xenoterracide♦ Jan 9 '11 at 6:29sed
to add spaces is not necessary: Next time you need to include code, just paste, mark, and click the 'code' icon over the edit box. You will then witness the magic of stackexchange javascript adding the four spaces for you :) – Janus Jan 10 '11 at 6:59