LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-25-2011, 04:45 PM   #1
Dizieze
LQ Newbie
 
Registered: Oct 2011
Posts: 5

Rep: Reputation: Disabled
Unhappy bash - execute on each directory within a directory


Hello all,
I need some help writing a bash script.

I need to execute a svn-dump on each directory within my svn-directory and then name the dumpfile whatever the directory was called with ".dump" as the extension.

Here is what I have so far:

Code:
#!/bin/bash

directory=/var/svn
extension=".dump"

for file in $( ls $directory )
do
rename=$directory$extension
svnadmin dump $directory > $rename
done
Within the /var/svn directory I have about 50 svn repositories such as /var/svn/IT.

You can probably tell I have no idea what I'm doing a little help would go a long way. =)
 
Old 10-25-2011, 06:55 PM   #2
Julian Andrews
LQ Newbie
 
Registered: Jan 2011
Distribution: Ubuntu
Posts: 21

Rep: Reputation: 13
Your script seems pretty close to the mark to me!

A couple minor notes:

It's best to avoid using 'ls' when you can just use globbing - it's faster and easier to read.

Also, you should always use quotes around filenames in case they have spaces in them.

You can check if a file is a directory with the if [ -d "$file" ] construct.

Working on the assumption that you want the .dump files in the /var/svn folder, here's what I came up with.

Code:
#!/bin/bash

directory=/var/svn
extension=".dump"
for file in "$directory"/*
do 
    if [ -d "$file" ]
    then
        svnadmin dump "$file" > "$file$extension"
    fi
done
Let me know if this works for you!
 
1 members found this post helpful.
Old 10-25-2011, 07:10 PM   #3
spankbot
Member
 
Registered: Aug 2007
Posts: 133

Rep: Reputation: 16
Also, have a look at svnbak.pl. It takes care of backing up and rotating/archiving...

http://www.zulius.com/freebies/perl-...-repositories/
 
1 members found this post helpful.
Old 10-26-2011, 01:02 PM   #4
Dizieze
LQ Newbie
 
Registered: Oct 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks Julian! That worked great. Glad to know I was kinda close myself =P

I will look into svnbak.pl spankbot. Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] su results in Cannot execute bash: No such file or directory gujedan Linux - Newbie 1 02-13-2011 02:24 PM
Directory execute permission MTK358 Linux - Newbie 2 04-24-2010 11:53 PM
Bash scripting: "line [...]: [directory]: is a directory " ? serious Linux - Newbie 1 10-20-2007 01:08 PM
Execute command from other users directory ruj.sabya Linux - General 1 05-25-2007 09:01 AM
Bash script to strip a certain directory out of directories in a directory? rylan76 Linux - General 3 08-29-2006 12:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration