alias to a shell script - tablespace size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting alias to a shell script - tablespace size
# 1  
Old 01-13-2011
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:
Code:
> cat ts_size.sh
 
#!/bin/ksh
xwhere=" "
xwild=" "
wild=" "
if [$# -eq 1]
then
  wild=$(`echo ${1} | awk '{print index($1,"%") }'`)
  # echo $wild
  if [${wild} != 0]
  then
    xwild="like"
  else
    xwild="="
  fi
  xwhere="where tablespace_name "${xwild}" upper('"${1}"')"
fi
echo $xwhere
sqlplus -s / <<eof &2>/dev/null
set linesize 120;
set pagesize 1000;
set feedback off;
set echo off;
col tablespace_name forma a30;
select round(sum(bytes/1024/1024/1024),2) as "Gb", tablespace_name from dba_data_files ${xwhere} group by rollup (tablespace_name) order by 1 asc;
<<eof

The alias defined is:
Code:
ts_size='. ~/util/sql/ts_size.sh'

When I execute the shell script via the alias: notice I get some ksh not found and a 14873 and my command prompt etc.. AND when the shell finishes, I don't get my prompt back...

Code:
> ts_size
ksh: [1: not found
[2] 14873
>
        Gb TABLESPACE_NAME
---------- ------------------------------
       .38 SYSTEM
        .5 SI
        .5 SD
       .68 TOOLS
       .98 USERS
      1.17 RCTI
      7.13 SYSAUX
     17.58 RDL
     19.53 RDS
     28.32 RDLS
     43.95 UNDOTBS
     73.24 RCT
     86.32 RDRT
    314.73 RIN
    348.13 RD
    625.34 RDLL

When I press enter then I get the following:
Code:
[2] + Done ts_size
>

and I get my prompt.

When I execute it directly as a shell script. I get the following:
Code:
 > ts_size.sh
ts_size.sh[5]: [0: not found
 >
        Gb TABLESPACE_NAME
---------- ------------------------------
       .38 SYSTEM
        .5 SI
        .5 SD
       .68 TOOLS
       .98 USERS
      1.17 RCTI
      7.13 SYSAUX
     17.58 RDL
     19.53 RDS
     28.32 RDLS
     43.95 UNDOTBS
     73.24 RCT
     86.32 RDRT
    314.73 RIN
    348.13 RD
    625.34 RDLL
   1568.48 
 
>

Here too, I don't get the prompt back. I have to press the enter key to get my prompt back.

Any idea what I need to do to fix all these?

Thanks

Moderator's Comments:
Mod Comment Please use code tags, and indent your code / output, etc.

Last edited by Scott; 01-13-2011 at 02:12 PM.. Reason: Code tags; spacing.
# 2  
Old 01-13-2011
Please post the code in CODE tags. Space characters are very important in Shell.
This User Gave Thanks to methyl For This Post:
# 3  
Old 01-13-2011
see methyl answer below

Last edited by ctsgnb; 01-13-2011 at 01:07 PM..
This User Gave Thanks to ctsgnb For This Post:
# 4  
Old 01-13-2011
Some lines with obvious syntax issues. Nothing to do with alias.

Quote:
if [$# -eq 1]
(Space characters missing after [ and before ]).

if [${wild} != 0]
(Space characters missing after [ and before ])
(Wrong operator for comparing numbers).

sqlplus -s / <<eof &2>/dev/null
(The & is throwing your script into background !)

<<eof
(The << should not be there)
Probably should be:
Code:
if [ $# -eq 1 ]
if [ ${wild} -ne 0 ]
sqlplus -s / <<eof 2>/dev/null
eof

This User Gave Thanks to methyl For This Post:
# 5  
Old 01-13-2011
Thanks a lot...for your prompt responses..

Wow..such obvious mistakes...well most of my problems have been resolved. One issue remains...for some reason, one of the variables remains defined between runs. i.e. The first time I run it with a parameter (wild card for tablespace names) it seems to carry that over into the next execution.


Code:
 > ts_size s%
where tablespace_name like upper('s%')
        Gb TABLESPACE_NAME
---------- ------------------------------
       .38 SYSTEM
        .5 SD
        .5 SI
      7.13 SYSAUX
       8.5
 
 > ts_size
where tablespace_name like upper('s%')
        Gb TABLESPACE_NAME
---------- ------------------------------
       .38 SYSTEM
        .5 SPD
        .5 SI
      7.13 SYSAUX
       8.5
 >


Last edited by Scott; 01-13-2011 at 01:33 PM.. Reason: Code tags; spacing.
# 6  
Old 01-13-2011
Please post the current version of the script.

This line is weird:
Quote:
wild=$(`echo ${1} | awk '{print index($1,"%") }'`)
... but as it errors on my system it is hard to work out what it is meant do do. It is very unusual to use backticks inside parentheses. If we take the backticks away then it calculates where the "%" character is in the parameter $1 or returns zero if there is no "%" character.

Code:
Back on topic.
I wonder if your alias for "ts_size" is
ts_size='. ~/util/sql/ts_size.sh %s'

This User Gave Thanks to methyl For This Post:
# 7  
Old 01-13-2011
Any ideas/suggestions where I can look to resolve this last remaining puzzle?

I have no clue what could be causing this. I checked the env variables, there is nothing there defined that is being used in the shell script. I am not doing an export of any variables.

Thanks in advance.
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 for getting the file size

Hi can some one please help me how i can get the output i require: My text file "sample.txt" contains the text like below Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_fedora-lv_root 15G 2.6G 12G 19% /hari Filesystem Size ... (3 Replies)
Discussion started by: harimhkr
3 Replies

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

3. Shell Programming and Scripting

tablespace monitoring script

I have prepared the below script to monitor the tablespace and alert the users whenever it reaches a threshold limit. #!/bin/sh . /home/.profile sqlplus -s $LOGON << .eof > $scripts/check_tablespace.temp set pages 0 select tablespace_name, free_percent from ( SELECT... (4 Replies)
Discussion started by: svajhala
4 Replies

4. Shell Programming and Scripting

Global alias does not work in shell script

Hi Linux Set up - alias ls='ls -l' Then run script #! /bin/ksh sub() { ls } sub Is there any way to get it working. I don't want to define alias inside of the program Thank you (2 Replies)
Discussion started by: zam
2 Replies

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

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

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

8. Shell Programming and Scripting

Size of an array in sh shell script

Is there a way to find out the size of an array in sh shell script? Thanks. (1 Reply)
Discussion started by: trivektor
1 Replies

9. Shell Programming and Scripting

Bourne: How to invoke an alias from within a shell script

Bourne: How to invoke an alias from within a shell script If I type in the alias in the command line, it runs If I insert that same alias into my shell script and run the shell script, the alias is not invoked. Help please. (2 Replies)
Discussion started by: techshots
2 Replies

10. Shell Programming and Scripting

Get file size in c shell script?

Hi, I want to use an 'if statement' that will check if a certian file is greater in size than a certain value given by the user, but cannot get it to work. Do you have any ideas how this can be done? Your help is appreciated! (6 Replies)
Discussion started by: Dado
6 Replies
Login or Register to Ask a Question