0% found this document useful (0 votes)
3 views

unix_oracle

The document provides an overview of basic networking concepts in UNIX, including remote server access using telnet and FTP commands. It also details the configuration of Oracle's Net8 networking software, including setting up environment variables and executing SQL scripts. Additionally, it covers the use of cron for automating tasks and includes exercises for practical application.

Uploaded by

preet.agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

unix_oracle

The document provides an overview of basic networking concepts in UNIX, including remote server access using telnet and FTP commands. It also details the configuration of Oracle's Net8 networking software, including setting up environment variables and executing SQL scripts. Additionally, it covers the use of cron for automating tasks and includes exercises for practical application.

Uploaded by

preet.agarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

© New Age Training, Inc.

1
Basic networking

As mentioned before, UNIX is a network operating system. We login to server using


telnet or one of telnet emulators. We can also use other protocols and programs to
interact remotely with server.
Try ftp from your command window on PC.
Try this now using your Unix account:

© New Age Training, Inc. 2


FTP servers come in many flavors, but every one will have the same basic set of commands: get
to download files, put to upload, mget /mput for multiple files transfer, “!” as escape character
(temporary gets you back to your original server). Do not forget to set prompt off before doing
multiple files transfer, otherwise you will be prompted for each file. Set mode to binary for
binary files, to ascii for text files.

Two more commands you hardly will get around without when there is a need to network
troubleshooting.
$ ping <hostname>
$ tracert <hostname> (tracert in Micro$oft dialect)

Just ping and traceroute alone will provide you enough information to pinpoint the problem and
be a good friend to your system administrator.

© New Age Training, Inc. 3


Net8 is the foundation of Oracle's family of networking products, allowing services and their applications to reside on different
computers and communicate as peer applications. The main function of Net8 is to establish network sessions and transfer
data between a client machine and a server or between two servers. Net8 software is installed on each machine in the
network.

LISTENER provides
access to database
running on the same
machine. A client and server
can run different
operating systems.

Servers and clients


can physically reside
in different
locations.

Oracle network software is


supplied with Oracle Server
EE or Client Software CD.

TNSNAMES.ORA file
controls to which
Oracle server(s) a
client can connect.

© New Age Training, Inc. 4


Configure your .bash_profile to work with Oracle:

# .bash_profile

# Get the aliases and functions


if [ -f ˜/.bashrc ]; then
. ˜/.bashrc
fi

# User specific environment and startup programs

DISPLAY=localhost:0.0; export DISPLAY


ORACLE_HOME=/u02/oracle/817; export ORACLE_HOME
ORACLE_SID=bigora; export ORACLE_SID
USERNAME=”” Edit your file so that
the following matches
PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
BASH_ENV=$HOME/.bashrc
USERNAME=””

export BASH_ENV PATH


unset USERNAME

Exit, login again and check:

[test@biglinux test]$ echo $ORACLE_HOME


/u02/oracle/817
[test@biglinux test]$ echo $ORACLE_SID
bigora

© New Age Training, Inc. 5


Login to Oracle:

[test@biglinux test]$ sqlplus test/test

SQL*Plus: Release 8.1.6.0.0 - Production on Wed Mar 14 04:13:02 2001

(c) Copyright 1999 Oracle Corporation. All rights reserved.

Connected to:
Oracle8i Enterprise Edition Release 8.1.6.1.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

SQL>

Login to Oracle using Net8:

[test@biglinux test]$ sqlplus test/test@bigora

SQL*Plus: Release 8.1.6.0.0 - Production on Wed Mar 14 04:13:54 2001

(c) Copyright 1999 Oracle Corporation. All rights reserved.

Connected to:
Oracle8i Enterprise Edition Release 8.1.6.1.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

SQL>

© New Age Training, Inc. 6


You can login to Oracle in a similar way under
MS-DOS (Windows) environment.

© New Age Training, Inc. 7


Exit to Operating System prompt without exiting from Oracle:

HOST is a SQL*Plus command


SQL> host
[test@biglinux test]$

[test@biglinux test]$ date


Wed Mar 14 04:16:09 EST 2001

[test@biglinux test]$ exit


exit

SQL>
You can enter OS commands
SQL> host date without leaving Oracle
Wed Mar 14 04:17:35 EST 2001
SQL> host pwd
/usr/test
SQL> host whoami
test

SQL>

Under MS-DOS

© New Age Training, Inc. 8


SQL> host vi cre_customer.sql

drop table customer;

create table customer


