Cannot get CRON to run script

Status
Not open for further replies.

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,972
I've been messing with this all day and searching the internet for help but I have tried many things, nothing has helped.

I'm trying to execute the following script which works fine running under SU in SSH. Might I add, I believe I need to use SU/root for the smartctl command.

In CRON I had set it up like this:
User: root
command: sh /mnt/farm/email/esmart.sh /dev/ada0

Even forcing the /dev/ada0 in the script and removing it from the command line gives no joy.

I currently am using a location on the pool vice on /tmp or somewhere else which is my final goal so I don't have to spin up the drives just to run this command.

Code:
#!/bin/sh
#
# Script to email Drive Results
# Usage:  esmart.sh drive path
# Example: sh esmart.sh /dev/ada0

switch1=$1

(
echo "To: joe@email.net"
echo "Subject: SMART Drive Results for ${switch1}"
echo " "
) > /mnt/farm/email/cover
smartctl -i -H -A -l error ${switch1} >> /mnt/farm/email/cover
sendmail -t < /mnt/farm/email/cover


I have simplified this drastically in many ways, used explicit paths, and I'm now to the point of having to ask for assistance. There must be something obvious I'm overlooking which is why I hate to ask a stupid question.

EDIT: I think my problems are in the redirects. It's driving me nuts.

Thanks,
Mark
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,972
Fixed but don't know why

I've fixed it but I really don't know why it works now. I ended up reducing my script down to individual lines and once I got them working I started to build them together. Eventually it all works. Here is the end result. And you would think the #!/usr/local/bin/sh was the only real difference but I had tried that earlier today well before I posted asking for help but it's didn't seem to help. I am currently running it as root.

Code:
#!/usr/local/bin/sh
#
switch1=$1
(
echo "To: joe@email.net"
echo "Subject: SMART Drive Results for ${switch1}"
echo " "
) > /mnt/farm/email/cover
smartctl -i -H -A -l error ${switch1} >> /mnt/farm/email/cover
sendmail -t < /mnt/farm/email/cover


Now if I could get the formatting of the text columns in the email to line up properly then I'd be almost set.
 

RichR

Explorer
Joined
Oct 20, 2011
Messages
77
ummmm,,,

Check to see if there actually is a /usr/local/bin/sh (in mine there isn't)

try /bin/sh or /bin/bash

Also, interesting way to get mail - I do mine in a totally different manor (from the cron file itself) since it's not root, I have a gui cron load my cron file vi a crontab script:

#! /bin/bash

# set -x

echo "Checking for a cron"
if [ -f ~/scripts/pacs.cron ] ; then
logger -t "pacs" "Removing old, and loading the new crontab"
crontab ~pacs/scripts/pacs.cron
fi

logger -t "pacs" "Done"
echo "Done"



Part of the pacs.cron file:
45 0 * * * ~/scripts/somescript.sh | /usr/bin/mail -s "Some Account Sync" rich@mydomain.com

Let me know....

Rich
 
Status
Not open for further replies.
Top