Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2009
    Posts
    272

    Unanswered: Running script every alternate day

    Environment :
    db2 V9.7 on AIX

    I want to have a db2 backup run every alternate day. How can I schedule this in crontab ? Or is there any logic to induce in the script such that database backup runs every other day.

    Thanks in advance for your help

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Jun 2009
    Posts
    272
    This wouldn't work out. Some months end with 31 days while some end with 30 days. So the above approach you suggested, for few of the months, would result in the execution of jobs on two consecutive days, One at the end of the month and one at the start of the new month.

    But our aim is to run a job on alternate days.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    You can put something like this in your script:

    Code:
    if [[ $(($(date +%s) / 60 / 60 / 24 % 2)) -eq 0 ]]
    then
      echo "not today" && exit
    fi
    It will exit the script on even days but continue on odd days.
    Last edited by n_i; 12-03-13 at 15:39. Reason: It should be "&& exit" - otherwise it won't exit
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    Join Date
    Apr 2012
    Posts
    156
    Great solution, nice and simple :-)

  6. #6
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    It will exit the script on even days but continue on odd days
    31 and 1
    execution of jobs on two consecutive days, One at the end of the month and one at the start of the new month.
    needs more coding...
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  7. #7
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by przytula_guy View Post
    I
    31 and 1
    execution of jobs on two consecutive days, One at the end of the month and one at the start of the new month.
    No, not really. I'm counting days since the Unix epoch, not days of the month.

    date +%s gives you the number of seconds since 1 January 1970.
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •