0

i am getting following email every 10 min. as I own the VPS. I am not expert in linux and am learning to manage linux servers. Please help me why am i getting these emails and how to stop them or how to fix the issue i am running CentOS 6 on 123-reg VPS

Subject: Cron /usr/lib64/sa/sa1 1 1 /usr/lib64/sa/sa1: line 11: /bin/date: cannot execute binary file /usr/lib64/sa/sa1: line 13: /bin/date: cannot execute binary file

and below email every 1 hour Subject: Cron run-parts /etc/cron.hourly /etc/cron.hourly/0anacron:

/etc/cron.hourly/0anacron: line 6: /bin/date: cannot execute binary file
/etc/cron.hourly/0anacron: line 6: [: =: unary operator expected

in 0anacron its:

#!/bin/bash
# Skip excecution unless the date has changed from the previous run 
if test -r /var/spool/anacron/cron.daily; then
    day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
    exit 0;
fi

# Skip excecution unless AC powered
if test -x /usr/bin/on_ac_power; then
    /usr/bin/on_ac_power &> /dev/null
    if test $? -eq 1; then
    exit 0
    fi
fi
/usr/sbin/anacron -s
6
  • Please edit your question and include the cotents of your 0anacron file
    – DavidPostill
    Commented Mar 18, 2015 at 13:19
  • Sorry for that i have just added it , thanks David Commented Mar 18, 2015 at 13:31
  • 1
    Did you check: /bin/date and ls -l /bin/date ?
    – dan
    Commented Mar 18, 2015 at 13:57
  • it gives me -rwxr-xr-x. 1 root root 41365188 Mar 17 16:29 /bin/date if i do ls -l /bin/date Commented Mar 18, 2015 at 14:20
  • As the same user as the CRON job, at a command line, please post the out of 'which date' and 'file which date' preserve the back-tick quotations. The cron job is probably running as root - check this with 'crontab -l' as root and you should see the appropriate commands listed.
    – Daniel
    Commented Mar 18, 2015 at 15:27

1 Answer 1

1

0anacron error:


This is the correct code:

#!/bin/bash

# Skip excecution unless the date has changed from the previous run 
if test -r /var/spool/anacron/cron.daily; then
    day="$(cat /var/spool/anacron/cron.daily)"
fi
if [ "$(date +%Y%m%d)" == "$day" ]; then
    exit 0
fi

# Skip excecution unless AC powered
if test -x /usr/bin/on_ac_power; then
    /usr/bin/on_ac_power &> /dev/null
    if test $? -eq 1; then
        exit 0
    fi
fi
/usr/sbin/anacron -s

This fixes the [: =: unary operator expected problem. Here you're a list of fails corrected on the code sorted by relevance, the first is the worst:

  • In bash conditional you missed a equal sign. Is == instead of =.
  • ` (backtick) Is deprecated, use $(command) instead of `command`
  • You ended the 8th line with a semicolon when there isn't need to do that.
  • Indent your code 2 or 4 spaces uniformly.

date error:


Your /bin/date binary seems to be corrupted, did you see that link?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .