shell script

Posted on 2011-10-26
Last Modified: 2013-01-21
   Can anyone explain me how to execute a shell script like im having putty, sqlplus how to use these two tools to execute a shell script
Question by:thota198
    LVL 73

    Accepted Solution

    are you trying to invoke sqlplus from a shell script?

    here's an example...

    save this as a file , for example  "compare_dates"

    function get_db_date {
    sqlplus -s / <<!EOF | tail -1
    set heading off
    set feedback off
    select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
    os_date=$(date +"%Y-%m-%d %H:%M:%S")
    if [[ $db_date = $os_date ]]; then
       echo "same"
       echo "different"
       echo ">$db_date<"
       echo ">$os_date<"

    Open in new window

    then grant execute permission on the script
    and invoke it

    $ chmod +x compare_dates
    $ compare_dates

    Note this part of the sqlplus command line...

     " / "

    that means it's going to log in with os authentication,  if you don't have an ops$  account it won't work

    LVL 76

    Assisted Solution

    by:slightwv (䄆 Netminder)
    From your previous questions recently this question is a little confusing.

    If you already have a shell script once you are a command line on the unix machine, connected to through putty, you just call it like any other command.  

    If the script doesn't have execute permissions you can force it.

    # cd /some/folder
    # . ./shell_script_name

    The first '.' forces execution.  The second '.' tells the OS to look in the current directory and ignore the PATH.  It is a good habit to get into from a security standpoint.

    You also seem to have sqlplus scripts.  You can execute them in the shell script like sdstuber posted above of run them manually if this is a one-time thing.

    # cd /some/folder
    # sqlplus username/password
    SQL> @sql_script_name
    LVL 34

    Assisted Solution

    by:Mark Geerlings
    Putty can be used to run shell scripts.  SQL*Plus can be used to run *.SQL scripts.  First become familiar with O/S commands that you can put in shell scripts.  And become familiar with SQL commands that you run interactively in SQL*Plus, or via *.SQL scripts in SQL*Plus.  You can actually combine the two as the example from sdstuber indicates where you actually have SQL commands inside a shell script (between the two "!EOF" markers).

    I find it simpler to keep my SQL commands in *.SQL files and not run them directly from shell scripts. When I do want to schedule SQL commands, I write a shell script that starts SQL*Plus and passes the *.SQL script to run.  Then I can schedule the shell script using cron.

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
    How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
    Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
    This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now