Hello All,
This is driving me nuts. Wrote a very simple script (it's in csh so sorry about that). Just something very simple though. Here is the catch. Works great from command line sometimes. Other times it runs no errors or anything but I never receive an email. Never runs from crontab either (meaning I never get an email). Just as a side note I definitely have one filesystem that is at 87 percent so it should flag that one everytime. Here's the crontab entry for it:
Here is the actual script. If someone can please tell me what this thing will not run consistently, I would be greatly appreciative . Just as an fyi. I orginal had this is ksh and had the same problem which is why i went back to csh.
#!/bin/csh -f
set MAXCAP=( 85 )
foreach i ( `cat /home/jtaylor/needed_scripts/vobstorage_list` )
set CAPACITY=( `df -k $i | grep -v avail | nawk '{print $5}' | nawk -F% '{print $1}'` )
cd $i
if ( "$CAPACITY" > "$MAXCAP" ) then
mailx -s "$i Exceeded $MAXCAP% and is at $CAPACITY%" `cat /home/jtaylor/needed_scripts/list` << FINISH
Runs daily at 7am
Located in /home/jtaylor/needed_scripts/disk_space_alarm
crontab:jtaylor
$i is at $CAPACITY% capacity. (Threshold is $MAXCAP%)
FINISH
endif
end
Your script probably uses commands that aren't in cron's PATH. It gives a much more minimal PATH than you get as a user. either set a sane PATH with export PATH="..." or, as the first line of your script, import a more complete profile with . /etc/profile
This is to check that your environment is sufficient (example, if the PATH variable has disappeared, then you should specify the full path for the command you use)
note that if you want to load the (suggested by Corona) environment file in csh , you should use
What does the output from "df -k myfilesystem" look like on your system? (there is much variation).
Can we see the "ksh" version? There is no place for "csh" in system scripts.
Suggest you remove the redirection of the output from the script for a one-off test and look in mail for the owner of the cron for any output messages or error messages.
Also, what's in this file:
Quick fix guess. If this is Solaris, specify the full path for "nawk".
Thanks for all the input folks. Just doesn't make any sense at all. I have a ton of other scripts running with no problem which are a lot more complicated than this one. They are on contrab as well and running without any issues. For the life of me I just can't figure this out at all. Makes no sense. Here is the output from the df command:
Filesystem kbytes used avail capacity Mounted on
gbplemcdm01:/clearcase-vbs/gbcvasvob01/02
524288000 66880064 457407936 13% /net/gbplemcdm01/clearcase-vbs/gbcvasvob01/02
and here is the out put from the entire df command i was aliasing:
13
---------- Post updated at 03:21 PM ---------- Previous update was at 02:53 PM ----------
Wow..I finally got it. It was the space between FINISH and endif that was making it behave erratically for some reason.. Still no idea why but hey it's working now. Thanks for all the input.
Still strongly advise that you stop redirecting all output to /dev/null. If the script works it will produce no output. If if produces error messages, the error messages will be found in unix mail for the owner of the cron. The environment for cron is quite limited.
If that does not solve the problem, please post the output from the following commands after blotting anything confidential like email addresses with X's.
The "sed" command is designed to make end-of line characters visible.
df -k /net/gbplemcdm01/clearcase-vbs/gbcvasvob01/02 | sed -n l
cat /home/jtaylor/needed_scripts/vobstorage_list | sed -n l
cat /home/jtaylor/needed_scripts/list | sed -n l
Is this command valid for every value of $i ?
Though I don't often read "csh", this looks like a character compare not a numeric compare: