Guest User

Untitled

a guest
May 27th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/bin/ksh
  2. #
  3. # Insert DB user and password here
  4. DB_USER=SCOTT
  5. DB_PASS=TIGER
  6. #
  7. #
  8. DIRECTORY_PATH="$1"
  9. ORACLE_DIRECTORY="$2"
  10. # print $9 may differ from *NIX versions but play with the numbers, this is tested on AIX/RHEL5
  11. #for Debian use print $8
  12. ls -l $DIRECTORY_PATH | grep -v '^d' | awk '{ print $9 }' > $ORACLE_DIRECTORY.lst
  13.  
  14. #adding files and directory name to csv
  15.  
  16. for fileName in $(< $ORACLE_DIRECTORY.lst)
  17. do
  18. cat>>$ORACLE_DIRECTORY.csv<<EOF
  19. $fileName,$ORACLE_DIRECTORY
  20. EOF
  21. done
  22.  
  23. # deleting previously entered files for that directory
  24. #####
  25. cat >> $ORACLE_DIRECTORY.sql <<EOF
  26. begin
  27. delete directory_files where directory='$ORACLE_DIRECTORY';
  28. commit;
  29. exception when no_data_found then
  30. null;
  31. end;
  32. /
  33. exit;
  34. EOF
  35. #
  36. $ORACLE_HOME/bin/sqlplus $DB_USER/$DB_PASS @./$ORACLE_DIRECTORY.sql
  37. #####
  38. #
  39. # loading new files into directory table, using ReadDirectory.ctl control file
  40. ####
  41. $ORACLE_HOME/bin/sqlldr userid=$DB_USER/$DB_PASS data=./$ORACLE_DIRECTORY.csv control=./ReadDirectory.ctl log=./ReadDirectory.log
  42. #
  43.  
  44. ## removing files...
  45. rm -rf $ORACLE_DIRECTORY.sql
  46. rm -rf $ORACLE_DIRECTORY.csv
  47. rm -rf $ORACLE_DIRECTORY.lst
  48. # over and out :)
  49. exit
Add Comment
Please, Sign In to add comment