Shell script to pull out value of tablespace used %age...

Oracle 11gR1 RHEL5
Hi all,
I'm sure there is something out there, but I was wondering if anyone knew an easy way to create a script the will take a value from a sql script and then if is a certain value or greater, then it will email me. So basically I'm trying to figure out how I can get a shell script to read sql output (tablespace free space) and grab let's say any tablespace that is more than 80% full, and then send me an email with the tablespace name. I have some references but just can't seem to figrue out the reading the value part. I'm still kinda new to the shell scripting world...but eager to learn.
Thanks.

Here is what I have so far. I am getting a permission denied error
#!/bin/bash
FILE=freespace.log
DATECMD=/bin/date
FREESPACELOG="${DIR}/freespace.`date '+%Y%m%d-%H:%M:%S'`.log"
DIR=/home/oracle/scripts/bin/free_space/logs
cd /home/oracle/scripts/bin/free_space/
sqlplus -S "/ as sysdba" << EOF > $FREESPACELOG
set lines 300 pages 400
select tbs.tablespace_name,
tot.bytes/1024 total,
tot.bytes/1024-sum(nvl(fre.bytes,0))/1024 used,
sum(nvl(fre.bytes,0))/1024 free,
(1-sum(nvl(fre.bytes,0))/tot.bytes)*100 pct,
decode(
greatest((1-sum(nvl(fre.bytes,0))/tot.bytes)*100, 80),
80, '', '*'
) pct_warn
from dba_free_space fre,
(select tablespace_name, sum(bytes) bytes
from dba_data_files
group by tablespace_name) tot,
dba_tablespaces tbs
where tot.tablespace_name = tbs.tablespace_name
and fre.tablespace_name(+) = tbs.tablespace_name
group by tbs.tablespace_name, tot.bytes/1024, tot.bytes
order by 5, 1;
exit &exit_status
EOF
*./test.sh: line 7: /freespace.20090331-12:46:53.log: Permission denied*
Edited by: JrOraDBA on Mar 31, 2009 12:48 PM

