# problem with starting script



## R3plik4tor (Aug 1, 2012)

Hi all..

My problem - I am used this script kontrola.sh for restart crashing proces but problem..


```
#!/bin/sh

GAMEDIR="/home/game"
LOG="$GAMEDIR/corerestart.log"

PIDAUTH=`ps aux | grep auth | grep -v grep | awk '{print $2;}'`
if [ "x$PIDAUTH" != "x" ];
then
echo "`date +%d.%m.%Y-%H:%M:%S` :: AUTH SERVER je ok! PID: $PIDAUTH" >> $LOG
else
echo "`date +%d.%m.%Y-%H:%M:%S` :: AUTH CORE spadlo" >> $LOG
echo "`date +%d.%m.%Y-%H:%M:%S` :: Startuji AUTH ..." >> $LOG
cd $GAMEDIR/auth && ./auth &

fi
```

problem..


```
: not found
: not found
kontrola.sh: 15: Syntax error: "fi" unexpected (expecting "then")
```

I check several discussions, but no information did not help, move, "*then*" or "*fi*" did not work, the system is FreeBSD 8.2 64bit 

help please

or I would anyone written a similar script for python ?


sorry for my english.. and thanks all


----------



## wblock@ (Aug 1, 2012)

What game is this for?


----------



## R3plik4tor (Aug 1, 2012)

ah sorry i am posted older script, my is this..


```
#!/bin/sh

SLOZKA="/home/test"
LOG="$SLOZKA/restart.log"

PIDWEB=`ps aux | grep web | grep -v grep | awk '{print $2;}'`
if [ "x$PIDWEB" != "x" ];
then
echo "`date +%d.%m.%Y-%H:%M:%S` :: WEB SERVER je ok! PID: $PIDWEB" >> $LOG
else
echo "`date +%d.%m.%Y-%H:%M:%S` :: WEB spadl" >> $LOG
echo "`date +%d.%m.%Y-%H:%M:%S` :: Startuji WEB ..." >> $LOG
cd $SLOZKA/web && ./web &

fi
```


----------



## SirDice (Aug 1, 2012)

R3plik4tor said:
			
		

> ```
> PIDWEB=`ps aux | grep web | grep -v grep | awk '{print $2;}'`
> ```


Use pgrep(1) instead of this.


----------



## da1 (Aug 1, 2012)

If you need to have that game up and running all the time, another approach is to use a supervise process for it like svscan, monit, etc.

However, writing a script for it is fun too .


----------



## izotov (Aug 1, 2012)

R3plik4tor said:
			
		

> ah sorry i am posted older script, my is this..
> 
> 
> ```
> ...



And does it not run for you? I tried and it works here just perfectly.
Anyways you might use xtrace and verbose flags with sh to see some more details:

```
#!/bin/sh
set -xv

<your code follows>
```


----------



## R3plik4tor (Aug 1, 2012)

SirDice said:
			
		

> Use pgrep(1) instead of this.



Thanks I go test..


----------



## R3plik4tor (Aug 1, 2012)

problem resolved.. PIDWEB is problem, running proces is "web" but WEB no.. problem is W or w .. thanks all and bye


----------

