
¿Alguien puede ayudarme a depurar este sencillo script? Lo he estado intentando durante 2 horas pero parece que no puedo hacerlo funcionar.
#!/bin/bash
echo "Search for MMSC or WAP connectivity errors"
sftpErrorCount=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" | grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| wc -l)
if [ "$sftpErrorCount" -gt 0 ]
then
sftpErrorDate=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" | grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| tail -1)
echo "Error found at around $sftpErrorDate please check FTP logs"
else
echo "No errors found"
Error al ejecutar el script:
$ sh test_script.sh
Search for MMSC or WAP connectivity errors
test_script.sh: line 14: syntax error: unexpected end of file
Respuesta1
Debe cerrar su declaración if con la palabra fi
.
#!/bin/bash
echo "Search for MMSC or WAP connectivity errors"
sftpErrorCount=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" |
grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| wc -l)
if [ "$sftpErrorCount" -gt 0 ] ; then
sftpErrorDate=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" |
grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| tail -1)
echo "Error found at around $sftpErrorDate please check FTP logs"
else
echo "No errors found"
fi
# ^ This closes the block.
También tenga en cuenta que hice algunos cambios de estilo en su guión. La sangría puede hacer que errores como estos sean más fáciles de encontrar.