Click to See Complete Forum and Search --> : Bash script
ok, this is my second try at making a back up script in bash. but once again i have got stuck.
here are parts of the responce i get from "bash -x .."
[root@localhost Shell]# bash -x ./newbackup
...
+ Filess=
+ /Programming/C++
./newbackup: /Programming/C++: is a directory
...
+ Filess=
+ /Programming/Shell
./newbackup: /Programming/Shell: is a directory
...
+ Filess=
+ /Programming/test
./newbackup: /Programming/test: Permission denied
ok i think bash is trying to exicute what ever i put in Filess. and if it cant it clears Filess. so is there anyway to make bash try not to exicute what is in the varable??
TIA
-Osh
The Kooman
10-31-2001, 12:35 AM
Originally posted by Osh:
<STRONG>ok, this is my second try at making a back up script in bash. but once again i have got stuck.
here are parts of the responce i get from "bash -x .."
[root@localhost Shell]# bash -x ./newbackup
...
+ Filess=
+ /Programming/C++
./newbackup: /Programming/C++: is a directory
...
+ Filess=
+ /Programming/Shell
./newbackup: /Programming/Shell: is a directory
...
+ Filess=
+ /Programming/test
./newbackup: /Programming/test: Permission denied
ok i think bash is trying to exicute what ever i put in Filess. and if it cant it clears Filess. so is there anyway to make bash try not to exicute what is in the varable??
TIA
-Osh</STRONG>
Show your source code - only then will the debug make sense! Otherwise we're just groping in the dark!
ok here is the source:
declare Input=$(cat newbackup.conf)
#Backup Area
BA=/BackUp/
#Subdirectory
SD=$(date +%Y%m%d)
NewSD=""
Filess=""
Mode="0"
#Mode 0 -Nothing
#Mode 1 -Not Recursive
#Mode 2 -Recursive
for a in $Input
do
if [ $Mode = "0" ] && [ $a != "r" ] && [ $a != "nr" ]
then
Filess=$Filess $a
elif [ $a = "r" ]
then
Mode=2
elif [ $a = "nr" ]
then
Mode=1
elif [ $Mode != "0" ]
then
NewSD=$SD$a
echo
echo $Filess
echo
echo $Mode
echo
echo $NewSD
echo
mkdir -p $BA$NewSD
for f in $Filess
do
if [ $Mode = "1" ]
then
echo $f******
cp -p $f $BA$NewSD
else
echo $f******
cp -R -p $f $BA$NewSD
fi
done
Filess=""
NewSD=""
Mode="0"
fi
done
where newbackup.conf = "Input=/Programming/* nr /ProgOnly /Programming/* r /ProgAll"
waxmop
10-31-2001, 04:34 PM
it might be good to clearly define your goals for us. do you want to backup everything in a dir tree, or an entire mount point, or just a specific list of files?
there's actually some already written really good backup utils out there. dump and tar are good places to start. they already deal with stuff like recursive copying, and if you include something like gzip with tar, you get the advantage that your backups will be compressed.
l01yuk
11-01-2001, 07:40 PM
I would say that it may well be that you are not always using the -r option with your copy statements.
If you could put in echo statements throughout to pinpoint exactly where the :is a directory error is being generated it would help.
Put something like
<statement>
echo 1
<statement>
echo 2
etc...
Pretty simple idea but it works well.
My first bet though would be that you are entering mode1 and are trying to copy a file only.
Hope it helps.
The Kooman
11-02-2001, 12:32 AM
Originally posted by Osh:
<STRONG>
<...snip...>
for a in $Input
do
if [ $Mode = "0" ] && [ $a != "r" ] && [ $a != "nr" ]
then
Filess=$Filess $a
</...snip...></STRONG>
Going by your error messages, I think your error is here! Enclose the RHS of your assignment expression in quotes:
Filess="$Filess $a"
BTW, I think you mean to use the '&&' operator in the way you use it in C but thats not quite it in bash. The '&&' operator is used for a different purpose in bash! E1 && E2 ... means that if expression E1 exits with an erorr status zero (ok) then execute E2 and so on. But what you want is the l
ogical "and" which is achieved by the -a operator:
if [ $Mode = "0" -a $a != "r" -a $a != "nr" ]
then
...
Finally, if "Mode" is only an integer, you could use an integer comparison instead:
if [ $Mode -eq 0 -a $a != "r" -a $a != "nr" ]
then
...
man bash for lots more info!
HTH.
l01yuk
11-02-2001, 04:26 AM
|--- SNIP
BTW, I think you mean to use the '&&' operator in the way you use it in C but thats not quite it in bash.
|--- SNIP
Umm, yes it is.
For if( i == 1 && j == 2) C reads that as if the evaluation (i is the same as 1) returns a success then evaluate (j is the same as 2). If this returns a success then execute the satements in the {}.
For an if statement in bash an and list using && will work in the same way. In fact the man page talks about && as a logical operator if you read a bit further down.
Sorry, that was rather off topic.
I would reccomend looking at the page http://steve-parker.org/sh/sh.shtml if you are in need of a tutorial on bash.
thanks for all the help.
i change Filess=$Filess $a
to Filess="$Filess $a"
and it worked. :)