Script doesn't work as expected when run on cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script doesn't work as expected when run on cron
# 1  
Old 09-12-2008
Script doesn't work as expected when run on cron

The script checks for free space stats on Oracle. If there are any tablespaces with more than 85% usage it prints the details of the tablespace. If all the tablespaces have more than 15% free space, then "All tablespaces have more than 15 pct free space" must be printed on the screen.

When I run on the shell with ./scriptname it runs as described above. When I run it as a cron job, I do not get the message "All tablespaces have more than 15 pct free space"when all tablespaces have more than 15% free space.

I am pasting a part of the script:

# call Oracle script to query tablespace size
`sqlplus -S "/as sysdba" @/home/sidadm/script/dba_data_files.sql > .tmp1`
# call Oracle script to query freespace in tablespace
`sqlplus -S "/as sysdba" @/home/sidadm/script/dba_free_space.sql > .tmp2`
# paste them into a single file
paste .tmp1 .tmp2 |tail +4 > .tmp

# get the number of tablespaces
TS_CT=`cat .tmp | wc -l`

awk -v m=0 -v n=0 -v i="$TS_CT" '
{
# calculate freespace percentage
k =$3/$2*100;
# print the details if the percentage of freespace is less than 15
if($3/$2*100 < 15)
{
m = m + 1; # m keeps a count of number of tablespaces with freespace percentage less than 15
if(m==1) # print the heading (only once)
{
printf("%s \n","Tablespaces having less than 15pct freespace GB")
printf("%s \n","Tablespace Totalspace Freespace Freespace_pct")
}
len =length ($1)
printf("%s",$1)
for ( ;len < 30 ;len++)
{
printf("%c"," ");
}
len=length($2)
printf("%s",$2)
for ( ;len < 15 ;len++)
{
printf("%c"," ");
}
len = length($3);
printf("%s",$3)
for ( ;len < 15 ;len++)
{
printf("%c"," ");
}

printf("%f \n ",$3/$2*100);

}
else
{
n = n + 1; # n keeps a count of tablespaces with freespace percentage more than 15
if(n==i) # if all the tablespaces have free space more than 15 %
{
printf("%s \n","All tablespaces have more than 15 pct free space")
}
}

}

' .tmp >> $TOBREMAILED
# 2  
Old 09-12-2008
Make sure your environment is the same by sourcing your .profile (wherever your needed variables are set in) etc. when starting it via cron, like
Code:
. ~/.profile

# here comes the script...

If you are still having problems, put a "set -x" in the beginning and check the verbose output of your cronjob.

Also use [ code ] and [ /code ] tags when displaying scripts in the forum please, thank you.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 09-12-2008
Either you can

- source the .profile before calling the script
eg: * * * * * ./.profile; sh script.sh

- or, call the .profile inside your script.
These 2 Users Gave Thanks to dennis.jacob For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script does not work as expected

Repeat this text in a file named notes.txt and run the script Before bash is a good language a blank line appears Also, the following notes are displayed incorrectly What is bad? ================================== Title : Note 1 ================================== Category: Computer Date... (3 Replies)
Discussion started by: cesar60
3 Replies

2. AIX

Script is not executing as expected when I schedule it in cron

Hi, I have a shell script which fetches the MRP status and the LAG status. When I execute it manually like, sh <script_name>, it fetches the output as expected, but when I schedule through crontab, it's not working as expected. Any help would be really appreciated. Here is the code... (3 Replies)
Discussion started by: Nagaraj R
3 Replies

3. Shell Programming and Scripting

Cron doesn't run job in background

Hi, First of all merry christmas and Happy holidays to all :D My situation is as below, When a backup job runs on a mainframe server, it creates a 0byte file on a network drive which is accessible through linux Linux server : Red Hat Enterprise Linux Server release 5.3 Beta (Tikanga) File... (6 Replies)
Discussion started by: sam05121988
6 Replies

4. Shell Programming and Scripting

my script doesn't work :(

i have this script and when i ejecute it, the console tell me this " sintax error line 41 unexpected element "}" " is the sintaxis ok? #!/bin/bash if ;then { exit 0; } if ; then { sudo /etc/init.d/apache2 start; sudo /etc/init.d/mysql start; php5 & nautilus... (3 Replies)
Discussion started by: keiserx
3 Replies

5. Shell Programming and Scripting

Help with script.. it Just doesn't work

Hello,, Im verry new to scripting and have some problems with this script i made.. What it does: It checks a directory for a new directory and then issues a couple of commands. checks sfv - not doing right now checks rar - it checks if theres a rar file and when there is it skips to... (1 Reply)
Discussion started by: atmosroll
1 Replies

6. HP-UX

fsck doesn't work - not even run?

Hi, please consider, I'm pretty new to HP-UX, thanks. Our server (rp7420 with HP-UX 11.31) has crashed due to disk write error (not boot partition). So I replaced damaged device with the new one of the same size and performed dd copy 1:1 to restore data - vxfs partition "/dev/vg01/lvol1"... (4 Replies)
Discussion started by: Morhoo
4 Replies

7. UNIX for Dummies Questions & Answers

For some reason, my grep doesn't work as expected

I am trying to find only those entries where 7018 and another number appear in the end of the line. 7018 2828 1423 2351 7018 2828 14887 2828 7018 1222 123 7018 1487 I am looking for a way to generate only the last two lines. I was trying to do just "grep '7018{1,5}" but it does not... (5 Replies)
Discussion started by: Legend986
5 Replies

8. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

9. Shell Programming and Scripting

Command doesn't work under cron ?

I have defined in cron crontab -l >/FIXENGINE/data/crontab.$(whoami).$(date +%a) The resulting file is named crontab.fixadmin. When I run the above from a command line, the file is named: crontab.fixadmin.Tue (or whatever day I happen to be running) The question is - why do I get... (4 Replies)
Discussion started by: bigjohn-nj
4 Replies

10. UNIX for Dummies Questions & Answers

ncopy doesn't work from cron

Hello, I have put the following command in a shell script: ncopy /home/Selma/my_file server2\!INPUT/my_file userpassword (server2 is the remote machine) The script works fine when it is invoked manually, however when it is scheduled to be run from crontab ncopy doesn't work (all of the... (2 Replies)
Discussion started by: Selma
2 Replies
Login or Register to Ask a Question