Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. #! /bin/bash
  2. # This is my very first program in IT industry :D
  3. #This programme is for creating qr codes for the data in the database and storing those codes back into the database.
  4. #Functions used are in the beggining
  5. #
  6. #====================START OF dirfun()..(creates directory)================
  7. #
  8. dirfun()
  9. { cd /home/rathankalluri/Rathan/
  10. if [ -d qrcodes ]
  11. then
  12. echo "Directory Exists"
  13. else
  14. mkdir qrcodes
  15. chmod 777 qrcodes
  16. echo "Dir created "
  17. fi
  18. }
  19. #
  20. #====================END OF dirfun()==================
  21. #
  22. #=================START OF name_qr_creator()..creates qr codes and its file names==========
  23. #
  24. name_qr_creator()
  25. {
  26. mysql <<EOF > cat >tempfil
  27. use mysql;
  28. select eno,ename from employee;
  29. EOF
  30. no_ln=$(wc -l tempfil|awk '{ print $1 }')
  31. #"echo The number of lines are $no_ln" This is for testing purpose
  32. count=1
  33. while [ "$count" -le "$no_ln" ] && read line
  34. do
  35. if [ $count = 1 ]
  36. then
  37. #"echo count is $count" This is for testing purpose
  38. count=2
  39. else
  40. #"echo The line is :: $line " This for testing purpose
  41. rawdat=`sed -n "$count"p tempfil`
  42. fnm=`echo $rawdat| sed -e 's/ /_/g'`
  43. #"echo The fil name is $fnm" This is for testing purpose
  44. touch "$fnm".png
  45. chmod 777 $fnm.png
  46. #"echo "The file is @ `pwd`"" For Testing
  47. $(qrencode "$line" -o "$fnm".png)
  48. stat=yes
  49. paths=(`pwd`"/$fnm.png")
  50. #"echo $paths" For Testing
  51. lp=1
  52. for word in $rawdat
  53. do
  54. if [ $lp = 1 ]
  55. then
  56. e_no=$word
  57. lp=2
  58. fi
  59. done
  60. #"echo $e_no" For Testing
  61. mysql -D mysql <<EOF
  62. insert into qrdata values('$stat','$paths','$e_no');
  63. EOF
  64. count=`expr $count + 1`
  65. fi
  66. done </home/rathankalluri/Documents/Details
  67. rm -rf tempfil
  68. rm -rf cat
  69. }
  70. #
  71. #=================End of name creator function =======================
  72. #
  73. #=================== M A I N P R O G R A M RUNS FROM HERE=================
  74. #
  75. #connecting to the sql database.If we have any privileges, use the commented code also.
  76. echo -e "Establishing Connections \n"
  77. /etc/init.d/mysqld start
  78. #echo "Enter the username :"
  79. #read usr_name
  80. #echo "Password :"
  81. #read -s passd
  82. #echo -n "Enter the database name : "
  83. #read db_name
  84. #mysql -h localhost -u $usr_name -p $passd; This code is used if we have any privileges set.
  85. #code for retriving from the database
  86. mysql <<M > cat >Details
  87. use mysql ;
  88. select * from employee ;
  89. M
  90. #"cat Details" #For Testing the output from Database
  91. echo -e "Initializing the Creation process \n"
  92. echo -e "Reading row by row details \n" #line to be removed later
  93. echo "Trying to create a directory"
  94. dirfun
  95. cd /home/rathankalluri/Rathan/qrcodes
  96. echo -e "Qr code generator started \n"
  97. name_qr_creator #Calling QR code creator
  98. echo "Done"
  99. echo -e "removing temporary files \n"
  100. rm -rf /home/rathankalluri/Documents/cat
  101. rm -rf /home/rathankalluri/Documents/Details
  102. echo -e "Killing Connections... please wait \n"
  103. /etc/init.d/mysqld stop
  104. echo -e "Program Termination Complete !!!!"
  105. exit 0
  106. #
  107. #======================== END OF MAIN PROGRAM ===============================
  108. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement