Bash: Error de sintaxis: inesperado cerca del token 'otro'

Bash: Error de sintaxis: inesperado cerca del token 'otro'

Muy bien, no entiendo en absoluto por qué bash me arroja este error. Creé un script que verifica si una unidad está montada en un directorio. Si se monta una unidad, realiza algunas tareas de rsync (e imprime el estado en un registro). Si no está montado, debería enviarme un correo electrónico (correo redactado del código).

Pero cada vez que ejecuto este código, aparece un "Error de sintaxis: token inesperado cerca de 'más'". ¿Por qué ocurre este error de sintaxis?

Probé con 1 [ en 2 [[ con la declaración f, ejecuté el script en sudo, pero no hubo dados.

Comentarios adicionales agregados al código para que puedas ver la lógica;).

#!/bin/bash
#Print to log that check is starting
printf "Checking if Backup drive is successfully mounted\n" >>/home/fileserver/Applications/Backup/logs/backup.log 2>&1 &&

# Start check
if [[ $(mount | grep -c /home/fileserver/Backup4TB) != 0 ]]; then

# If check is successfull, print it to log & start the backup
printf "Backup Drive successfully mounted, Backing up Applications folder to USB Backup Drive\n" >>/home/fileserver/Applications/Backup/logs/backup.log 2>&1 &&

# Backup using rsync
rsync --log-file=/home/fileserver/Applications/Backup/logs/rsync.log -avhP --delete /home/fileserver/Applications/ /home/fileserver/Backup4TB/Applications >/dev/null 2>&1 &&

# Print to log
printf "Backing up Books folder to USB Backup Drive\n" >>/home/fileserver/Applications/Backup/logs/backup.log 2>&1 &&

# Backup using rsync
rsync --log-file=/home/fileserver/Applications/Backup/logs/rsync.log -avhP --delete /home/fileserver/Media/Books/ /home/fileserver/Backup4TB/Books >/dev/null 2>&1 &&

# SYNTAX ERROR IS HERE - If check is unsuccessfull
else

# Print error to log
printf "ERROR - Mount was insuccesfull, sending email as warning\n" >>/home/fileserver/Applications/Backup/logs/backup.log 2>&1 &&

# Email me
/usr/sbin/ssmtp "MYEMAIL" < /home/fileserver/Applications/Backup/mountingerror/mountingerrorBackup.txt

fi

Respuesta1

Sí, lo encontré: coloco && después de mi último comando justo antes de la declaración else:

...

# Backup using rsync
rsync --log-file=/home/fileserver/Applications/Backup/logs/rsync.log -avhP --delete /home/fileserver/Media/Books/ /home/fileserver/Backup4TB/Books >/dev/null 2>&1 &&

# SYNTAX ERROR IS HERE - If check is unsuccessfull
else

...

Al eliminar el &&, el error desaparece:

...

# Backup using rsync
rsync --log-file=/home/fileserver/Applications/Backup/logs/rsync.log -avhP --delete /home/fileserver/Media/Books/ /home/fileserver/Backup4TB/Books >/dev/null 2>&1 

# SYNTAX ERROR IS HERE - If check is unsuccessfull
else

...

información relacionada