(
cust_id number(4) constraint pk_cust_id primary key,
cust_name varchar2(30),
dob date,
ssn number(9),
address varchar2(30),
city varchar2(20),
state varchar2(2),
zip number(5)
);

SQL> host ls
Desktop cre_customer.sql host

SQL> @cre_customer
drop table customer
*
ERROR at line 1:
ORA-00942: table or view does not exist

Table created.

© New Age Training, Inc. 9


Under MS-DOS

© New Age Training, Inc. 10


SQL> desc customer
Name Null? Type
----------------------------------------- -------- -------------------
CUST_ID NOT NULL NUMBER(4)
CUST_NAME VARCHAR2(30)
DOB DATE
SSN NUMBER(9)
ADDRESS VARCHAR2(30)
CITY VARCHAR2(20)
STATE VARCHAR2(2)
ZIP NUMBER(5)

Login to Oracle and run SQL


[test@biglinux test]$ sqlplus test/test @cre_customer script from UNIX prompt

SQL*Plus: Release 8.1.6.0.0 - Production on Wed Mar 14 04:49:27 2001

(c) Copyright 1999 Oracle Corporation. All rights reserved.

Connected to:
Oracle8i Enterprise Edition Release 8.1.6.1.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

Table dropped.

Table created.

© New Age Training, Inc. 11


SQL>
SQL> host ls /u02/oracle/817/sqlplus/demo
demobld.sql demodrop.sql Run SQL script from
another directory
SQL> @/u02/oracle/817/sqlplus/demo/demobld
Building demonstration tables. Please wait.
Demonstration table build is complete.
Disconnected from Oracle8i Enterprise Edition Release 8.1.6.1.0 -
Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production
[test@biglinux test]$
Check what demobld.sql script did
SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
BONUS
CUSTOMER
DEPT
DUMMY
EMP
SALGRADE

6 rows selected.

© New Age Training, Inc. 12


SQL> @/u02/oracle/817/sqlplus/demo/demodrop Remove demobld.sql objects
Dropping demonstration tables. Please wait.
Demonstration table drop is complete.
Disconnected from Oracle8i Enterprise Edition Release 8.1.6.1.0 -
Production
With the Partitioning option
JServer Release 8.1.6.0.0 – Production
[test@biglinux test]$

SQL> select table_name from user_tables; Check what demodrop.sql script did

TABLE_NAME
------------------------------
CUSTOMER Save this in a file:
cre_customer_seq.sql
SQL> create sequence customerid start with 1 increment by 1;

SQL> host vi ins_customer.sql

insert into customer(cust_id, cust_name, dob, ssn)


