what I want to do is to backup a database every day so that the first six days a week it is stored in a dir named 1 - 6. The last day it should be stored in a dir name woche_1 - woche_2 and once a month (15th) it should be stored in a dir named as the month. So I did this:
day=`date +%u`
date=`date +%d`
month=`date +%b`
if $day -lt 7 ]
then
dir=$day
else
((week=$date/7))
if $week -le 1 ]
then
dir="woche_1"
elsif $week -le 2 ]
dir="woche_2"
elsif $week -le 3 ]
dir="woche_3"
elsif $week -le 4 ]
dir="woche_4"
elsif $week -le 5 ]
dir="woche_5"
fi
fi
if $date -eq 15 ]
then
dir=$month
fi
The daily and monthly updates are working fine. Only the weekly don’t. They are stored in the main dir of the backup server. I log the result and it seems that the variable $dir is empty in that case. What’s wrong with that?
I read a bit but not the man and I found it like this. What confuses me is that I wrote that script about three years ago for the old server and it worked. I find lines like this in the log:
Zielverzeichnis ist: woche_3
which means target folder is: woche_3. And the file was placed in the correct folder. Now I moved it to the new server and it didn’t work. I’m really confused.
Ok, case statement could be better but I don’t like them.
BTW: Folders are not created with this but selected which means the folders exist on the backup server.
Thanx again. Will have to wait until sunday to check if it worked correctly.
All these answers assume that erikro is writing a bash, sh or ksh script. Which he did not say at all (but it may be very likely that he wants to use bash).
But while is script contains many contructs that are no bash constructs at all and he tells that part of it works, I wonder if he really does not use another language.
Should be a bash skript. You are talking about many constructs which are wrong? Well, I’m not a good bash script programmer. Mostly I use Perl. So what else is wrong? The problem itself seems to be solved.
Thanks for sharing! Buy Paul Smith bag and Paul Smith men’s shoes in Paul Smith Shop. Paul Smith, famous brand in UK. Colorful strips are is logo. The simple but useful, fashionable design is your best match. Nowadays, it has many stylish products, including Paul Smith’s shoes, Paul Smith bags-shirts, Wallets,Ties,Scarves,Cuffinks, Glasses,Belts, Bath Towels, Money Clips,Key Purses and Key Rings! Paul Smith, you deserved it!