mercredi 29 avril 2015

Run a script if not already running - getting [0: not found

I'm trying to run a script if not already running using another script.

test $ ls
arcane_script.py  calling_script.sh

This is what my script looks right now

test $ cat calling_script.sh 
#!/bin/bash

PROCESSES_RUNNING=$(ps -ef | grep "arcane_script.py" | grep -v "grep" | wc -l)
echo $PROCESSES_RUNNING
if [$PROCESSES_RUNNING = "0"]; then
    /usr/bin/python arcane_script.py
fi;

I've tried other variants within the if block, like [$PROCESSES_RUNNING -eq 0], but all of them output the same error message

test $ ./calling_script.sh 
0
./calling_script.sh: line 5: [0: command not found
test $ sh calling_script.sh 
0
calling_script.sh: 5: calling_script.sh: [0: not found

What am I doing wrong and how can I resolve it? I've googled around, but couldnt find much help.

Aucun commentaire:

Enregistrer un commentaire