SHELL 脚本检查是否数据库存在某张表

5060阅读 0评论2013-08-22 linux_kaige
分类:LINUX

源自百度的一个人发的问题,当时没什么事儿,就写了脚本,在这里分享or记录一下:

  1. [root@yang testshell]# cat tabletest.sh
  2. #!/bin/bash
  3. su - oracle <<ok
  4. fuckyou(){
  5. sqlplus /nolog <<fuck
  6. conn scott/yk123;
  7. select table_name from user_tables;
  8. exit;
  9. fuck
  10. }
  11. fuckyou >>/home/oracle/output.txt;
  12. exit
  13. ok
  14. #fuckyou >>/home/oralce/output.txt;如果在这里,那么则无法找到fuckyou这个函数。
  15. read -p "please input tablename: " -t 5 tablename
  16. tn=$(echo ${tablename} |tr [a-z] [A-Z])
  17. grep -l "${tn}" /home/oracle/output.txt && echo "the table ${tablename} exist.";
  18. [root@yang testshell]#sh tabletest.sh
  19. please input tablename: emp
  20. /home/oracle/output.txt
  21. the table emp exist.
  22. [root@yang testshell]#






上一篇:CU的博客是怎么了???
下一篇:virtualbox弄个centos