LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-22-2004, 11:44 PM   #1
gauge73
Member
 
Registered: Jan 2003
Location: Dallas, TX
Distribution: Fedora Core 4
Posts: 420

Rep: Reputation: 30
Issue with my backup script


I wrote a fairly simple backup script for my Linux machine in bash. Essentially it is a recursive script that looks at all the files in the directory, sees if they exist in the backup, then sees if they are newer than the backup, and then backs them up if necessary. So, here is the one problem I can't yet solve...

When the script is called it takes from two to an infinite number of arguments. The first is the backup destination, and the following arguments are sources. It goes through this list with the $@ variable in a for loop. When an argument is a directory, it calls itself with the appropriately altered destination directory and a /* added on to the source directory. So, for example, if I wanted to backup /source to /backup and one of the arguments was a subdirectory /source/sub then this is how it would work...

Code:
# First I call the script

backup /backup /source/*

# One of the files in /source/* is the subdirectory /source/sub, so the script calls itself recursively like so...

backup /backup/sub /source/sub/*

# And so on
So, this is the way it works essentially. Now, before all this occurs there's a test to see if the arguments exist (to catch human error, of course). The problem I'm having is that if these files have two consecutive spaces in their names, they return a false value in the test. So, if the variable that we're testing is $arg, this is how I have the test written...

Code:
if [ -e "$arg" ] ; then
...
else
echo "$arg does not exist!"
fi
I have the double quotes so that files with any spaces at all are valid. I just don't know why files with two spaces aren't. Also, when it outputs the error, the error does NOT display two spaces, but only one. I don't know why this is. I can't tell if the problem is in getting the value of $arg (i.e. the variable never gets two spaces), if it's in the test, or in what * returns or what. I'm kind of a newbie at this. Any recommendations?

Thanks very much in advance.
 
Old 02-22-2004, 11:57 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,965
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
I don't want to discourage your scripting efforts,
but why don't you use this rsync backup-script
and build up on that?


Cheers,
Tink
 
Old 02-23-2004, 11:14 AM   #3
gauge73
Member
 
Registered: Jan 2003
Location: Dallas, TX
Distribution: Fedora Core 4
Posts: 420

Original Poster
Rep: Reputation: 30
I appreciate the suggestion, but this is largely just a learning tool for me. I wouldn't feel like it was a success if I couldn't figure this out. :/
 
Old 02-23-2004, 12:16 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,965
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
In this case :)

Have a look at Druuna's fabulous support
http://www.linuxquestions.org/questi...pace+file+name


Cheers,
Tink
 
Old 02-23-2004, 02:22 PM   #5
gauge73
Member
 
Registered: Jan 2003
Location: Dallas, TX
Distribution: Fedora Core 4
Posts: 420

Original Poster
Rep: Reputation: 30
I read over the thread, but I didn't see anything that solved my problem. The issue is that if the argument in the command line (in this case the return value of the wildcard *) has two spaces in it, when testing that the file exists (which is necessary in case the file name was typed explicitly by the user, and it was inaccurate), it ends up evaluating to false when the file does exist.

Sorry for any confusion. I realize this is probably not the best description, but it's the best I can do. :/
 
Old 02-23-2004, 02:32 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,965
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Well, you'll basically need to put the $VARIABLE
that holds the value of the file/direcotry name into
Quotes ("$VARIABLE") so the string with spaces
gets treated like ONE value...

That said, spaces in file-names are a MS abomination
and shouldn't be used ;)


Cheers,
Tink
 
Old 02-23-2004, 07:22 PM   #7
gauge73
Member
 
Registered: Jan 2003
Location: Dallas, TX
Distribution: Fedora Core 4
Posts: 420

Original Poster
Rep: Reputation: 30
I found the solution. I had a line in the script to remove trailing slashes from any directories, and it was cutting the second space out of the file names. The line was something like this...
Code:
echo $arg | sed 's/\/$//'
and I added quotes around the variable to fix the problem, like so...
Code:
echo "$arg" | sed 's/\/$//'
Thanks for the help, Tinkster.

EDIT: (Post Script, actually)

I'm backing up files on our shared network drive. That means that my wife has files on the drive. That means I'm lucky there aren't files with slashes, asterisks, tabs, etc in them. I have to assume the worst when dealing with her file names.

Last edited by gauge73; 02-23-2004 at 07:25 PM.
 
Old 02-23-2004, 07:54 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,965
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Pleasure mate :}

And you should educate your wife ;}


Cheers,
Tink


P.S.: The downside of people not knowing anything
about underlying file-systems is utter stupidity when it
comes to naming conventions of files ;) I had that guy
ask me why the hell he couldn't use that back-slash
in his filename in Word :D
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Amanda backup issue, taking too long now changlinn Linux - Enterprise 11 04-07-2009 05:30 PM
fsplit and backup issue Paxmaster Linux - Software 0 09-09-2005 06:47 PM
Backup issue lawadm1 Linux - Software 0 10-09-2004 08:47 AM
Backup Issue ro_1010 AIX 6 09-01-2004 02:48 PM
backup script ixion Linux - Software 2 01-09-2003 06:39 AM


All times are GMT -5. The time now is 02:49 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration