Plesk 12 tentando obter um email com detalhes da fila

1

Estou tentando configurar um e-mail que informará quando houver 100 e-mails na fila de e-mails. Eu não sou uma pessoa do servidor Linux, então eu gostaria de receber ajuda. Eu tenho:

            # get server hostname
            hostname='cat /etc/hostname'

            current_mailq= "/var/qmail/bin/qmail-qstat"

            # 'postqueue -p | tail -n 1 | cut -d' ' -f5'

            yourEmail="[email protected]"


            if [ "$current_mailq" -gt "100" ]
            then
            echo "Mail queue problem - there is currently $current_mailq mails in queue. Please check it out." > check_email_queue_outgoing.txt
            mail -s "$hostname - mail queue alert - there are $current_mailq emails in queue" "$yourEmail" < check_email_queue_outgoing.txt
            else
            echo "Mail queue is fine - there is currently $current_mailq mails in queue. Please check it out."
            echo "Do nothing, situation is fine."
            fi

Que eu encontrei em um fórum plesk.

Quando executo o cron job, ele diz

        Output from command /home/xxxxxx/check_email_queue.sh ..

        /home/xxxxxx/check_email_queue.sh: line 2: 
        : command not found
        /home/xxxxxx/check_email_queue.sh: line 3: 
        : command not found
        cat: /etc/hostname: No such file or directory
        /home/xxxxxx/check_email_queue.sh: line 6: 
        : command not found
        /home/xxxxxx/check_email_queue.sh: line 7: /var/qmail/bin/qmail-qstat
        : No such file or directory
        /home/xxxxxx/check_email_queue.sh: line 8: 
        : command not found
        /home/xxxxxx/check_email_queue.sh: line 10: 
        : command not found
        /home/xxxxxx/check_email_queue.sh: line 12: 
        : command not found
        /home/xxxxxx/check_email_queue.sh: line 13: 
        : command not found
        /home/xxxxxx/check_email_queue.sh: line 21: syntax error near unexpected token 'fi'
        /home/xxxxxx/check_email_queue.sh: line 21: 'fi'
        Mail handler 'limit-out' said: REPLY:554:5.7.0 Your message could not be sent. The user xxxxxx is not allowed to send email.

Alguma idéia, por favor?

editar ...

Eu troquei o usuário para root e ele agora envia e-mails, mas os outros erros permanecem - não consigo descobrir o tamanho da fila de e-mails obrigado

    
por user1616338 31.12.2016 / 17:54

1 resposta

0

Experimente esta versão:

#!/bin/bash

hostname='cat /etc/hostname'

current_mailq="'postqueue -p | tail -n 1 | cut -d' ' -f5'"
yourEmail="[email protected]"

echo "$current_mailq"

if (( "$current_mailq" >= "100" )) ; then
echo "Mail queue problem - there is currently $current_mailq mails in queue. Please check it out." > check_email_queue_outgoing.txt
mail -s "$hostname - mail queue alert - there are $current_mailq emails in queue" "$yourEmail" < check_email_queue_outgoing.txt
else
echo "Mail queue is fine - there is currently $current_mailq mails in queue. Please check it out."
echo "Do nothing, situation is fine."
fi

Preste atenção, é muito difícil fazer um bom código bash / sh / cmd portátil. IMO, é melhor usar o Idioma do Google e criar programas portáteis claros para qualquer sistema operacional.

    
por 01.01.2017 / 13:37