Syntax error I don'rt understand

Hi folks,

I am currently trying to write a script for an automatic backup that looks like that:

 1 #!/bin/sh
  2 
  3 # Load environment variables from the .env1 file
  4 if [ -f "/home/uli/.env1" ]; then
  5     export $(grep -v '^#' /home/uli/.env1 | xargs)
  6 else
  7     echo ".env1 file not found!"
  8     exit 1
  9 fi
 10 
 11 # Define variables
 12 RESTIC_REPOSITORY="sftp:udapro.de:/srv/system"
 13 EMAIL_RECIPIENT="info@ulikleemann.de"
 14 DATE=$(date +"%Y-%m-%d")
 15 TIME=$(date +"%H:%M:%S")
 16 SUBJECT_SUCCESS="System-Backup Successful"
 17 SUBJECT_FAILURE="System-Backup Failure"
 18 SSH_KEY="/home/uli/.ssh/id_ed25519"
 19 OTP_SECRET="$GOOGLE_SECRET"
 20 
 21 # Function to send email
 22 send_email() {
 23     local subject="$1"
 24     local body="$2"
 25     echo "$body" | mail -s "$subject" "$EMAIL_RECIPIENT"
 26 }
 27 
 28 # Function to generate OTP
 29 generate_otp() {
 30     oathtool --totp -b "$OTP_SECRET"
 31 }
 32 
 33 # Generate OTP
 34 OTP=$(generate_otp)
 35 
 36 # Perform the backup
 37 if restic -r "$RESTIC_REPOSITORY" --password-file  <echo ("$RESTIC_PASSWORD") --option ssh.command="ssh -i $SSH_KEY -o BatchMode=yes -o StrictHostK    eyChecking=no -o ChallengeResponseAuthentication=no -o UsePAM=yes -o AuthenticationMethods=publickey" backup /etc /lib /lib64 /usr /opt /var; then
 38     send_email "$SUBJECT_SUCCESS" "The system backup completed successfully on $DATE at $TIME."
 39 else
 40     send_email "$SUBJECT_FAILURE" "The system backup failed on $DATE at $TIME."
 41     exit 1
 42 fi
 43 

In Line 37 a fet a Syntax-Error saying: 37: Syntax error: “(” unexpected (expecting “then”)

Which ( does it mean? and how to write that then statement correctly?

I don’t understand that error, could you please help?

Many thanks in advance ,

Uli

in bash you put the body of the if statement after a then

if <condition>
then
  <body>
else
  <body>
fi

try to put the then on a new line, or search for the condition ending prematurely

Hi ILM,
Many thanks for you help it runs now, but there is still one problem I have no idea how to fix maybe you.
the script should backup different folders to a server via SFTP, that uses publickey (ssh-key) and OTP authentication with google-authenticator.
The restic password and google-secret is stored in that .env1 file. The script accepts the restic password for the backup repository, but always asks for the top (6-digit number), that I have to put in manually. And as the script shall run automatically as a cronjob that ist the pain . Do you maybe have an idea how to edit it, so it doesn’t ask for a manual input? That would be extremely helpful.

Many thanks in advance

Uli

Solved I had to edit sshd_config so that it asls for the publickey only.