Issues with shell script

Hi,
I am executing on procedure using the shell script. The Shell script would the spool the output of the procedure into Status.txt file and send the condents through the mail. I am getting correct output when i run the job manually. But it is not giving the output when the job is scheduled in Crontab. Please find the below my shell script.
ORACLE_SID=ora
export TNS_ADMIN=/oracle/11.2.0/network/admin
export ORACLE_HOME=/oracle/11.2.0
export PATH=/oracle/11.2.0/bin:$PATH
export LIBPATH=/oracle/11.2.0/lib32:$LIBPATH
sqlplus -s test/test@test << EOFSQL
SET HEAD off
SET LINESIZE 8000
SET feedback OFF
SET pagesize 0
SET termout OFF
SET SERVEROUTPUT ON
SPOOL Status.txt
begin JobStatus();
end;
SPOOL off
SET termout ON
exit;
EOFSQL
TO='EmailID'
file=/myFolder/Status.txt
cat $file|mailx -s "Status" ${TO}

The only PATH a user cron job knows by default is "/usr/bin" and "/bin", hence it won't find any Oracle applications. ORACLE provides a tool named "oraenv" to setup the required Oracle shell environment. oraenv reads /etc/oratab to setup $ORACLE_HOME, etc. It is by default installed in /usr/local/bin. The following example should work:
#!/bin/sh
# Filename: /home/oracle/scripts/sqlplus_sample.sh
# Author: dude
PATH=/usr/local/bin:$PATH
export $PATH
ORACLE_SID='orcl'
ORAENV_ASK=NO
. oraenv -s
oradate=`sqlplus -s /nolog <<-EOF
  set pages 0 feed off
  connect / as sysdba
  select sysdate from dual;
exit
EOF
`
echo "`date`: Oracle $oradate" >> /tmp/sqlplus_sample.output
[oracle@vm10]$ chmod 755 /home/oracle/scripts/sqlplus_sample.sh
[oracle@vm10]$ crontab -l
* * * * * /home/oracle/scripts/sqlplus_sample.sh
[oracle@vm10]$ cat /tmp/sqlplus_sample.output
Mon Dec 12 11:27:01 CET 2011: Oracle 12-DEC-11
Mon Dec 12 11:28:01 CET 2011: Oracle 12-DEC-11
Mon Dec 12 11:29:01 CET 2011: Oracle 12-DEC-11
Mon Dec 12 11:30:01 CET 2011: Oracle 12-DEC-11Btw, exporting a shell variable means to make it available to sub-shells or child processes.
Also, depending on how you connect, you don't need to export TNS_ADMIN. If you establish a local connection you will be connecting to the oracle database process directly using the BEQ protocol, in which case you don't even need a listener process running. For instance:
$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 12-DEC-2011 12:10:29
Copyright (c) 1991, 2010, Oracle.  All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused
$ sqlplus scott/tiger
SQL*Plus: Release 11.2.0.2.0 Production on Mon Dec 12 15:05:57 2011
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Similar Messages

  • Need to enable Usage Tracking With Shell Script

    Hi All
    I have patch 11.1.1.6.7 installed in system. I have Redhat linux 6 sytem
    Can we enable usage tracking with shell script ? if yes how ?
    Thanks
    Samit Baghla

    Hi Samit,
    No you can not as per my info because everything to be configured for the usage tracking is via repository and enterprise manager. You need to invoke it in em and rpd you need to do modelling. I still did not understand that why you want to create the shell script !!
    Thanks,
    Amol
    (Please mark this answer, if you found correct)

  • Using TACACS+ auth from ACS 5.1.0.44 to ACE. Having Issues with Shell (Exec)

    Using TACACS+ auth from ACS 5.1.0.44 to ACE. Having Issues with Shell (Exec)
    So I am trying to get TACACS+ auth to work for my ACE.
    The command string that I have on the ACE is as follows:
    tacacs-server host 172.16.101.4 key 7 XXXYYYZZZ timeout 15
    aaa group server tacacs+ tacacs+
      server 172.16.101.4
    aaa authentication login default group tacacs+ local
    aaa authentication login console local
    aaa accounting default group tacacs+ local
    But to finish getting this enabled I need to create some sort of shell (exec) string in the ACS that tells the ACE what permission level to allocate.
    I do not know how to do this on the ACS 5.1.0.44.
    Anyone know?
    TAC made a good suggestion but the command path doesn't seem to line up with my version of ACS.
    Thanks for your reply. About this question:
    shell:<Context>*<Role> <Domain>
    What I meant is that you need to check the following couple of things on
    your ACS server in order to have AAA Tacacs users to login into the
    ACE over the context with superuser ritghts.
    Group setup ‑> users ‑> TACACS + Settings ‑> enable Shell(exec)
    ‑> enable Custom attributes ‑> right below this part you need to
    use the following sintax to link the ACE context that this user
    has access to.
    For example:
    shell:<Context>*<Role> <Domain>
    shell:Admin*Admin default‑domain
    Where this user will have access to the Admin context with the role
    admin using the 'default‑domain'

    Wilfred,
    What you will have to do on your version of ACS is modify the shell profile that your admins are hitting for other IOS devices or you can create another shell profile under Policy Elements -> Device Administration ->
    Once you get into this shell profile select the Custom Attributes tab and put in the following fields close to the bottom of the screen, from the example you provided type shell:Admin for the attribute field and then default-domain for the value field, and make sure you select this requirement as optional, if you select mandatory and other IOS devices use this same shell profile you will force this av pair to these devices also which will impact the priv levels that then need for authentication.
    After you add this attribute, save your changes and then test, also make sure that your Aceess Policy is calling this shell profile under the authorization profile for default device admin.
    Thanks,
    Tarik Admani

  • Alignmnet Issues with SAP Script

    Hi All i have an issue with SAP script i have few columns in the script where in the values in the column changes dynamically.For example the value of second column in the first row can be 5 characters and the value of the same in the 2nd row can be of 10 characters and it keeps varying for every row but the max length of it would be 20 characters.
    Now the issues is with the second column as the text in this column keep varying the text in the same row after the second column keep moving either towards right or towards left depending on the text in the second column,Can any one help me as how  can i fix this issue.
    Looking for your valuable inputs.
    Regards
    Hari Krishna.

    Hari,
    http://help.sap.com/saphelp_47x200/helpdata/en/d1/802d91454211d189710000e8322d00/frameset.htm
    Even though it is not the solution,I guess this link will be helpful.
    K.Kiran.

  • SQL in Connection with shell scripts

    Hello everyone,
    I have a conceptual question:
    If people like to implement their SQL-Scripts attached on a shell script(Ruby, Perl, or even OS-Shell), what are actually the benefits doing this? Can someone please give me a szenario, which is very effectively if we do it with combination with shell-script.
    My second question: does oracle sql developer support this shell combination?
    Thank you..

    Wrapping sql script in a shell script provides flexibility. Shell can provide better parameter validation than SQL, better output handling, and better error trapping. Personally I would have the sql script separately for purist modularisation reasons, but you can merge the two.
    e.g.
    getdate.sql
    select sysdate from dual;getdate.sh can look like this
    sqlplus user/pwd @getdateor
    sqlplus user/pwd <<EOSQL
    @getdate
    EOSQLor
    sqlplus user/pwd <<EOSQL
    select sysdate from dual;
    exit
    EOSQLMy preference would be for either of the first two.
    You can use various shell facilities to capture the output of the sql statement for use elsewhere. Variations of the above example can be use to get the current database date and time into the shell environment for use in other queries, or in the shell itself.
    You can run SQL Developer from the command line, but the tool of choice for command line is SQL Plus.

  • Help with shell script

    Can anyone here help me (getting my feet wet) with an addition to a profile (applmgr) that I am trying to make - in the form of a shell script.
    I have the following lines in the profile file - but each time I log into the server as applmgr, I get the error following
    if $HOSTNAME=hostname1
    tnen
    . /u01/xxees/EBST/apps/apps_st/appl/APPSEBST_$HOST.env
    fi
    if $HOSTNAME=hostname2
    ./u01/xxees/EBST2/apps/apps_st/appl/APPSEBST_$HOST.env
    fi
    The error message I am getting us
    -bash: /local/ebsuser/applmgr/.profile: line 39: syntax error near unexpected token `fi'
    -bash: /local/ebsuser/applmgr/.profile: line 39: `fi'
    Thank you all.
    Edited by: 864641 on Jun 13, 2012 1:49 PM

    From the Error Message at line Number 38, I feel that, the file /u01/xxees/EBSTEST/apps/apps_st/appl/APPSEBST_$HOST.env (where $HOST can be "hostname01" or "hostname02") has been modified and has unmatched if.
    Also, If you are using the variable HOSTNAME, I feel that the env file should be like /u01/xxees/EBSTEST/apps/apps_st/appl/APPSEBST_$HOSTNAME.env in which case your script will be like:
    if [$HOSTNAME == "hostname01"]; then
    . /u01/xxees/EBSTEST/apps/apps_st/appl/APPSEBST_$HOSTNAME.env
    fi
    if [$HOSTNAME == "hostname02"]; then
    . /u01/xxees/EBSTEST2/apps/apps_st/appl/APPSEBST_$HOSTNAME.env
    fi
    Hope that this two things will help in resolving the issue.

  • Need help with shell scripting and Patching

    Hello all,
    I am a very new Oracle DBA and I just have an interview where i have been ask two questions that i have no idea of what it is
    1/ What is shell scripting and how do you do shell scripting?
    2/ What is Patching and how do you do patching?
    Can some one help to have a very good understanding of these tow questions?
    Thanks a lot

    1/ What is shell scripting and how do you do shell scripting?shell accept command from you (via keyboard) and execute them. But if you use command one by one (sequence of 'n' number of commands) , the you can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands. This is know as shell script.
    Shell script defined as:
    "Shell Script is series of command written in plain text file. Shell script is just like batch file in MS-DOS
    for example:- for taking backup, health check and doing some task Operating system level or Oracle database level we can create shell script and schedule a cron job
    2/ What is Patching and how do you do patching?for example ,in windows while using sometimes you might face an issue/error and it gives pop up error message would like to send/report this error to microsoft? microsoft will send you a fix for that. lot of fixes for errors/bugs are released as patches.( n number of patches with newer features are releases as new version)
    likewise in oracle for resolving bugs we should have to apply patch.
    patch is basically a fix for a bug/bugs. we need to use opatch utility to apply the paches.
    hope, this helps you

  • Pl/sql procedure with shell script

    Hi Guys,
    I will be updating some of the columns in the database thru SQL UPDATE stament. I want to make this process automatic. I.e instead of running manually this uodate process, i want to write a unix script which run on cron job. In the update stament I have to compare date like e_create_date > to_date (........, 'yymmdd') and date should be 2 days previous then to date and I would ike to create the spool file which I would like to send through mail.the script will run automatically.
    I am confused how to write shell script & sql procedure and how to call it inside the shell script. How can this be done.
    Help Appreciated.
    Thanks
    sonu

    save the Store procedure as a create_SP.sql in OS
    save another testrun.sql
    as follows
    begin
    sp_test('&p_test');
    end;
    If you are on a Unix or Solaris OS then
    open a Shell Script as follows :
    and name as test.sh or test.ksh
    var='SYSTEM'
    export var
    sqlplus username/password
    @create_SP.sql
    -- this created a store procedure on the database
    @testrun.sql $var
    This will execute the SP with parameter from OS Variable.

  • Checking database availability with shell script

    can anyone help with a script that checks for database availability before 10 P.M and 7 A.M at 5 minites interval and starts a SQL Load of a table once the db is available.
    I have no Shell script experience at all but I can amend an already written script.
    Please Help !!

    Dear Timothy,
    Within the Oracle software you have installed on your machine, there is a script called "dbstart" within the <ORACLE_HOME>/bin directory. This script provided by Oracle can be easily modified to check whether the server is up and should help solve your problem.
    Ciao!

  • Packagemaker with shell-script?

    I pulling my hair here. Trying to make a package with a shell-script, postinstall. When i try to choose it its greyed out so i cant select it at all. permissions are root:admin and 0555, i have no clue whats wrong anymore and i have searched the whole internet!
    Using Tiger with Xtools 2.1.
    Happy for all suggestions.
    thx

    1) If you have access to a Windows machine , run the problematic query in windows 'rwrun' and see whether there is any output That way we can find out whether this a 'shell' related problem . [ ie the way cmd lines are passed ]
    2) Backup and Edit the rwrun.sh script . There you can see
    rwrun $* # or something to this effect
    Instead of '$*' , put your command line args inside directly .
    Then just simply run using rwrun.sh < no args >
    Again , this is to see whether this problem is due to the way shell handles parameters
    3) You can even try setting env variables [ as in reports.sh ] and trying 'rwrun' in shell prompt itself
    rwrun <.....> # no .sh
    4) Please consult SuSe shell docs and see whether % [ or may be ' and \ ] has any special meaning.
    Thanks
    The Oracle Reports Team

  • Intermittent issues with Matlab Script in LV2012

    I'm having some intermittent issues with the Matlab Script in LV2012.  I'm running Windows 7 64 bit, and my Matlab is 2013 64-bit.  I've tried the suggestion here:
    http://digital.ni.com/public.nsf/allkb/8BEBC0C86541224286257AF300561B5E
    I tried this but it didn't work for me. 
    I've also looked at this:
    http://digital.ni.com/public.nsf/allkb/2B3FF46C8512C4F786256CF30071BE53?OpenDocument
    In one of my .vi's if I change 2 of the 3 input variables to the complex type, it works.  It seems to be insensitive to the data type of the first input variable.  In another .vi this trick doesn't work at all.  The fix given in the link is to update the .dll, but this seems to be old news as the .dll in my directory is newer than the one referenced in this link.
    The other funny thing is these scripts worked fine on Friday afternoon, but were throwing this error this morning.  I've closed and reloaded both Labview and Matlab, but that didn't fix the issue.
    Are there any new fixes for this issue that I haven't been able to find?
    Thanks,
    Doug

    Doug,
    If you have a service contract feel free to call in to the support line and you'll be able to work with someone on the phone. That'll be the quickest way to resolution.
    Feel free to send me a PM if you wish and I can take a look at the code and test it on our machine. 
    Notes for Branch AE:
    Please reply to This Post within 24 hours
    The US AE is expected to reply to all of your posts within 24 hours. Having this expectation will keep the escalation moving quickly and toward a fast resolution.
    You can also use other communication channels: Phone, Sametime, Lync,etc. to discuss the issue with the US AE. This can help with troubleshooting and quick diagnosis of the issue.
    Click here to provide kudos for a post on this page

  • Java with Shell Scripts

    How can I include shell scripts in a java program?
    I want to create a GUI with Java and when I click a button or check a check box or choose something from a drop down list , I want a shell program to be called each time.For example, If i click a jbutton or check a jcheckbox, I want to execute something like this:
    sed 's/\([0-9]*\)\([-]\)\([0-9]*\)\([-]\)\([0-9]*\)\([-]\)\([0-9:.]*\)\(.*\)/\5\2\3\4\1\6\7/' $file >>temp;exit;;
    How can show the results on the GUI?
    All the graphical environment will be implemented with Java but underneath the job will be made by the scripts.
    I thank you in advance.
    I am looking forward to your answers.
    Lazaros

    Runtime#exec() returns a Process where you can call getInputStream().

  • Threads in java with Shell script

    hello
    I have shell script program which prints continuous number upto infinate.
    that shell script program is running or not i want to see by using threads in java can any one help me out.
    thanx
    mahen

    mark1971 wrote:
    You have to keep in mind that once a Thread finishes the run method you must not reuse it.Perfectly said. I believe sleep() can be replaced with wait() n notify(), if it is based on pre defined condition.
    For example, when input value read ( from kbd or socket etc) is "start", or time is between 2 pm and 3pm, this thread has to be executed.
    Once thread done its work, it can be again moved to wait() state.
    1. No need of stopping thread here.
    2. I think wait() may cause to latency.
    Please correct me if I am wrong.

  • HELP with Shell scripting!!!

    Hello all,
    I'm very new to shell scripting and I'm trying to learn a little more as I go on. I'm trying to write a shell script to create a symbolic link to an application and have it moved to the current user's desktop. I've been doing some testing with the default applications installed on Leopard here is what I have so far...
    ls -s /Applications/Chess.app
    I've trying using cp commands, but I continue to get error messages. The above script does create a symbolic link to my home directory, but I want to then move it from the home directory to the current user's desktop. Can anyone lead me any further?
    Thanks in advance for any help!

    I'm also having a problem making my shell script unix executable. I have tried chmod +x path/to/script and then I killall Finder but nothing happens. Am I doing something wrong?
    Are you trying to make your script "Double-Clickable"?
    Then you still need to do the
    chmod +x /path/to/script
    But that will just make it something you can run from a shell.
    If you want double-clickable, you can create an Automator app
    Applications -> Automator -> Run Shell Script
    Or you can download the free Platypus utility that will make any script a double-clickable applications.
    Or you can name your script
    myscript.command
    where the .command is the important part, which the Finder will treat as something it should execute as a shell script when double-clicked.
    And no killing Finder. They will work without messing with the Finder.
    Personally, I prefer the Automator app or Platypus. Well I also work a lot in the shell, and I execute scripts as script in the shell all the time, so I only create a lot more scripts that get executed as commands than I do double-clickable scripts.

  • [SOLVED] Change environment variables with Shell scripts

    How can I change the "BROWSER" environment variable with a shell script; so I can change it on the fly?
    Last edited by oldtimeyjunk (2012-10-31 12:57:42)

    If you just want to do it for BROWSER so that you can change your default web browser on the fly, you could set BROWSER to e.g. ~/bin/mybrowser and create a symlink to the browser you want at ~/bin/mybrowser. Then you could change the symlink at will.
    EDIT: man xdg-settings
    Last edited by cfr (2012-10-31 02:20:16)

Maybe you are looking for

  • Creation of Dropdown "custom" field in PCUI

    Hello I have created a new field through EEWB and want to place it in both form view and list view of Accounts transaction (crmm_account) in PCUI. This field should be come as a drop down field and should have specific values to be picked from the do

  • Cannot play music purchased under old apple id after new hard drive installed

    Replaced crashed HD and used Time Machine to restore to 10.7.5. Had changed my Apple ID a while backe (couple months). Now music purchased with old ID will not play, asking me to authorize under old ID, have no idea what the password was and the emai

  • 9.3.1 to ????

    All, At present on 9.3.1 with EPMA As Corporate is moving to IE8, I have to upgrade to Mixed Release(9.3.3 all products except SharedService/EPMA/WorkSpace to 11.1.1.3) or all products to 11.1.1.3 (11.1.1.3 IE8 included all the products we use) Which

  • Patch 8.1.5.0.2

    Hi, did anybody patches the new patch against 8.1.5.0.1 on a SuSE 6.2 system ?? What did it fix ??? Michael

  • FM11 crashes when I try to open a file from a book

    Hi, I have been using framemaker 11 all these days. From yesterday , I have a strange issue. FrameMaker 11 crashes every time I open a file from a book. I have attached the screenshot of the error I get. Can anyone help  me as to what could be the is