Linux/Unix shell scripts run SQL statements across servers and Instances

Source: Internet
Author: User

During database O & M, it is inevitable that you need to query databases across multiple servers and multiple Oracle instances. For example, you need to check the value of the open_cursor parameter in all current production environment databases to determine whether to increase the value. The database server to be viewed has multiple instances and multiple database servers. In this way, dozens of databases and hundreds of database servers are queried one by one, that means we have to get tired. It is like a method to write a shell script to patrol all servers and all instances on the server. See the description in this article.

For details about how to call SQL statements in shell scripts, refer to the following link:

Linux/Unix shell scripts call SQL and RMAN scripts

Passing variables between Linux/Unix shell SQL statements

1. Use ssh-keygen to generate a key for fast Login

To automatically execute scripts across servers, you must implement password-free automatic login before you can jump between multiple servers. Therefore, you must first generate a logon key.
Three steps are required to survive the logon key. Create a key on the local machine, copy the public key to the remote host, and append the public key to the authorized_keys of the remote host.
The following is an operation example:

Oracle @ linux1: ~> Mkdir ~ /. Ssh # first create the. ssh directory locally and grant permissions
Oracle @ linux1: ~> Chmod 700 ~ /. Ssh
Oracle @ linux1: ~> Ssh-keygen-t rsa # Use ssh-keygen to generate a key pair, or use dsa
Generating public/private rsa key pair.
Enter file in which to save the key (/users/oracle/. ssh/id_rsa ):
Enter passphrase (empty for no passphrase ):
Enter same passphrase again:
Your identification has been saved in/users/oracle/. ssh/id_rsa.
Your public key has been saved in/users/oracle/. ssh/id_rsa.pub.
The key fingerprint is:
01: c8: 48: 01: f2: 3d: a7: b4: cd: 4a: 9c: 10: 2d: ba: ef: 4e oracle @ linux1

Oracle @ linux2: ~> Mkdir ~ /. Ssh # create a. ssh directory on the remote server and grant permissions to it
Oracle @ linux2: ~> Chmod 700 ~ /. Ssh

Oracle @ linux1: ~> Scp ~ /. Ssh/id_rsa.pub 172.161.196 :~ /. Ssh # copy the public key to the remote server, that is, machine linux2
The authenticity of host '192. 168.1.196 (172.161.196) 'can't be established.
RSA key fingerprint is 08: 3d: 69: 80: 85: 1d: ce: 57: 32: e0: 72: e0: 38: 66: 0c: 36.
Are you sure you want to continue connecting (yes/no )? Yes
Warning: Permanently added '192. 168.1.196 '(RSA) to the list of known hosts.
Password:
Id_rsa.pub 100% 393 0.4KB/s

Oracle @ linux2: ~> Cat ~ /. Ssh/id_rsa.pub> ~ /. Ssh/authorized_keys # append the public key to authorized_keys of the remote server.

Oracle @ linux1: ~> Ssh 172.161.196 date # verify whether a password is required
Thu Aug 22 10:50:47 HKT 2013

  • 1
  • 2
  • 3
  • 4
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.