Cronjob problem

I've been trying for hours to get a cronjob to work but I still run into problems and i'm getting a bit frustated. Maybe someone can help me.

I have put
Code:
* * * * * root /usr/scripts/load.cron.sh
in /etc/crontab

Now I get emails every minute with the following:
Code:
/usr/scripts/load.cron.sh: Permission denied
So I thought I should change permissions to get it working. I change permission ls -l gives
Code:
-rwxr--r--  1 root  wheel   518 Oct 15 08:06 load.cron.sh*

Now I get emails
Code:
/usr/scripts/load.cron.sh: not found

I'm a newbee, i've been trying but this is just to much :(

Thanks
 
Make sure the first line of load.cron.sh is
Code:
#!/bin/sh
If that is not your problem, show us what load.cron.sh looks like
 
Don't use /etc/crontab for this. Only system related stuff is supposed to be in there.

If you want to add your own things use # crontab -e
(Note that you don't need to add the username then)
 
@SirDice: I changed it back to what you advices

@jalla: I changed /bin/bash to /bin/sh and now it seems to be working.

The cronjob output is still wrong but I think that's another problem so i'm going to try to figure that out for myself.

Code:
#!/bin/sh
max_loadavge=1.0

loadavg=$(uptime | awk '{gsub(",",""); print $11}')

#echo "Load Average:$loadavg on `date`" >> /var/log/load.log

SUBJECT="`hostname` LOAD AVERAGE ALERT $loadavg(>$max_loadavge)"

EMAIL1="email@me.me"

ETEXT1="Load Average:$loadavg on `date`\n\n"
ETEXT2="USER     PID %CPU %MEM   VSZ   RSS  TT  STAT STARTED      TIME COMMAND\n"

echo -e "$ETEXT1$ETEXT2"

if [ $(echo "$max_loadavge < $loadavg"|bc) -eq 1 ]
then
echo -e "$ETEXT1$ETEXT2" | mail -s "$SUBJECT" "$EMAIL1"

fi

exit
 
Oke,

It script is working, I get a script email when load is over 1. But now the cronjob keeps sending me emails every minute.
 
If a cronjob produces output it will be emailed. So if you don't want to receive those emails make sure the script doesn't produce any output.
 
Sirdice,
I think I'm not really clear, excuse me.
I get emails every minute with the subject
Code:
Cron <root@admin> /usr/scripts/load.cron.sh
when the load is higher > 1, I get:
Code:
xxxx.yyyy.nl LOAD AVERAGE ALERT 2.01(>1.0)

I don't need the first messages.
 
I don't think you understood me.

If a cronjob produces output that output will get mailed.
It has nothing to do with the mail functionality inside your script.
 
  • Thanks
Reactions: bdj
Sirdice, I think I get the point now, if I run it by hand the script produces an output even though the load is below 1. I think I have a script error.
 
Back
Top