Originally published on Netease blog 20:17:39
Operating the database in Solaris shell is not very complicated. The whole process is the same as writing an FTP login shell.
The following is the shell I wrote after referring to the online materials:
1. Execute SQL commands
#! /Usr/bin/sh
If [$ #! = 2]
Then
Echo "not enough arguments"
Exit 1
Fi
Sqlplus $1/$2 <EOF
Spool off;
@ Test. SQL
Exit
EOF
This shell function is very simple, that is, entering sqlplus, using a user to connect to a database instance, and then executing a test. SQL script. you can also directly write SQL commands in shell scripts, but note the line feed problem.
2. Start the database
#! /Usr/bin/sh
Sqlplus/nolog <EOF
Connect/As sysdba
Startup;
Exit
EOF
3. Stop the database
This script only needs to change startup to shutdown immediate.
This shell is written in here document technology, indicating that the input parameters after shell are between two EOF.