Similar Messages

  • Script to pull out last logon date

    Hello,
    I have a list of user that I would like to pull out last logon date from AD.
    This is the script I am using at the moment but it produces blanks and I don't know what the blanks mean.
    Import-Module ActiveDirectory
    #This script requires PowerShell AD Module
    Import-csv "c:\scripts\samaccountname.csv" |
    foreach-object {get-aduser $_.samaccountname -Properties lastlogondate} |
    select name,Lastlogondate |
    Export-csv c:\scripts\LastLogon.csv -NoTypeInformation
    Please can you help?
    Kind Regards, PenDraKon

    If you want an accurate lastLogon date, you have to check across domain controllers.
    Here's an advanced function I created a while ago for this.
    Function Get-LastLogon {
    <#
    .SYNOPSIS
    Returns LastLogon information
    .DESCRIPTION
    Queries the LastLogin information for a user across domain controllers and returns the highest (latest) value
    .EXAMPLE
    Get-LastLogon User
    .EXAMPLE
    Get-LastLogon -Identity User
    .EXAMPLE
    Get-ADUser User | Get-LastLogon
    .EXAMPLE
    Get-LastLogon User1, User2
    .PARAMETER users
    List of users - pipeline can be used
    #>
    [CmdletBinding()]
    param
    [Parameter(Position= 0,
    Mandatory=$True,
    ValueFromPipeline=$True,
    HelpMessage='What user would you like to find the last logon for?')]
    $identity
    Begin {}
    Process {
    Foreach ($account in $identity) {
    $dateStamp = $null
    $domainController =$null
    Get-ADDomainController -Filter * | Foreach {
    $dc = $_.HostName
    $lastLogon = (Get-ADUser $account -Properties LastLogon -server $dc | Select-Object Name,@{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}}).Lastlogon
    If ($dateStamp -le $lastlogon)
    $dateStamp = $lastlogon
    $domainController = $dc
    } # End of ForEach
    $properties = @{
    Name=$account;
    LastLogon=$dateStamp;
    DomainController=$domainController}
    New-Object -TypeName PSObject -Prop $properties
    } # End of ForEach
    } # End of Process
    End {}
    } # End of Function
    You can then run...
    Import-CSV ".\samaccountname.csv" | % {Get-LastLogon $_.samaccountname}
    or...
    Import-CSV ".\samaccountname.csv" | % {Get-LastLogon $_.samaccountname} | Export-CSV ".\report.csv" -noType

  • Power Shell Script to pull all deactivated users

    Has anyone written a script to pull a list of deactivated users?
    my goal is to validate sharepoint administrators in AD to see if they are active or deactivated. Any insight would be appreciated.

    yes. sorry for not making that clear. I found a few examples to enter in a user name to check AD, but i need to do that with a list of names instead rather than one by one.
    Hi,
    Here's a few possibilities:
    Returns all disabled AD accounts -
    Search-ADAccount -AccountDisabled
    Checks each username listed -
    $usersToCheck = 'tester1','tester2','tester3','tester4'
    foreach ($user in $usersToCheck) {
    If (((Get-ADUser $user).Enabled) -eq $true) { Write-Host "$user is enabled in AD" -ForegroundColor Green }
    Else { Write-Host "$user is disabled in AD" -ForegroundColor Red }
    Reads a text file of usernames and checks those -
    Get-Content .\userList.txt | ForEach {
    If (((Get-ADUser $_).Enabled) -eq $true) { Write-Host "$_ is enabled in AD" -ForegroundColor Green }
    Else { Write-Host "$_ is disabled in AD" -ForegroundColor Red }
    Don't retire TechNet! -
    (Don't give up yet - 12,575+ strong and growing)

  • How to execute a shell script which is present in remote machine using ODI

    I have requirement of executing a batch (shell script) which is present in the remote machine.
    i have an ODI agent in remote machine as well. I have created agent locally by using the remote machine IP and port.
    I am able to test the agent successfully. But when i am executing the package using that agent it is failing with the following error
    errorODI-1226: Step Execution of the Scenario REMOTE_DEMO version 001 fails after 1 attempt(s).
    ODI-1241: Oracle Data Integrator tool execution fails.
    Caused By: oracle.odi.runtime.agent.invocation.InvocationException: HTTP/1.1 500 ODI-1423: Warning connecting to Agent localagent: work repository WORKREP1 is not bound to the master
    My Work Repository Name is : WORKREP1
    Remote Work Repository Name is:WORKREP_LOCAL.
    Could anyone please help me regarding this.
    I can't download shell script and run it locally this needs to be run on that remote machine only.
    Thanks
    senthilkumar

    This is the code.
    1. we can declare types dynamically
    2. Internal table dynamically
    3. Select querry dynamically
    just copy paste this code
    Here is the code for your question
    DATA:v_fieldname
    TYPE fieldname,
    l_PROG TYPE string,
    v_mess TYPE string,
    l_sid TYPE string,
    wa_ddfields TYPE dntab.
    DATA i_tab TYPE STANDARD TABLE OF string.
    DATA:l_str TYPE string,
    l_str1 TYPE string.
    PARAMETERS matnr type marc-matnr.
    end-of-SELECTION.
    *build the subroutine pool
    APPEND 'PROGRAM subpool.' TO i_tab.
    APPEND `LOAD-OF-PROGRAM.` TO i_tab.
    APPEND `DATA i_tab1 TYPE TABLE OF vbak.`      TO i_tab.
    APPEND `DATA l_rows TYPE i.`      TO i_tab.
    APPEND `select * into table i_tab1 from vbak.` To i_tab.
    append 'DESCRIBE TABLE i_tab1 LINES l_rows.' to i_tab.
    append 'Write :  l_rows .' to i_tab.
    GENERATE SUBROUTINE POOL i_tab NAME l_PROG
    MESSAGE v_mess
    SHORTDUMP-ID l_sid.
    IF sy-subrc = 0.
    PERFORM ('LOOP_AT_TAB') IN PROGRAM (l_PROG) IF FOUND.
    ELSEIF sy-subrc = 4.
    MESSAGE v_mess TYPE 'I'.
    ELSEIF sy-subrc = 8.
    MESSAGE l_sid TYPE 'I'.
    ENDIF.
    Edited by: vijay wankhade on Jan 1, 2009 5:34 PM
    Edited by: vijay wankhade on Jan 1, 2009 5:34 PM

  • PL/SQL function - unix shell script

    Hello,
    I have an application that calls a unix shell script This unix shell script calls a oracle function in the PL/SQL package. For example,
    In package pkg_test, there is function f_test. This function returns pls_interger.
    How can I write a unix shell script to return the value from the oracle function, so that the application can get the value from the unix shell script?
    Many thanks.

    Thank you for your response.
    The Oracle functuion pkg_name.proc_name will return different values, 0, 1, 2, 3 in diffefrent conditions.
    The unix script, myscript.ksh calls pkg_name.proc_name.
    The other application will call myscript.ksh and this application will need to get the values 0, 1, 2, 3 from myscript.ksh.
    Can we make it without using the unix shelll function?
    Thanks.
    Edited by: slsam01 on Jun 2, 2009 9:21 PM

  • Shell Scripting Resources && Conditional

    Hiya folks.
    I'm looking for a great shell scripting site. Or a book. The Apple Mac Dev Centre is ... well she ain't workin for me.
    For instance, I'm looking for some leadership on a conditional, which those docs won't show me:
    troubleshooting=false
    *if [$troubleshooting==1]; then*
    * echo $troubleshooting*
    * echo $nameStart*
    * echo $myDate*
    * echo $newFName*
    * echo $mSource*
    * echo $mTarget*
    fi
    How do I trip this conditional?
    Cheers

    How do you set a boolean?
    Everything in a shell variable is a string. Some of those strings may look like numbers, but as far as the variable is concerned they are strings. There are no boolean variables. It is all in how you interpret the strings in your variable.
    I'll have to check up on the syntax for bash.
    You could read, reread, read and read "man bash". But I know it is not easy to actually figure out how to use the stuff the man page tells you, or even what they really mean when they use various terms. A book with examples helps, but there is magic hidden in the man page that sometimes takes ages and heavy use of shell scripting to figure out, and I've found that no one book will clearly explain every trick that can be done with shell scripts.
    I prefer to have spaces in there, but not around parens of any kind. I wish languages would be the same that way. Heh.
    And I like to have spaces around equal signs in assignments, but Bourne based shell scripts have their own rules. That is just the way it is.
    The syntax for the 'if' command is
    if list; then list; [ elif list; then list; ] ... [ else list; ] fi
    where "A list is a sequence of one or more pipelines separated by one of the operators ...". "A pipeline is a sequence of one or more commands separated by the character |".
    In the original Bourne shell (which ran in 64kilobytes of memory for code, data, and stack space) all expressions were handed by an external program 'test'. So your 'if' statement would have originally been
    if test $troubleshooting = 1; then
    fi
    Someone figured out that Unix filenames do not care what characters make up their name, so a hardlink was created between /bin/test and /bin/[
    ls -li /bin/test /bin/[
    57880389 -r-xr-xr-x 2 root wheel 46720 Jun 17 2009 /bin/[
    57880389 -r-xr-xr-x 2 root wheel 46720 Jun 17 2009 /bin/test
    You will notice that 57880389 (the file's inode) is identical for both 'test' and '['.
    So when you wrote
    if [$troubleshooting==1]; then
    the shell first processed the line and performed variable substitution, so the 'if' line converts to
    if [false==1]; then
    now the shell processes the 'list' of pipelines/commands following the 'if' statement. So a command is the first white space separate token, which is "[false==1]", so the shell looked in all the PATH directories looking for a file with the name "[false==1]" and did not find anything.
    However, if you white space separate the command in the 'list' from its arguments, then the shell can figure out what the first command is, invoke that command, and pass its arguments to the command.
    Now shells have more than 64kilobytes of memory to work with, and so the [[ ... ]] syntax was invented as a way to indicate that the expression was to use the shell built-in evaluation code. And I think bash eventually decided that it would do the /bin/[ program code evaluation as a built-in as well.
    But since you can also say
    if myprogram --opt --opt arg arg arg; then
    fi
    the shell must still be able to tell the difference between [ or [[ as expression evaluation operators, and a legal file with the name /home/me/bin/[myprogram, or $HOME/bin/[[myprogram, so it cannot assume that [ or [[ always start an expression evaluation.

  • Running Shell Scripts within Java code!!!

    Hi,
    How do I run a shell script from my Java code???
    Also I need to ensure my next line of Java code is executed only after the shell script has finished executing.
    Since my shell script just cuts out some line for a txt file and then only my Java code parses the cut-out file section and processes certain info.
    Please help!!!
    Thanks!!!

    Runtime.exec and, if you need your Java to stop until the external executable is complete, Process.waitFor.
    And you'll want to read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Problems to run shell scripts in terminal

    Hey mates,
    I'm not very experienced in writing shell scripts. However, I received a few shell scripts I wanted to execute. I used following command:
    chmod u+x model.sh
    I did not received any error message so that I think that this command works. Afterwards, I wanted to run these file with:
    ./model.sh
    However, it doesn't work, I receive an error message:
    -bash: ./model.sh: /bin/sh^M: bad interpreter: No such file or directory
    If I choose another shell script of my colleague I can run it and it works properly. What's the problem?
    I use in all shell scripts the same syntax starting with
    "! /bin/sh
    Thus, I don't see the reason why the first script isn't running while the second one is fine.
    Help appreciated!
    cheers,
    Thomas

    Unix and Terminal questions are best asked in the Mac OS X Technologies > Unix Forum
    <http://discussions.apple.com/forum.jspa?forumID=735>
    As jsd2 has pointed out, you CANNOT have Windows <CR><LF> line terminators in your file (aka ^M^J). Just about every Unix shell will choke on the <CR>
    We run into this problem all the time with users moving Unix shell scripts through a Windows system and having Windows convert the <LF> terminated Unix files into Windows <CR><LF> files, and then either use them in a Windows Cygwin environment (where they "Barf"), or move them back to a Unix system with the <CR><LF> line terminations still in the scripts, and they "Barf".
    You can look at the contents of your scripts using the following command
    cat -v script.name
    Any ^M characters found at the end of lines will be part of <CR><LF> Windows line terminators.
    You can use the following command to remove the <CR> from those files
    tr -d '
    ' <script.name >new.name
    chmod +x new.name
    If you wish to pursue this further, I would suggest using the Mac OS X Technologies > Unix Forum
    <http://discussions.apple.com/forum.jspa?forumID=735>

  • Perl Scripting -  Is it an alternative to shell scripting?

    Hi all,
    I am new to Oracle. I am trying to learn the basic concepts
    I read that PERL is a server side scripting language.
    I understand the purpose of shell scripts. I come across terms PERL shell scripts.
    I understand PERL interpreter comes with UNIX.
    1. So, is scripting using PERL an alternative to shell scripting? or
    Does it have a different purpose?
    2. If an alternative, then when would PERL scripting be better than shell scripting or vice versa ?
    3. If an alternative, can PERL be exclusively used replacing shell scripting or as mentioned in my 2nd question used based on the application.
    Your reply will be truly appreciated.
    Thanks!

    A hypothetical question: If a unix had PERL
    installation can I use it replacing the unix shell
    scripting for carrying out day to day DBA tasks? You
    mentioned it is not done that way but theoretically
    can it be done?
    Yes, if you are proficient with Perl, you can use perl to script DBA scripts. Perl is more powerful than shell script. So there's nothing Perl can't do that shell can, there are many things Perl can, regular shell can't.
    The limitation is some company has tight policy on installing non-default software on servers, especially production high security servers.
    If not for carrying out day to day DBA tasks using
    PERL scripting is there any other reason for why PERL
    may come installed or can be installed in a UNIX
    flavor?
    Like said, Perl has many useful functions and modules. With DBD/DBI module and string processing power (Regular Expression etc), Perl is very popular tool for dataloading scripts as well as phyton.
    Perl and Phyton are also heavy used for CGI application and much more.

  • Calling a report from a shell script

    We are modifying all concurrent programs to encrypt the oracle password by using the "ENCRYPT" option in the concurrent program definition for all unix based programs.
    The db user/password is derived from the FCP_LOGIN within the shell script. If I submit the concurrent prorgam and go to the root directory on which the unix shell scripts are present and execute the following command :
    ps -ef
    I can see the call to the concurrent program and since I am using the encrypt method, i cannot see the password(I could see the password before the change)
    The problem is one of the shell scripts is calling an Oracle Report by using ar25run command which needs a userid as the parameter.
    So when I issue the above ps command, i can see the password in the call to this report.
    Is there any other way of passing the oracle user/password to the report? This is required for SOX compliance.
    thanks,

    I guess it should be the same problem as if you are calling CONCSUB from unix also, because both need userid and password.
    If that's the case probably metalink note 104541.1 might help you.

  • Shell scripts to read data from a text file and to load it into a table

    Hi All,
    I have a text file consisting of rows and columns as follows,
    GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001
    GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001
    GEF001 000093625 MKL005675 000001 000000 000000 000000 000000 000000 000001 My requirement is that, i should read the first 3 columns of this file using a shell script and then i have to insert the data into a table consisting of 3 rows in oracle .
    the whole application is deployed in unix and that text file comes from mainframe. am working in the unix side of the application and i cant access the data directly from the mainframe. so am required to write a script which reads the data from text file which is placed in certain location and i have to load it to oracle database.
    so I can't use SQL * loader.
    Please help me something with this...
    Thanks in advance.

    1. Create a dictionary object in Oracle and assign it to the folder where your file resides
    2. Write a little procedure which opens the file in the newly created directory object using ULT_FILE and inside the FOR LOOP and do INSERTs to table you want
    3. Create a shell script and call that procedure
    You can use the post in my Blog for such issues
    [Using Oracle UTL_FILE, UTL_SMTP packages and Linux Shell Scripting and Cron utility together|http://kamranagayev.wordpress.com/2009/02/23/using-oracle-utl_file-utl_smtp-packages-and-linux-shell-scripting-and-cron-utility-together-2/]
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com

  • Calling Shell Script From Java

    Hi i have a shell script which calls the ant command.How do i call this shell script from jdk 1.5. I used p = runtime.exec( filename) but it threw an IOException saying cannot execute. How do i call this from my java program which runs on the redhat linux box.Please Help

    Possibility:
    It does not have execute permissions - Either grant them by chmod or use the command as sh <script-name>
    Rich

  • Query to pull out Tables from Workbooks/Folders

    Hi,
    Do anybody have a query which helps to pull out tables which are used in the Workbook or folders, without opening the workbook or a folder ? Your earliest help is Appreciated.
    Thanks,
    Ashok

    Hi Farheen......
    Please try this........
    SELECT T0.HousBnkAct, T1.CardName, T0.PymCode, T0.DflAccount,
    T0.DflBranch, T0.BankCtlKey, T1.DocNum,T1.NumAtCard, T2.LineTotal, T2.Dscription,
    T3.Branch, T3.Street FROM OCRD T0 LEFT JOIN OPCH T1 ON T0.CardCode = T1.CardCode
    LEFT JOIN PCH1 T2 ON T1.DocEntry = T2.DocEntry LEFT JOIN DSC1 T3 ON
    T0.HousActKey = T3.AbsEntry WHERE T1.DocDate >='[%0]' AND T1.DocDate <='[%1]' AND T1.DocStatus = 'o' AND T0.PymCode = 'EFT'
    Regards,
    Rahul

  • What is a shell script?

    dear members,
    what is a shell script?
    I know that it is used for database file management but how?
    can any body highlight on this in detail.
    regards
    sandeep

    > what is a shell script?
    I know that it is used for database file management but how?
    can any body highlight on this in detail.
    Unix provides several command environments, which can also be used as simple programming languages, for example this in korn shell:
    /Users/williamr: integer i=3
    /Users/williamr: while (( i-- > 0 ))
    do
           print $i
    done2
    1
    0
    /Users/williamr: They can be saved as files and executed by entering their names (subject to execution privileges and path setup), thus extending the set of commands available.
    While endlessly useful, they are nothing to do with databases and were not designed for interacting with them.

  • Shell Scripts in oracle Apps on Windows

    Hi Experts,
    Usually we are using shell scripts on Linux, but here i am using windows for Oracle applications, how can i write Shell scripts for concurrent program, is there any way to achieve this. Please suggest me.
    Thanks,
    RED.

    Please see these docs/links.
    How Do You Run A Unix Host Script From Concurrent Managers On MS Windows Platform? [ID 412392.1]
    https://forums.oracle.com/forums/search.jspa?threadID=&q=host+AND+Concurrent+AND+Windows&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

Maybe you are looking for

  • Freeze Pane Property of Excel in RTF template for XML Publisher Report

    Hi all, I have created RTF template and it's output type is Excel. I want to apply Freeze Pane Property of Excel in rtf template so that it can be applied to Excel Output. Please let me know any information regarding this ASAP. Thanks, P.A.

  • Not sure if this email is legit

    Hello, The following information for your Apple ID was updated on 11/jan/2014. This changes was initiated from Egypt. Shipping and/or billing address If these changes were made in error, or if you believe an unauthorised person accessed your account,

  • System alias does not work if not the same as logical system name?

    In most of the situations, we define the portal system alias same as the connected R/3 client logical system name. I also saw some exceptions that system aliases were defined differently from the connected R/3 client logical systems, and they were te

  • Can't upgrade beyond 10.5.6

    I have a Powermac w/2 1gz G4 processors running Leopard. I have not been able to upgrade beyond 10.5.6, however. Each time I try to upgrade I get nothing but kernel panics on startup. As a result, I end up having to reinstall the OS and restore from

  • All names appear in the group mails.  They didn't before.

    I used to be able to send group mail with just the title of the group appearing in the "To" window. Now, all the names in the group have to be there or it won't go out. Sometimes I don't want the names there. iMac G5   Mac OS X (10.4.8)