Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a script that I wrote to verify on an OS X machine (v 10.7.4) if a volume is up or down. If it goes down, it is supposed to send an email. When I run the script from the command line, it works perfectly and shows me my control volume (DGS_Ima_ASDF_ges_MTL) as being down in the email I receive. However, if I schedule the script in the crontab, it says all my volumes are down, including my control volume, in the email that I receive. Can someone maybe tell me how to fix this. This is my script:


array=("Chatelaine" "DGS_Ima_ASDF_ges_MTL" "FMC_MTL" "GF_MTL" "Holding_Tank_MTL" "LACM_MTL" "LAP_MTL" "actualite" "Loulou" "Loulou_Web" "MQC_MTL" "PS_MTL" "QP_MTL" "Visuels_MTL")


for counter in ${!array[*]}
   mount | grep ${array[counter]}
   if [ $? -ne 0 ]; then
       echo "${array[counter]}" >> $SAVE_TO

ls ~/Documents | grep drives_not_mounted
if [ $? -eq 0 ]; then
    mailx -s "Mounted volumes are down" "$EMAIL_ADDRESSES" < $SAVE_TO

share|improve this question

closed as off-topic by ceejayoz, Sven, mdpc, Dennis Williamson, Ward Aug 10 '13 at 2:43

  • This question does not appear to be about server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

(Qeuestion) Title =! Job title. –  Sven Aug 9 '13 at 15:31
What user are you running the cron job as? Also, relative paths are always a bad idea in scripts. –  cduffin Aug 9 '13 at 15:33
The user running the cron job is the same one I use when testing from the command line. It is also the same user I use for running a similar script that checks if a process has dropped. This script has no problems. The script that works, has the same relative paths. –  zdarma Aug 9 '13 at 16:13
One difference when running as a crontab is that you don't source /etc/profile. Have you tried . /etc/profile at the top of your script or when calling the cron job? Does that change result for you? –  Petter H Aug 9 '13 at 16:38
Adding the PATH=.... as suggested by minniux fixed the problem. –  zdarma Aug 9 '13 at 17:21

1 Answer 1

up vote 2 down vote accepted

First, add the following PATH line to your crontab file:


Second, configure cron to log the output of the script to a log file so you can further troubleshoot it, by adding the following next to the cron job line itself:

 &> /path/to/log.txt
share|improve this answer
After looking at the output of the script in a log file, I saw that crontab did not recognize the command "mount". I added the PATH to my crontab and all is good. Thanks. I'd give you an UP on that, but my reputation isn't high enough. Thanks again. –  zdarma Aug 9 '13 at 16:40
grep CRON /var/log/syslog since failed cron jobs will already make a log, there is no point in making a separate log file. –  j0h Aug 9 '13 at 19:32
not in all systems, and not always detailed enough :) –  minniux Aug 18 '13 at 14:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.