Can't seem to figure out how to script a simple closed loop
I'm stuck. I need to run a simple commandline command for subversion(svnadmin dump...) for 15 days. Then start again and overwrite each of the old .dmp files with new ones.
I think I can do it by brute force with a crontab entry for each of the 15 days at a time, but I'm not even sure I know how to do that.
I'm trying to automate a process I do manually every day. That is, I execute the same command every day for 15 days running, manually changing the filename of the file by 1 each time, i.e. file.1.dmp, file.2.dmp, and so on.
Then after I reach the end of 15 days, I start again changing the filename being written back to the name of the first file I created 15 days ago. This overwrites the 15 files one a day for 15 days. That is, after I create the file.15.dmp, I (manually) change the name of the file being created back to file.1.dmp again.
I realize that this may not be descriptive enough to help me with getting an answer. I don't know how else to explain it. I'd be more than glad to fill in any details I've missed.
I've thought about using a for loop, but it's been so long since I've had to do any programming I hesitate to go down that path. I've though about using the current date variable to change the filename, but how do I reset the script to start again after 15 days?
The point of my exercise is to have a rolling backup/dump file for 15 days that I can restore from if needed.
Your time and consideration is much appreciated.
OK, hows this idea:
Nermal's soln looks about right to me.
Here's some good links on bash
A few notes
1. I'd always use [[ ]] rather than [ ] http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS
2. I'd also use bash arithmetic built-in $(( )) http://tldp.org/LDP/Bash-Beginners-G...ml#table_03_04 section 3.4.6 instead of calling expr (just an efficiency thing; no big deal)
3. don't forget to provide the entire path for any files, unless you first cd into the correct dir before you start.
If you're working on Linux (Unix generally) you're going to need a certain proficiency with the shell of your choice, hence the links above.
I would add that you don't even really need the 15 test as if 14 exists it will overwrite 15 anyway.
So another revision could look like:
First thanks very much for all your kind assistance. Not only am I a baby "script kitty", but so far removed from having to write scripts at this level as to be ridiculous. Apologies for my ignorance. I really am trying to remedy that as quickly as I can.
Next, I've modified the proposed script to mimic what my actual filenames are.
if [ -f main15.svn_dmp ]
for i in 14 13 12 11 10 9 8 7 6 5 4 3 2 1
if [ -f main`$i`.svn_dmp ]
mv main`$i`.svn_dmp file.`expr $i + 1`.svn_dmp
svnadmin dump /var/www/svn/main/ > /svndump/main'$i'.svn_dump
This script will be called by another script that puts one in the appropriate directory for the created files to reside. A simple cd /svndump/...
This, what I call dump script, is in turn called by cron.
Third, I don't know if I made it too clear, but I'm executing the svnadmin dump command once a day every day for 15 days. I change the numeric characters by hand every day when I execute the script. Then after I have completed the 15th day of svnadmin dump, I simply start executing the command again starting with the /svndump/main1.svn_dump filename.
Will this proposed script step through those 15 days like I now do manually? I guess there should really be a day changing mechanism to wrap this proposed script? Or are we talking about a whole different script than what is proposed?
I know this sounds a little screwy. The best way for me to describe what the script should do is to describe what I'm already doing manually. If I'm not to clear on that, please tell me how I can respond to make it clearer.
Thanks again... I've looked through all my coding books and can't seem to find anything that approximates what I want to do. I'm hoping you will have the time to help me with my problem.
Thanks in advance for your consideration.
PS.... Sorry to have to spell out the body of the script rather than embed it as code... I'm going to have to figure out how to do that in this forum too!
Well last issue first, you simply use [code][/code] tags around your code and it will appear like the other entries.
As for calling from another script in which you only do a cd, you can either add that to this script or just place the path within the script.
Yes all scripts demonstrated understand that you will be doing this everyday and on the 15th day the process should go back to day 1 file and overwrite.
Errors I can see is you have placed your variables in what look like back ticks. At best they could be double quotes but even they are not required.
The other main error is that your final line will always output as follows:
Let me know if I did not answer all your questions?
I need to think about this and try out the script as it's written to see if I can get it to work... I'll update this post tomorrow with tonight's results.
The script I'm going to try tonight reads as follows:
You did not read my last post correctly. Your last line is still incorrect. You do not want to use $i but
rather a '1' (See my code snippet from previous post)
|All times are GMT -5. The time now is 08:14 PM.|