tablespace monitoring script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting tablespace monitoring script
# 1  
Old 01-26-2011
tablespace monitoring script

I have prepared the below script to monitor the tablespace and alert the users whenever it reaches a threshold limit.

Code:
#!/bin/sh
. /home/.profile

sqlplus -s $LOGON << .eof > $scripts/check_tablespace.temp
set pages 0
select tablespace_name, free_percent
from (
            SELECT b.tablespace_name, b.tablespace_size_mb, sum(nvl(fs.bytes,0))/1024/1024 free_size_mb,
            (sum(nvl(fs.bytes,0))/1024/1024/b.tablespace_size_mb *100) free_percent
            FROM dba_free_space fs,
                 (SELECT tablespace_name, sum(bytes)/1024/1024 tablespace_size_mb FROM dba_data_files
                  GROUP BY tablespace_name
                 ) b
           where
           fs.tablespace_name like 'INFA_%'
           and
           fs.tablespace_name = b.tablespace_name
           group by b.tablespace_name, b.tablespace_size_mb
        ) ts_free_percent
WHERE free_percent < 60
ORDER BY free_percent;
exit
eof

cd $scripts
chmod ugo+rw check_tablespace.temp
counter=`cat check_tablespace.temp | sed '/^$/d'| wc -l`
echo "count="$counter
if [ $counter -gt 0 ] then
   cat check_tablespace.temp | mailx -s 'Alert: Free tablespace alert' $alertlist
fi
rm check_tablespace.temp

But when I execute the script, it fails with following error.

Code:
cat: cannot open check_tablespace.temp

Script creates check_tablespace.temp and when I execute the cat command from commandline, it works fine.

Code:
cat check_tablespace.temp
INFA_TS                        45.575

Also i tried to change the permissions assuming that it is a permission problem, but still it fails with the same error.

Sam
# 2  
Old 01-26-2011
Hi.

What is the value of "scripts"?

If it's not set, the file will go into the root directory, and the cd will go to your home directory.

i.e
Code:
$scripts/check_tablespace.temp

becomes
Code:
/check_tablespace.temp

and
Code:
cd $scripts

becomes
Code:
cd

# 3  
Old 01-26-2011
Quote:
Originally Posted by scottn
Hi.

What is the value of "scripts"?

If it's not set, the file will go into the root directory, and the cd will go to your home directory.

i.e
Code:
$scripts/check_tablespace.temp

becomes
Code:
/check_tablespace.temp

and
Code:
cd $scripts

becomes
Code:
cd

Thanks for the reply. The value of $scripts is set at .profile which i am sourcing it during the initial part of the script

Code:
. /home/.profile

# 4  
Old 01-26-2011
What is the dot here? The closing one should be the same, no?

Code:
sqlplus -s $LOGON << .eof > ...
...
.eof

# 5  
Old 01-26-2011
Yes thats a good catch. I removed the dot (.eof) from eof and added ';' in the if statement. It worked.

Thanks much

Sam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Tablespace growth trend

Hi experts, I have the below details with me.How to calculate the tablespace growth between two dates. sample data(have data upto 1 year): INSTANCE_NAME DATE TABLESPACE_NAME MB_ALLOC MB_FREE MB_USED PCT_FREE PCT_USED MAX ---------------- ---------... (1 Reply)
Discussion started by: navsan420
1 Replies

2. Shell Programming and Scripting

Error in Scripting to monitor tablespace in Oracle DB

Buddies, I am writing the below script 'tab.sh' to monitor the tablespaces in Database:- ------------------------------- export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2 export PATH=$PATH:$ORACLE_HOME/bin export ORACLE_SID=orcl sqlplus system/oracle as sysdba <<EOF spool... (5 Replies)
Discussion started by: sandip250382
5 Replies

3. Shell Programming and Scripting

Help with a monitoring script

I currently have a shellscript to check the size of a filesystem and email me if the size is over a certain percentage (80%). I have this script on crontab and executes the shell every 10 mins. I have the above in place on 8 servers. It so happens that a file system on one of the servers is... (1 Reply)
Discussion started by: goddevil
1 Replies

4. UNIX for Advanced & Expert Users

ldapsearch in monitoring script without bind password written in script

Hi I do a very simple monitoring of our OpenLDAP (runs in cronjob and generate alerts if unsuccessfull) $ ldapsearch -h hostname.domain -D "cn=monitor_user,ou=People,dc=organisation" -w "password" -b "dc=organisation" -x "(&(cn=monitor_user)(ou=People))" dn | grep -v version dn:... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

5. Shell Programming and Scripting

Script to check Oracle tablespace

I'm new to unix script, and I need to check the tablespaces daily, here is the script(quite simple), but it does not work. Did I missed something ? Please guide me, Many thanks ! #!/bin/sh echo "ORA TABLEASPACE:" sqlplus system/oracle as sysdba; set pagesize 9999; set linesize 132; ... (5 Replies)
Discussion started by: dehetoxic
5 Replies

6. Shell Programming and Scripting

alias to a shell script - tablespace size

I have developed the following shell script. The idea was to create an alias to execute it and return the tablespaces and their sizes from an oracle database. When I execute is via the alias, I have issues. So, here is the script first: > cat ts_size.sh #!/bin/ksh xwhere=" " xwild=" "... (8 Replies)
Discussion started by: desibabu
8 Replies

7. Shell Programming and Scripting

Monitoring script

Hi, I want to write script that monitors particular ports in a server. I completed the script but.... If the server is restarted i need manually start the script.. Is there any way i can make the script start by it self after the server reboot........ Thanks, Firestar (4 Replies)
Discussion started by: firestar
4 Replies

8. Shell Programming and Scripting

error in script path for tablespace usage

Hi , I am trying to run this script in crontab but I get errors. When I run it explicitly like ./monitor_tblsp from another location then it runs fine . I am messing somewhere with paths but I don't know where and how . Please help . Here is the error part ./monitor_tblsp: touch: not... (2 Replies)
Discussion started by: capri_drm
2 Replies

9. Shell Programming and Scripting

Need help in a shell script to edit a tablespace creation script.

Hi, CREATE TABLESPACE aps_blob_large01 DATAFILE '/c2r6u13/u03/oradata/qnoldv01/aps_blob_large0101.dbf' SIZE X 270532608 REUSE DEFAULT STORAGE (INITIAL 134217728 NEXT... (2 Replies)
Discussion started by: rparavastu
2 Replies

10. Shell Programming and Scripting

Shell Script to find the tablespace size in oracle.

Hi, I need to execute a script to find the tablespace size in oracle.But i get an error.:confused: Script Executed:- #!/bin/ksh ORACLE_SID= oracelinstance ORACLE_HOME= oracle path PATH=$ORACLE_HOME/bin export ORACLE_SID ORACLE_HOME PATH sqlplus... (4 Replies)
Discussion started by: vighna
4 Replies
Login or Register to Ask a Question