Cron.daily Exec format error

2

Usando o Ubuntu 16. Eu tenho o seguinte script na pasta cron.daily . No entanto, estou recebendo um erro por meio da notificação por e-mail:

/etc/cron.daily/clamscan_daily:
run-parts: failed to exec /etc/cron.daily/clamscan_daily: Exec format error
run-parts: /etc/cron.daily/clamscan_daily exited with return code 1

Script

  #!/bin/bash
    LOGFILE="/var/log/clamav/clamav-$(date +'%Y-%m-%d').log";
    EMAIL_MSG="Please see the log file attached.";
    EMAIL_FROM="[email protected]";
    EMAIL_TO="[email protected]";
    DIRTOSCAN="/var/www";

    for S in ${DIRTOSCAN}; do
     DIRSIZE=$(du -sh "$S" 2>/dev/null | cut -f1);

     echo "Starting a daily scan of "$S" directory.
     Amount of data to be scanned is "$DIRSIZE".";

     clamscan -ri "$S" >> "$LOGFILE";

     # get the value of "Infected lines"
     MALWARE=$(tail "$LOGFILE"|grep Infected|cut -d" " -f3);

     # if the value is not equal to zero, send an email with the log file attached
     if [ "$MALWARE" -ne "0" ];then
     # using heirloom-mailx below
     echo "$EMAIL_MSG"|mail -a "$LOGFILE" -s "Malware Found" -r "$EMAIL_FROM" "$EMAIL_TO";
     fi
    done

    exit 0

Não consigo descobrir o problema aqui. Alguma idéia?

Eu tentei executar isso no terminal e consegui:

./clamscan_daily
Starting a daily scan of /var/www directory.
 Amount of data to be scanned is 427M.
./clamscan_daily: line 15: /var/log/clamav/clamav-2017-10-25.log: Permission denied
tail: cannot open '/var/log/clamav/clamav-2017-10-25.log' for reading: No such file or directory
./clamscan_daily: line 21: [: : integer expression expected

UPDATE 2:

Quando executo ls -l , só consigo ver o número 2 para esse script. Poderia ser esse o problema?

ls -l
total 56
-rwxr-xr-x 1 root root  376 Mar 31  2016 apport
-rwxr-xr-x 1 root root 1474 Oct 31  2016 apt-compat
-rwxr-xr-x 1 root root  355 May 22  2012 bsdmainutils
-rwxr-xr-x 2 root root  751 Oct  4  2016 clamscan_daily
-rwxr-xr-x 1 root root 1597 Nov 26  2015 dpkg
-rwxr-xr-x 1 root root  372 May  6  2015 logrotate

UPDATE # 3

ls -l /var/log/clamav
total 388
-rw-r--r-- 1 root   root   233 Sep 15  2016 clamav-2016-09-15.log
-rw-r--r-- 1 root   root   234 Sep 16  2016 clamav-2016-09-16.log
-rw-r--r-- 1 root   root   234 Sep 17  2016 clamav-2016-09-17.log
-rw-r--r-- 1 root   root   234 Sep 18  2016 clamav-2016-09-18.log
-rw-r--r-- 1 root   root   233 Sep 19  2016 clamav-2016-09-19.log
-rw-r--r-- 1 root   root   234 Sep 20  2016 clamav-2016-09-20.log
-rw-r--r-- 1 root   root   233 Sep 21  2016 clamav-2016-09-21.log
-rw-r--r-- 1 root   root   233 Sep 22  2016 clamav-2016-09-22.log
-rw-r--r-- 1 root   root   233 Sep 23  2016 clamav-2016-09-23.log
-rw-r--r-- 1 root   root   232 Sep 24  2016 clamav-2016-09-24.log
-rw-r--r-- 1 root   root   232 Sep 25  2016 clamav-2016-09-25.log
-rw-r--r-- 1 root   root   232 Sep 26  2016 clamav-2016-09-26.log
-rw-r--r-- 1 root   root   233 Sep 27  2016 clamav-2016-09-27.log
-rw-r--r-- 1 root   root   233 Sep 28  2016 clamav-2016-09-28.log
-rw-r--r-- 1 root   root   232 Sep 29  2016 clamav-2016-09-29.log
-rw-r--r-- 1 root   root   234 Sep 30  2016 clamav-2016-09-30.log
-rw-r--r-- 1 root   root   234 Oct  1  2016 clamav-2016-10-01.log
-rw-r--r-- 1 root   root   234 Oct  2  2016 clamav-2016-10-02.log
-rw-r--r-- 1 root   root   234 Oct  3  2016 clamav-2016-10-03.log
-rw-r--r-- 1 root   root   234 Oct  4  2016 clamav-2016-10-04.log
-rw-r--r-- 1 root   root   238 Oct 25 15:06 clamav-2017-10-25.log
-rw-r----- 1 clamav adm   5688 Oct 25 15:27 clamav.log
-rw-r----- 1 clamav adm  13196 Oct 22 06:25 clamav.log.1
-rw-r----- 1 clamav adm   2001 Aug 21 06:25 clamav.log.10.gz
-rw-r----- 1 clamav adm    896 Aug 13 06:25 clamav.log.11.gz
-rw-r----- 1 clamav adm   1894 Aug  7 06:25 clamav.log.12.gz
-rw-r----- 1 clamav adm   1359 Oct 16 06:25 clamav.log.2.gz
-rw-r----- 1 clamav adm   1153 Oct  8 06:25 clamav.log.3.gz
-rw-r----- 1 clamav adm   1869 Oct  2 06:25 clamav.log.4.gz
-rw-r----- 1 clamav adm    898 Sep 24 06:25 clamav.log.5.gz
-rw-r----- 1 clamav adm   1336 Sep 18 06:25 clamav.log.6.gz
-rw-r----- 1 clamav adm   1710 Sep 10 06:25 clamav.log.7.gz
-rw-r----- 1 clamav adm   1373 Sep  4 06:25 clamav.log.8.gz
-rw-r----- 1 clamav adm   1794 Aug 27 06:25 clamav.log.9.gz
-rw-r----- 1 clamav adm  46135 Oct 25 15:26 freshclam.log
-rw-r----- 1 clamav adm  83017 Oct 22 06:25 freshclam.log.1
-rw-r----- 1 clamav adm   6219 Aug 21 06:25 freshclam.log.10.gz
-rw-r----- 1 clamav adm   4737 Aug 13 06:25 freshclam.log.11.gz
-rw-r----- 1 clamav adm   6389 Aug  7 06:25 freshclam.log.12.gz
-rw-r----- 1 clamav adm   6382 Oct 16 06:25 freshclam.log.2.gz
-rw-r----- 1 clamav adm   5228 Oct  8 06:25 freshclam.log.3.gz
-rw-r----- 1 clamav adm   6415 Oct  2 06:25 freshclam.log.4.gz
-rw-r----- 1 clamav adm   4580 Sep 24 06:25 freshclam.log.5.gz
-rw-r----- 1 clamav adm   6596 Sep 18 06:25 freshclam.log.6.gz
-rw-r----- 1 clamav adm   5320 Sep 10 06:25 freshclam.log.7.gz
-rw-r----- 1 clamav adm   6921 Sep  4 06:25 freshclam.log.8.gz
-rw-r----- 1 clamav adm  15812 Aug 27 06:25 freshclam.log.9.gz
    
por Joanna Mikalai 25.10.2017 / 15:44

2 respostas

6

Pode parecer uma coisa pequena, mas certifique-se de que os caracteres #! sejam os dois primeiros caracteres do script (sem espaços em branco anteriores). Para ilustrar:

# cat /etc/cron.hourly/shebang-test
  #!/bin/bash
  echo "Hello from $0" >> /tmp/cron.out
#
# run-parts --report /etc/cron.hourly
/etc/cron.hourly/shebang-test:
run-parts: failed to exec /etc/cron.hourly/shebang-test: Exec format error
run-parts: /etc/cron.hourly/shebang-test exited with return code 1
#

(falha); mas depois de remover o espaço em branco principal

# sed -i 's/^ *//' /etc/cron.hourly/shebang-test
#
# cat /etc/cron.hourly/shebang-test
#!/bin/bash
echo "Hello from $0" >> /tmp/cron.out

é executado com sucesso

# run-parts --report /etc/cron.hourly
# cat /tmp/cron.out
Hello from /etc/cron.hourly/shebang-test
#
    
por steeldriver 25.10.2017 / 18:05
0

O cron o executa como root? Certifique-se de que isso acontece.

Logo após o formato da hora no seu crontab, você pode adicionar o usuário.

Por exemplo, yourscript será executado como root às 6h todos os dias se você adicionar isso ao crontab:

0 6 * * * root /pathtoscript/yourscript

    
por Academiphile 25.10.2017 / 16:08