Script works fine but not with crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script works fine but not with crontab
# 1  
Old 02-18-2011
Script works fine but not with crontab

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:
Code:
0 7 * * 1-5 /home/jtaylor/needed_scripts/disk_space_alarm >> /dev/null 2>&1

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.
Code:
#!/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


Last edited by Scott; 02-18-2011 at 04:02 PM.. Reason: Please use code tags
# 2  
Old 02-18-2011
This question is so common it's in our FAQ.

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
# 3  
Old 02-18-2011
run this in crontab :

Code:
0 17 * * 1-5 env >/tmp/myenv

then post the result of the command

Code:
cat /tmp/myenv

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
Code:
source /etc/profile

instead of
Code:
. /etc/profile

# 4  
Old 02-18-2011
What Operating System and version do you have?

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.

Quote:
0 7 * * 1-5 /home/jtaylor/needed_scripts/disk_space_alarm >> /dev/null 2>&1
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:
Quote:
/home/jtaylor/needed_scripts/vobstorage_list

Quick fix guess. If this is Solaris, specify the full path for "nawk".
# 5  
Old 02-18-2011
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:
Code:
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.

Last edited by Scott; 02-18-2011 at 04:03 PM.. Reason: Please use code tags
# 6  
Old 02-18-2011
just use full path when using commands in your scripts :

Code:
/usr/bin/cat 
/usr/bin/grep
/usr/bin/awk
/usr/bin/mailx 
....

or wherever they are of course.
# 7  
Old 02-18-2011
@jacktay

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.
Code:
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 ?
Quote:
cd $i
Though I don't often read "csh", this looks like a character compare not a numeric compare:
Quote:
if ( "$CAPACITY" > "$MAXCAP" ) then
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

2. Shell Programming and Scripting

sed command not working inside ksh script but works fine outside

Hi, I am a bit confused ,why would a sed command work fine outside of ksh script but not inside. e.g I want to replace all the characters which end with a value and have space at end of it. so my command for it is : sed -i "s/$SEPARATOR /$SEPARATOR/g" file_name This is working fine in... (8 Replies)
Discussion started by: vital_parsley
8 Replies

3. UNIX for Dummies Questions & Answers

C-program works fine interactively, but not on the SGE server

Greetings, I have a C-program that is made to implement a hidden Markov model on an input file. The program is very memory intensive. I've installed it on my local server where I have an account and it compiles fine. The way they have the server set up is that you can either work... (1 Reply)
Discussion started by: Twinklefingers
1 Replies

4. Shell Programming and Scripting

Part of the Shell script is not running via crontab, runs fine manually

Hello Team, As a part of my job we have made a script to automate a service to restart frequently. Script having two functions when executing it's should find the existing service and kill it, then start the same service . Verified the script it's working fine when executing... (18 Replies)
Discussion started by: gowthamakanthan
18 Replies

5. Shell Programming and Scripting

Script runs fine manually but not in crontab

Hello Guys, I have scratched my head alot on this but couldn't find clue what's wrong. Can you please help me with this? My problem is as following. 1) When I manually execute following script it runs successfully with below output. bash-3.00# more smssend #!/bin/bash echo -e "<Request... (16 Replies)
Discussion started by: umarsatti
16 Replies

6. Shell Programming and Scripting

Not the correct output, works fine via CLI, not inside the script.

Guys, I need you help please. The script below is not working correclty for checking via a awk/if statement . Can you tell me what i am doing wrong in the script code "if($1 == "$RETENTION_LEVEL") " Syntax RETENTION_LEVEL=`echo $LINE | cut -f2 -d" "` echo " ==============... (4 Replies)
Discussion started by: Junes
4 Replies

7. Shell Programming and Scripting

Sed script not working properly on Solaris (works fine on AIX)?

Hi, I have a problem with a SED script that works fine on AIX but does not work properly on a Solaris system. The ksh script executes the SED and puts the output in HTML in tables. But the layout of the output in HTML is not shown correctly(no tables, no color). Can anyone tell if there is... (7 Replies)
Discussion started by: Faith111
7 Replies

8. Shell Programming and Scripting

Cron job fails, but works fine from command line

I have a very basic script that essentially sends a log file, via FTP, to a backup server. My cron entry to run this every night is: 55 23 * * * /usr/bin/archive_logs The script runs perfectly when executed manually, and actually worked via cron for about three weeks. However, it mysteriously... (3 Replies)
Discussion started by: cdunavent
3 Replies

9. UNIX for Dummies Questions & Answers

Crontab works but does not execute script

Hi guys, my first post time here, so hello to everyone :) I've got a problem running one of my scripts at work. I can get crontab working on simple scripts (i.e. one that just outputs date to a temp file). but it won't correctly execute the script i want to use. My script is a PHP script. It... (6 Replies)
Discussion started by: renegadeice
6 Replies

10. Shell Programming and Scripting

Script works fine until I | more

Hello all, This beats me. I have a script that executes some commands and redirects their output to some text files that I will parse. The commands are along the lines of: dsmadmc -id=admin -pa=admin -outfile=/home/tools/qlog.txt q log f=d If I just run the script it works. If I execute... (2 Replies)
Discussion started by: Skovian
2 Replies
Login or Register to Ask a Question