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
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
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
2. Shell Programming and Scripting
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
3. UNIX for Dummies Questions & Answers
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
4. UNIX for Dummies Questions & Answers
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
5. HP-UX
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
6. Shell Programming and Scripting
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
7. Shell Programming and Scripting
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
8. Shell Programming and Scripting
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
9. AIX
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
10. UNIX for Beginners Questions & Answers
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
LEARN ABOUT CENTOS
drop_owned
DROP
OWNED(7) PostgreSQL 9.2.7 Documentation DROP OWNED(7)
NAME
DROP_OWNED - remove database objects owned by a database role
SYNOPSIS
DROP OWNED BY name [, ...] [ CASCADE | RESTRICT ]
DESCRIPTION
DROP OWNED drops all the objects within the current database that are owned by one of the specified roles. Any privileges granted to the
given roles on objects in the current database and on shared objects (databases, tablespaces) will also be revoked.
PARAMETERS
name
The name of a role whose objects will be dropped, and whose privileges will be revoked.
CASCADE
Automatically drop objects that depend on the affected objects.
RESTRICT
Refuse to drop the objects owned by a role if any other database objects depend on one of the affected objects. This is the default.
NOTES
DROP OWNED is often used to prepare for the removal of one or more roles. Because DROP OWNED only affects the objects in the current
database, it is usually necessary to execute this command in each database that contains objects owned by a role that is to be removed.
Using the CASCADE option might make the command recurse to objects owned by other users.
The REASSIGN OWNED (REASSIGN_OWNED(7)) command is an alternative that reassigns the ownership of all the database objects owned by one or
more roles.
Databases and tablespaces owned by the role(s) will not be removed.
COMPATIBILITY
The DROP OWNED statement is a PostgreSQL extension.
SEE ALSO
REASSIGN OWNED (REASSIGN_OWNED(7)), DROP ROLE (DROP_ROLE(7))
PostgreSQL 9.2.7 2014-02-17 DROP OWNED(7)