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
...
- 07-11-2008 #1Just 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?!?!
- 07-11-2008 #2
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.
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.Code:if [ $(date +%u)=5 ]; then
--
Bill
Old age and treachery will overcome youth and skill.
- 07-11-2008 #3Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Why not use cron to make that decision?
- 07-11-2008 #4Just 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 ]"...
- 07-12-2008 #5Linux 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.
- 07-13-2008 #6Just Joined!
- Join Date
- Jun 2008
- Posts
- 8
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!


Reply With Quote
