Find the answer to your Linux question:
Results 1 to 6 of 6
Hi everybody after years of programming on windows I started to write some scripts on linux, and I'm stuck on a IF! I feel so rookie.... if ['date +%u'=5]; then ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    8

    Stuck on an IF!

    Hi everybody

    after years of programming on windows I started to write some scripts on linux, and I'm stuck on a IF! I feel so rookie....

    if ['date +%u'=5]; then
    tar "full"
    else
    tar "incremental"
    fi

    I'd like to make a full backup on th 5th day of the week, and incremental all the others.
    Where I do wrong?!?!

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    In that first line, use backticks. Also, make sure your left square bracket is followed by a space and your right square bracket is preceded by a space.
    Code:
    if [ `date +%u`=5 ]; then
    Those backticks look far too much like regular single quotes. For that reason, I'd recommend the $(whatever) syntax:
    Code:
    if [ $(date +%u)=5 ]; then
    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Why not use cron to make that decision?

  4. #4
    Just Joined!
    Join Date
    Jun 2008
    Posts
    8
    thanks I've solved the problem
    cron fires do_backup `date +%u` and inside the script the check is "if [ $1 = 5 ]"...

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    An alternative way would be to have two cron entries - one with "5" in the 5th field to do the full backup and the other with "0-4,6" to do the incremental backup. Give the script a "full" or "inc" argument to switch. It's a close call in your specific application as to which is the most effective, but for some apps letting cron decide on the day is neater.

  6. #6
    Just Joined!
    Join Date
    Jun 2008
    Posts
    8
    Quote Originally Posted by scm View Post
    An alternative way would be to have two cron entries - one with "5" in the 5th field to do the full backup and the other with "0-4,6" to do the incremental backup. Give the script a "full" or "inc" argument to switch. It's a close call in your specific application as to which is the most effective, but for some apps letting cron decide on the day is neater.
    that was my previus configuration, but now I need a script where I can write just once all the backup commands as they change often and I prefer not to be forced to put changes in two files.
    However now the script is ok! cron fires "do_backup `date +%u`" and the script has an if with $1, if it's not 5 it adds "- newer..." to tar options.
    Thanks a lot to everyone!

Posting Permissions

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