我需要一个执行以下操作的 shell 脚本:
1-接受用户名密码连接字符串并连接到 sqlplus
2- 运行“.sql”文件。
3- 需要 shell 脚本在运行“.sql”文件时获取该会话的 pstack
通过使用下面的代码,我可以连接到 sqlplus 并运行“.sql”文件。
#!/bin/bash
echo "Enter Your USERNAME: "
read my_uname
echo "Enter Your PASSWORD: "
read my_passwd
echo "Enter Your HOSTNAME: "
read my_hostname
echo "Enter Your PORTNO: "
read my_port
echo "Enter Your SERVICE: "
read my_service
sqlplus -s ${my_uname}/${my_passwd}@${my_hostname}:${my_port}/${my_service} @test.sql
我可以使用以下脚本获得所需的输出:
#!/bin/bash
#Promt 输入数据库的用户名
echo“输入您的用户名:”
读取我的_uname
#提示输入上述用户的密码
回显“输入您的密码:”
读取我的_passwd
#提示 pod 的主机名
echo“输入您的主机名:”
读取我的主机名
#Promt 监听器的端口号
echo“输入您的端口号:”
读取我的端口
#提示服务已连接
回显“输入您的服务:”
阅读我的_服务
#使用上述输入参数连接到 sqlplus 的连接字符串
sqlplus -s ${my_uname}/${my_passwd}@${my_hostname}:${my_port}/${my_service} @test.sql &
#使用脚本名称获取上述sqlplus的进程id
my_pid=
ps -ef | grep -v grep | grep test.sql | awk '{print $2}'
#等2秒
睡觉2
#在上面步骤获得的进程ID上运行pstack
pstack ${my_pid}