2

I'm setting up a simple backup script to backup key files on my server every 12 hours. Just trying to test the script now and I'm getting the following error message;

 python /<pathwayhere>/autobackup.sh
 File "/<pathwayhere>/autobackup.sh", line 2
 exec {lock_fd}>/<pathwayhere>/backuplock || exit 1
              ^ SyntaxError: invalid syntax

I have ensured all of the encodings are correct, and I've recreated the file both in the terminal and using WinSCP as well to no avail. I can't work out why the script won't run, so any advice and ideas would be appreciated.

Here is the original file;

#!/bin/bash
exec {lock_fd}>/<pathway here>/lock/backuplock || exit 1
flock -n "$lock_fd" || { echo "ERROR: flock() failed." >&2; exit 1; }
if [ -z "$STY" ]; then exec screen -dm -S backup /bin/bash "$0"; fi

python /<pathway here>/scripts/backup/workwarn5.py
sleep 5m
python /<pathway here>/scripts/backup/workwarn1.py
sleep 1m
python /<pathway here>/scripts/backup/workstart.py

To note as well, my python scripts work fine. It is just a simple shell script I am trying to run.

New contributor
Jacob Eells is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 1
    That error message looks like it's from Python, and you also seem to be running python /<pathwayhere>/autobackup.sh. Shouldn't you run the script with a shell, as in bash /path/to/autobackup.sh (or just /path/to/autobackup.sh if the execute permission bit is set)? – ilkkachu Nov 8 at 14:25
  • You were totally correct. I was running the command incorrectly. However, I've now got this error message instead; #!/bin/bash: No such file or directory ERROR: flock() failed. Any ideas? – Jacob Eells Nov 8 at 14:31
  • you should edit your question to show exactly what commands you run, and what the exact error message is – ilkkachu Nov 8 at 16:06

Your Answer

Jacob Eells is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.