Execute DB2 SQL. Common users can use crontab to perform regular execution.

Source: Internet
Author: User

This article mainly tells you the example of using crontab to regularly execute DB2 SQL. Today, we tested it in RHEL 5.3. Common users use crontab to periodically execute DB2 SQL operations, it took some detours because of the usage. /The execution result is correct.

While crontab cannot be executed, it is very depressing. I checked it online for a long time, and many said it was a permission issue for/usr/bin/crontab.

But I can check it at RHEL 5.3.

 
 
  1. -rwsr-sr-x 1 root root 309K 2007-06-22 /usr/bin/crontab 

My permissions are correct. I checked a lot of information to find out that it was a problem with the DB2 environment variables, mainly because the level is not enough and the consciousness is not high. I wrote down the backup

Log on to linux as a db2inst1 user

 
 
  1. 1. vi db2inst1cron
  2. * ***/Home/db2inst1/tongji. sh>/home/db2inst1/B .txt
  3. 2. crontab db2inst1cron
  4. 3. vi tongji. sh (1, 777)
  5. #! /Bin/bash
  6. # Tongji auto
  7. Top = "20"
  8. Qiantian = $ top 'date-d' 2 day ago '+ "% y % m % d "'
  9. Yesterday = $ top 'date-d' 1 day ago '+ "% y % m % d "'
  10. Echo "----------------------------------------------"
  11. Echo $ (date + "% y-% m-% d % H: % M: % S ")
  12. Echo "----------------- setp1: date --------------------"
  13. Echo "qiantian:" $ qiantian
  14. Echo "yesterday:" $ yesterday
  15. Echo "----------------- setp2: char ---------------------"
  16. # Sed-I "s/$ qiantian/$ yesterday/g" 'grep $ qiantian-rl/home/db2inst1/tongji_sec'
  17. Echo "---------------- step3: dbconnect -----------------"
  18. Db2 "connect to toolsdb"
  19. Echo & quot; 1232312312 & quot"
  20. Db2-tf/home/db2inst1/tongji_sec/SQL _sec. SQL
  21. 4. vi SQL _sec. SQL
  22. Insert into liuchao values (10 );
  23. A.
  24. [Db2inst1 @ localhost ~] $./Tongji. sh is correct and the result is desired)
  25. 10-03-09 15:37:27
  26. ----------------- Setp1: date --------------------
  27. Qiantian: 20100307
  28. Yesterday: 20100308
  29. ----------------- Setp2: char ---------------------
  30. ---------------- Step3: dbconnect -----------------
  31. Database Connection Information
  32. Database server = DB2/LINUXX8664 9.5.3
  33. SQL authorization ID = DB2INST1
  34. Local database alias = TOOLSDB
  35. 1232312312
  36. DB20000I The SQL command completed successfully.
  37. [Db2inst1 @ localhost ~] $
  38.  
  39. B. crontab execution error, no database operation, not expected result)
  40. 10-03-09 15:38:01
  41. ----------------- Setp1: date --------------------
  42. Qiantian: 20100307
  43. Yesterday: 20100308
  44. ----------------- Setp2: char ---------------------
  45. ---------------- Step3: dbconnect -----------------
  46. 1232312312

Solution

 
 
  1. #! /Bin/bash
  2. # Tongji auto
  3. ./Home/db2inst1/sqllib/db2profile # introduce the db2 environment variable. There is a space behind it)
  4. Top = "20"

The above content is an introduction to regular users who use crontab to regularly execute DB2 SQL examples. I hope you will gain some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.