values
(customerid.nextval,'Sara
Davis',to_date('10121965','mmddyyyy'),123456789);

insert into customer(cust_id, cust_name, dob, ssn)


values
(customerid.nextval,'Mark
Paris',to_date('02171940','mmddyyyy'),987654321);

insert into customer(cust_id, cust_name, dob, ssn)


values
(customerid.nextval,'Sam
Woo',to_date('07241973','mmddyyyy'),999999999);

commit;
© New Age Training, Inc. 13
SQL> @ins_customer

1 row created.

1 row created.

1 row created.

Commit complete.

SQL> select cust_id, cust_name, dob, ssn from customer;

CUST_ID CUST_NAME DOB SSN


---------- ------------------------------ --------- ----------
3 Sara Davis 12-OCT-65 123456789
4 Mark Paris 17-FEB-40 987654321
5 Sam Woo 24-JUL-73 999999999

© New Age Training, Inc. 14


SQL> host vi customer_report.sql

SET PAGESIZE 20
SET LINESIZE 80

spool customer.rpt

TTITLE CENTER 'Customer Report' SKIP 1 -


CENTER '===============' SKIP 2
BTITLE CENTER '- CONFIDENTIAL -'

column cust_id heading Customer|Id format 9999


column cust_name heading Customer|Name format a30
column dob heading DOB format a10
column ssn heading SSN format a11

select cust_id,
cust_name,
to_char(dob,'mm-dd-yyyy') dob,
substr(to_char(ssn),1,3)||'-'||
substr(to_char(ssn),4,2)||'-'||
substr(to_char(ssn),6,3) ssn
from customer
order by 2;

spool off

© New Age Training, Inc. 15


SQL> @customer_report

Customer Report
===============

Customer Customer
Id Name DOB SSN
-------- ------------------------------ ---------- -----------
4 Mark Paris 02-17-1940 987-65-432
5 Sam Woo 07-24-1973 999-99-999
3 Sara Davis 10-12-1965 123-45-678

- CONFIDENTIAL –

© New Age Training, Inc. 16


SQL> host ls
Desktop customer.rpt host
cre_customer.sql customer_report.sql ins_customer.sql

SQL> host cat customer.rpt

Customer Report
===============

Customer Customer
Id Name DOB SSN
-------- ------------------------------ ---------- -----------
4 Mark Paris 02-17-1940 987-65-432
5 Sam Woo 07-24-1973 999-99-999
3 Sara Davis 10-12-1965 123-45-678

- CONFIDENTIAL -

© New Age Training, Inc. 17


SQL> host vi cre_customer.sh

#!/bin/sh
# cre_customer.sh
# Multi task script
# date: 03-10-2001
#
sqlplus test/test << EOF

@cre_customer.sql
@cre_customer_seq.sql
@ins_customer.sql
@customer_report.sql

exit

This shell script combines all steps into one.

© New Age Training, Inc. 18


[test@biglinux test]$ chmod u+x cre_customer.sh
[test@biglinux test]$ ls -ltr
total 28
drwxr-xr-x 5 test student 4096 Mar 13 06:43 Desktop
-rw-r--r-- 1 test student 0 Mar 14 04:25 host
-rw-r--r-- 1 test student 256 Mar 14 04:36
cre_customer.sql
-rw-r--r-- 1 test student 414 Mar 14 05:25
ins_customer.sql
-rw-r--r-- 1 test student 594 Mar 14 06:51
customer_report.sql
-rw-r--r-- 1 test student 821 Mar 14 06:52 customer.rpt
-rw-r--r-- 1 test student 85 Mar 14 07:01
cre_customer_seq.sql
-rwxr-xr-x 1 test student 142 Mar 14 07:09
cre_customer.sh Execute script

[test@biglinux test]$ ./cre_customer.sh

© New Age Training, Inc. 19


What if we don’t want to hardcode username/password?
SQL> host vi cre_customer2.sh

#!/bin/sh
# cre_customer2.sh
#
# date: 03-10-2001
#
sqlplus $1/$2 << EOF

@cre_customer.sql
@cre_customer_seq.sql
@ins_customer.sql
@customer_report.sql

exit

[test@biglinux test]$ ./cre_customer2.sh scott tiger

[test@biglinux test]$ ./cre_customer2.sh nat_0000 nat_pwd

cre_customer2.sh becomes a general script that we can


run against any schema!
© New Age Training, Inc. 20
Using Cron
Cron allows users to automate repetitive tasks.

$ crontab –e Run cre_customer_cron.sh every 1 minute.


Run cre_customer_cron.sh every 1 minute.

* * * * * . cre_customer_cron.sh

$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.2077 installed on Fri Apr 6 04:23:11 2001)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
* * * * . cre_customer_cron.sh

The Crontab File's Syntax


To tell cron what you want it to run, and how often you want it to run it, you need
to create a crontab file. A crontab file is just a text file with the following syntax:
minute hour day-of-month month-of-year day-of-week command

© New Age Training, Inc. 21


vi cre_customer_cron.sh

#!/bin/sh
# cre_customer_cron.sh
#
# date: 04-05-2001
#
ORACLE_HOME=/u02/oracle/817; export ORACLE_HOME;
ORACLE_SID=bigora; export ORACLE_SID;
0-59/2 * * * * ./cre_customer_cron.sh

sqlplus test/test << EOF Run cre_customer_cron.sh every 2 minutes.

@cre_customer.sql
@cre_customer_seq.sql
@ins_customer.sql
@customer_report.sql

exit

$ crontab -r

© New Age Training, Inc. 22


Exercise:

1. Setup your .bash_profile to work with Oracle. Check.

2. Login to your Oracle account (should be the same as under NT) and run
/u02/oracle/817/sqlplus/demo/demobld (without exiting from Oracle).

3. Using data dictionary check all tables in your schema.

4. Write a SQL script report based on the output below (using EMP and DEPT tables).
Store output in employee.rpt file.

Employee Information

Employee Employee Department


Number Name Salary Name
------------ ------------- --------- ------------------

5. Using Unix command list content of the employee.rpt file. Do not use editor.

6. Schedule script created in step 4 to run every 3 minutes. Check.

DO NOT FORGET TO REMOVE YOUR CRON JOB USING crontab -r

© New Age Training, Inc. 23

You might also like