Sponsored Content
Top Forums Shell Programming and Scripting Script doesn't work as expected when run on cron Post 302235546 by RoshniMehta on Friday 12th of September 2008 06:19:24 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
OID2NAME(1)						  PostgreSQL 9.2.7 Documentation					       OID2NAME(1)

NAME
oid2name - resolve OIDs and file nodes in a PostgreSQL data directory SYNOPSIS
oid2name [option...] DESCRIPTION
oid2name is a utility program that helps administrators to examine the file structure used by PostgreSQL. To make use of it, you need to be familiar with the database file structure, which is described in Chapter 56, Database Physical Storage, in the documentation. Note The name "oid2name" is historical, and is actually rather misleading, since most of the time when you use it, you will really be concerned with tables' filenode numbers (which are the file names visible in the database directories). Be sure you understand the difference between table OIDs and table filenodes! oid2name connects to a target database and extracts OID, filenode, and/or table name information. You can also have it show database OIDs or tablespace OIDs. OPTIONS
oid2name accepts the following command-line arguments: -f filenode show info for table with filenode filenode -i include indexes and sequences in the listing -o oid show info for table with OID oid -q omit headers (useful for scripting) -s show tablespace OIDs -S include system objects (those in information_schema, pg_toast and pg_catalog schemas) -t tablename_pattern show info for table(s) matching tablename_pattern -V, --version Print the oid2name version and exit. -x display more information about each object shown: tablespace name, schema name, and OID -?, --help Show help about oid2name command line arguments, and exit. oid2name also accepts the following command-line arguments for connection parameters: -d database database to connect to -H host database server's host -p port database server's port -U username user name to connect as -P password password (deprecated -- putting this on the command line is a security hazard) To display specific tables, select which tables to show by using -o, -f and/or -t. -o takes an OID, -f takes a filenode, and -t takes a table name (actually, it's a LIKE pattern, so you can use things like foo%). You can use as many of these options as you like, and the listing will include all objects matched by any of the options. But note that these options can only show objects in the database given by -d. If you don't give any of -o, -f or -t, but do give -d, it will list all tables in the database named by -d. In this mode, the -S and -i options control what gets listed. If you don't give -d either, it will show a listing of database OIDs. Alternatively you can give -s to get a tablespace listing. NOTES
oid2name requires a running database server with non-corrupt system catalogs. It is therefore of only limited use for recovering from catastrophic database corruption situations. EXAMPLES
$ # what's in this database server, anyway? $ oid2name All databases: Oid Database Name Tablespace ---------------------------------- 17228 alvherre pg_default 17255 regression pg_default 17227 template0 pg_default 1 template1 pg_default $ oid2name -s All tablespaces: Oid Tablespace Name ------------------------- 1663 pg_default 1664 pg_global 155151 fastdisk 155152 bigdisk $ # OK, let's look into database alvherre $ cd $PGDATA/base/17228 $ # get top 10 db objects in the default tablespace, ordered by size $ ls -lS * | head -10 -rw------- 1 alvherre alvherre 136536064 sep 14 09:51 155173 -rw------- 1 alvherre alvherre 17965056 sep 14 09:51 1155291 -rw------- 1 alvherre alvherre 1204224 sep 14 09:51 16717 -rw------- 1 alvherre alvherre 581632 sep 6 17:51 1255 -rw------- 1 alvherre alvherre 237568 sep 14 09:50 16674 -rw------- 1 alvherre alvherre 212992 sep 14 09:51 1249 -rw------- 1 alvherre alvherre 204800 sep 14 09:51 16684 -rw------- 1 alvherre alvherre 196608 sep 14 09:50 16700 -rw------- 1 alvherre alvherre 163840 sep 14 09:50 16699 -rw------- 1 alvherre alvherre 122880 sep 6 17:51 16751 $ # I wonder what file 155173 is ... $ oid2name -d alvherre -f 155173 From database "alvherre": Filenode Table Name ---------------------- 155173 accounts $ # you can ask for more than one object $ oid2name -d alvherre -f 155173 -f 1155291 From database "alvherre": Filenode Table Name ------------------------- 155173 accounts 1155291 accounts_pkey $ # you can mix the options, and get more details with -x $ oid2name -d alvherre -t accounts -f 1155291 -x From database "alvherre": Filenode Table Name Oid Schema Tablespace ------------------------------------------------------ 155173 accounts 155173 public pg_default 1155291 accounts_pkey 1155291 public pg_default $ # show disk space for every db object $ du [0-9]* | > while read SIZE FILENODE > do > echo "$SIZE `oid2name -q -d alvherre -i -f $FILENODE`" > done 16 1155287 branches_pkey 16 1155289 tellers_pkey 17561 1155291 accounts_pkey ... $ # same, but sort by size $ du [0-9]* | sort -rn | while read SIZE FN > do > echo "$SIZE `oid2name -q -d alvherre -f $FN`" > done 133466 155173 accounts 17561 1155291 accounts_pkey 1177 16717 pg_proc_proname_args_nsp_index ... $ # If you want to see what's in tablespaces, use the pg_tblspc directory $ cd $PGDATA/pg_tblspc $ oid2name -s All tablespaces: Oid Tablespace Name ------------------------- 1663 pg_default 1664 pg_global 155151 fastdisk 155152 bigdisk $ # what databases have objects in tablespace "fastdisk"? $ ls -d 155151/* 155151/17228/ 155151/PG_VERSION $ # Oh, what was database 17228 again? $ oid2name All databases: Oid Database Name Tablespace ---------------------------------- 17228 alvherre pg_default 17255 regression pg_default 17227 template0 pg_default 1 template1 pg_default $ # Let's see what objects does this database have in the tablespace. $ cd 155151/17228 $ ls -l total 0 -rw------- 1 postgres postgres 0 sep 13 23:20 155156 $ # OK, this is a pretty small table ... but which one is it? $ oid2name -d alvherre -f 155156 From database "alvherre": Filenode Table Name ---------------------- 155156 foo AUTHOR
B. Palmer <bpalmer@crimelabs.net> PostgreSQL 9.2.7 2014-02-17 OID2NAME(1)
All times are GMT -4. The time now is 09:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy