[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

shell script

   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
3 Solutions
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

slightwv (䄆 Netminder) Commented:
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
Mark GeerlingsDatabase AdministratorCommented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now