I am trying to write a nanny script, to use in AWS's Linux terminal, to run a python script that can be a bit flakey at times. I am very new to using the terminal / bash, etc, so I could be missing something totally obvious / second nature to others. Here is what I have:
#! /usr/bin/env bash
while true:
script.py
sleep 1 # pause, so if script.py immediately dies we don't burn a core
I put the above code in a runProgram.sh file, located in the same directory as my python program. I then went into the terminal, and ran:
chmod -x runProgram.sh
followed by:
bash runProgram.sh
The terminal throws the following error:
"line 6: syntax error: unexpected end of file".
I took the bash code right from a stackoverflow response though, so I'm not sure what I'm missing in terms of syntax etc. any help is appreciated!
CodePudding user response:
I was able to reproduce your issue, by directly copy-pasting the snippet you pasted.
Modified your script slightly. Feel free to copy-paste directly.
#!/bin/bash
while [ True ]
do
python3 script.py
done
Also this is my current bash
version
/tmp:$ bash --version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.
Why does chmod x
do?
It essentially gives execute level permissions for your script of interest.
CodePudding user response:
This command makes the file non executable:
chmod -x runProgram.sh
What you want to do is to make executable like so:
chmod x runProgram.sh
Turn both, your shell script and python script executable.
then you can run it by typing ./runProgram.sh
or bash runProgram.sh
.