LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-05-2007, 05:23 PM   #1
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Rep: Reputation: 15
newbie scripting: Writeing a Shell script Backup Program,


ok i am a newbie(in my opinion but according to some i am not)
and i am writing a shell script for comparing 2 dirs for that will print the differences between the 2 dirs to the shell.
I think i have the rough idea on how to do this but i am still not sure.
what i need is the shell equivalent to the following python code:
Code:
#!/usr/bin/env python
dirone = raw_input("what is the first dir name?")
print "Setting..." dirone
dirtwo = raw_input("what is the second dir name?")
print "Setting..." dirtwo
outputdir = raw_input("what is the output dir?")
where dirone and dirtwo are environment variables for use in a late part of script. I have trawled the web and this forum and found nothing on this so after a long time looking i have decided to post a thread on it.
here is the shell script so far:
Code:
#!/bin/sh
<insert code here>
cd $dirone
find > $outputdir/dirone.txt
cd $dirtwo
find > $outputdir/dirtwo.txt
thanks in advance
HoodedManWithSythe(Timothy Armstrong)

Last edited by hoodedmanwithsythe; 06-10-2007 at 08:23 AM.
 
Old 03-06-2007, 09:47 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
http://tldp.org/LDP/abs/html/index.html
 
Old 03-06-2007, 05:01 PM   #3
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
thank that helped alot

Thanks that helped a lot as is follows a very similar layout as the one i learned python fromand so i found it easy to follow here is the script if any one wishes to use it.
I will be making a more useful program in a while that will also handle the backup and restore aspect of things as well as this folder comparator.
if i was to redo this from scratch i would consider writing it in assembly but this would be far more difficult even if it meant that it was compatible with more systems (rather than just ones with /bin/sh).
again thanks for the help and i will possibly be asking more questions in this topic for the other part of this project.
Code:
#!/bin/sh
# This script was written for the purpose of compairing 2 folders so as you can check to see what files 
# are present in the first compaired to those in the second.
# Showing this by the use of the </> arrows. < meaning in the first folder but not the second folder
# and > meaning in the second folder but not the first folder.
# outputting to a text file named Output.txt

#start of file
#setting intial variables
outputfile=Output.txt
dironefile=dirone.txt
dirtwofile=dirtwo.txt
#requesting optional variables
echo "What is the Output Directory(full Dir Name Not the Local)? " #setting an optional variable as it is inputed by the user (echo "<place text here>" ; read <env variable> is used as an equivilent to <env variable>=raw_input("<place text here>") as in python)
read outputdir
echo "Setting the Output Directory to $outputdir. " #echo is the shell equivilent to print "" in python
echo Set to $outputdir Dir 
echo "What is the First Directory For Compairing(Full Dir Name Not the Local)? "
read dirone
echo "Setting the First Directory for Compairing to to $dirone. "
echo Set to $dirone .
echo "What is the Second Directory For Compairing(full Dir Name Not the Local)? "
read dirtwo
echo "Setting the Second Directory for Compairing to to $dirone. "
echo Set to $dirtwo .
cd $dirone #moving to a directory
find > $outputdir/$dironefile #brutaly useing the 'find' command to get a files list with '>' redirecting the output to a file (as set by environ ment variable at start)
cd $dirtwo
find > $outputdir/$dirtwofile
cd $outputdir
diff $dironefile $dirtwofile > $outputdir/$outputfile #useing diff in correct mannor to find all the diferences betwean the two directories
cat $outputdir/$outputfile #showing the output of the program on the screen
 
Old 03-09-2007, 12:36 PM   #4
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
ok a quick update and a question. first the question how do I get a current dir pure location from shell with out hardwiring in to the program. and can some one please move this thread to the Non-*NIX Forums>Programming as i think it will serve more purpose there.
and the update to the program so far
Code:
#!/bin/sh
# This script was written for the purpose of compairing 2 folders so as you can check to see what files 
# are present in the first compaired to those in the second.
# Showing this by the use of the </> arrows. < meaning in the first folder but not the second folder
# and > meaning in the second folder but not the first folder.
# outputting to a text file named Output.txt

#start of file
#setting intial variables
outputfile=Output.txt
dironefile=dirone.txt
dirtwofile=dirtwo.txt
#requesting optional variables
#setting an optional variable as it is inputed by the user (echo "<place text here>" ; read <env variable> is used as an equivilent to <env variable>=raw_input("<place text here>") as in python)
#echo is the shell equivilent to print "" in python

function1 ()
{

o1a="What is the Output Directory(Full Dir Name Not the Local)?"
o1="echo "
o2="read OPdir"
o3a="Setting the Output Directory to "
o4a="Set Output Dir as "

$o1$o1a ; $o2 ; $o1$o3a$OPdir ; $o1$o4a$OPdir

}

function1

function2 ()
{

fi1a="What is the First Directory For Compairing(Full Dir Name Not the Local)? "
fi1="echo "
fi1b="read FIP1dir"
fi1c="Setting First Directory as "
fi1d="Set Frist Directory as "

$fi1$fi1a ; $fi1b ; $fi1$fi1c$FIP1dir ; $fi1$fi1d$FIP1dir

}

function2

function3 ()
{

fi2a="What is the Second Directory For Compairing(full Dir Name Not the Local)? "
fi2b="echo "
fi2c="read FIP2dir"
fi2d="Setting the Second Dir as "
fi2e="Set Second Dir as "

$fi2b$fi2a ; $fi2c ; $fi2b$fi2d$FIP2dir ; $fi2b$fi2e$FIP2dir

}

function3

cd $dirone #moving to a directory
dir -1 > $outputdir/$dironefile #brutaly useing the 'find' command to get a files list with '>' redirecting the output to a file (as set by environ ment variable at start)
cd $dirtwo
dir -1 > $outputdir/$dirtwofile
cd $outputdir
diff $dironefile $dirtwofile > $outputdir/$outputfile #useing diff in correct mannor to find all the diferences betwean the two directories
cat $outputdir/$outputfile #showing the output of the program on the screen
 
Old 03-09-2007, 12:42 PM   #5
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
You mean the pwd command?
 
Old 03-09-2007, 12:43 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved per OPs request.

P.S.: Next time you want your thread moved report it :}
I don't think that all posts are being read by mods.
 
Old 03-09-2007, 02:00 PM   #7
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
Thanks

Quote:
You mean the pwd command?
yes thank you that helps immediately now i can finish this section of the script.
Quote:
Moved per OPs request.

P.S.: Next time you want your thread moved report it :}
I don't think that all posts are being read by mods.
I will do thanks.

By-the-way I will be expanding this project in to a full backup utility and if I have time between my upcoming exams i will possible convert to python because I can write with python and have experience in TK (Tkinter libraries) based scripts and so generate a full python based GUI. But only if i have time.
The reason i started this project was cause someone i know wants a backup util similar to syncback that will run on Linux and he doesn't like using any of the current ones.
 
Old 03-09-2007, 02:12 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Do you know which current ones he has evaluated? :} "Any"
sounds a bit much, given the multitude out there.


Cheers,
Tink
 
Old 03-09-2007, 02:40 PM   #9
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Quote:
Originally Posted by Tinkster
Do you know which current ones he has evaluated? :} "Any"
sounds a bit much, given the multitude out there.


Cheers,
Tink
Yeah, really. The problem you originally posted (comparing two directories and sending the differences to the shell) can be done with the diff command. The overall script looks like it could be easily accomplished with rsync.
 
Old 03-09-2007, 05:19 PM   #10
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
true but as i say i am a newbie and so i don't know a what this rsync command is and if you look i do use the diff command, not in the way you are thinking i am sure but i am just comparing my intermediate python/tk knowledge and dragging this into a basic backup program for a friend.
and I admit I only write programs as I need them and I don't actually even consider it a hobby of mine as I only do it about once or twice a year.
and so my knowledge and understanding stays pretty low.
I actually work as a digital 3d artist(when not at collage) and don't even touch the programming side of things in a work environment cause i don't need to. I don't wish to sound ungrateful but it's not my area and i can't keep tabs on more than a few ways of doing things especialy considering i don't do this often and as the time i am not in collage i am working as a digital 3d artist i don't have time to take this up as a hobby.
so unless this rsync command and way of useing diff is going to speed up the way that things are currently progressing then i would rather that you didn't try to explain it to me as i will end up just ballsing it up as i am not the programmer type and i can't work the way you guys do and i just wont understand and you will end up just getting pissed off with trying to explain something to me that might as well be quantum pyhsics for all i will understand of it.
again i wish not to sound ungrateful but i just won't get what you are trying to explain to me if it doesn't follow my line of thinking or needs a complete rewrite of the program so far
 
Old 03-09-2007, 05:58 PM   #11
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
No, I'm just suggesting that you (or your friend) install rsync and use that for incremental backups. Just trying to save you some time and heartache, but if you want to write a script that's fine too.
 
Old 03-09-2007, 07:14 PM   #12
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
well thanks but he just said on skype that rsync is one that he has already tried and doesn't like.
what he wants is a program the matches his daily needs to a point not a program that just "does the job after a bit of hammering to fit the slot"
any way the final code is done for the comparitor part now anyway.
I just finnished it
Code:
#!/bin/sh
# This script was written for the purpose of comparing 2 folders so as you can check to see what files 
# are present in the first compared to those in the second.
# Showing this by the use of the </> arrows. < meaning in the first folder but not the second folder
# and > meaning in the second folder but not the first folder.
# outputting to a text file named Output.txt

#start of file
#setting intial variables
lcldir="`pwd`"
outputfile=Output.txt
dironefile=dirone.txt
dirtwofile=dirtwo.txt
#requesting optional variables
#setting an optional variable as it is inputed by the user (echo "<place text here>" ; read <env variable> is used as an equivilent to <env variable>=raw_input("<place text here>") as in python)
#echo is the shell equivilent to print "" in python

function1 ()
{

echo -n "What is the Output Directory(Full or Local Dir Names)?" ; read OPdir
echo "Setting the Output Directory to $OPdir "
echo "Set Output Dir as $OPdir"
echo -n "hit enter to continue" ; read HTENTER
mnu=""

function7

}


function2 ()
{

echo -n "What is the First Directory For Compairing(Full or Local Dir Names)?" ; read FIP1dir
echo "Setting First Directory as $FIP1dir"
echo "Set Frist Directory as $FIP1dir"
mnu=""


function4

}


function3 ()
{

echo -n "What is the Second Directory For Compairing(Full or Local Dir Names)? " ; read FIP2dir
echo "Setting the Second Dir as $FIP2dir"
echo "Set Second Dir as $FIP2dir"
mnu=""


function5

}


function4()
{

echo "Moving to First Dir"
cd $FIP1dir #moving to a directory
echo "Saving file list at $OPdir/$dironefile"
find > $OPdir/$dironefile
echo "Moveing Back to Initial Directory"
cd $lcldir #moveing back to original directory
echo -n "hit enter to continue" ; read HTENTER
mnu=""


function7

}

function5()
{

echo "Moving to Second Dir"
cd $FIP2dir
echo "Saving file list at $OPdir/$dirtwofile"
find > $OPdir/$dirtwofile
echo "Moveing Back to Initial Directory"
cd $lcldir
echo -n "hit enter to continue" ; read HTENTER
mnu=""


function7

}

function6()
{

echo "Moving to Output Dir if it is Not Initial Dir"
cd $OPdir
echo "Comparing File Lists"
diff $OPdir/$dironefile $OPdir/$dirtwofile > $OPdir/$outputfile #useing diff in correct mannor to find all the diferences betwean the two directories
echo "Here is a list of files are in one dir but not in the other,"
cat $OPdir/$outputfile #showing the output of the program on the screen 
echo "If the 'Arrow' before the file name points LEFT then the file is in the First dir and not the Second Dir."
echo "If it points RIGHT then the file is in the Second Dir but not in the First Dir."
echo -n "hit enter to continue" ; read HTENTER
mnu=""


function7

}

function7a()
{
clear
echo "Menu:"
echo "1.Set The Output Directory (if it isn't the current directory) "
echo "2.Set The First Directory For Comparing"
echo "3.Set The Second Directory For Comparing"
echo "4.Compare Directories"
echo "5.Exit"
echo -n "Please Select a Menu Item:" ; read mnu
function7
clear
}


function7()
{

if [ "$OPdir" = "" ]
then
   OPdir=$lcldir 
fi

if [ "$mnu" = "" ]
then
   function7a
elif [ "$mnu" = "1" ] 
then
   function1
elif [ "$mnu" = "2" ] 
then
   function2
elif [ "$mnu" = "3" ] 
then
   function3
elif [ "$mnu" = "4" ] 
then
   function6
elif [ "$mnu" = "5" ]
then
   exit
clear
else
   function7a
fi

}
function7
Feel Free to use it in any way you wish
 
Old 06-10-2007, 07:54 AM   #13
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
new version

ok so this thread has been inactive for a while but alas I have done some more work on the program so here is the new code.
P.S. at the moment crashes on conversion when it doesn't have access rights to a file.
Code:
#!/bin/sh
# This script was written for the purpose of comparing 2 folders so as you can check to see what files 
# are present in the first compared to those in the second.
# Showing this by the use of the </> arrows. < meaning in the first folder but not the second folder
# and > meaning in the second folder but not the first folder.
# outputting to a text file named Output.txt
#setting an optional variable as it is inputed by the user (echo "<place text here>" ; read <env variable> is used as an equivilent to <env variable>=raw_input("<place text here>") as in python)
#echo is the shell equivilent to print "" in python
#start of file
#setting intial variables
lcldir="`pwd`"
outputfile=Output.txt
dironefile=dirone.txt
dirtwofile=dirtwo.txt

if [ "$OPdir" = "" ]
then
   OPdir=$lcldir 
fi

function14()
{
if [ "$scanmnu" = "1" ] 
then
   function4
elif [ "$scanmnu" = "2" ] 
then
   function5
elif [ "$scanmnu" = "3" ]
then
   function9
elif [ "$scanmnu" = "4" ] 
then
   function0
else
   function13
fi
}

function13()
{
clear
echo "Scan Menu:"
echo "1, Scan First Dir"
echo "2, Scan Second Dir"
echo "3, Compair Scans"
echo "4, Back to Main Menu"
echo "Note: Both scans will output a file list called either dirone.txt or dirtwo.txt."
echo "These files must be in the same output dir that is set when doing the compair otherwise the compair WILL NOT WORK."
echo "After compairing the 2 files will be deleted and replaced by a single file called Output.txt which will be a" 
echo "complete copy of what appears on the screen."
echo -n "Please Select a Menu Item:" ; read scanmnu
mnu=""
mainmnu=""
function14
}

function0 ()
{
clear
echo "DirectComparison 1.0.7.06"
echo "Main Menu:"
echo "1, Compare Directories"
echo "2, Setup"
echo "3, Exit"
echo -n "Please Choose a Menu Item:" ; read mainmnu
scanmnu=""
mnu=""
function8
}


function1 ()
{
echo -n "What is the Output Directory(Full or Local Dir Names)?" ; read OPdir
echo "Setting the Output Directory to $OPdir "
echo "Set Output Dir as $OPdir"
echo -n "hit enter to continue" ; read HTENTER
mnu=""
function7
}


function2 ()
{
echo -n "What is the First Directory For Compairing(Full or Local Dir Names)?" ; read FIP1dir
echo "Setting First Directory as $FIP1dir"
echo "Set Frist Directory as $FIP1dir"
mnu=""
function7
}


function3 ()
{
echo -n "What is the Second Directory For Compairing(Full or Local Dir Names)? " ; read FIP2dir
echo "Setting the Second Dir as $FIP2dir"
echo "Set Second Dir as $FIP2dir"
mnu=""
function7
}


function4()
{
echo "Moving to First Dir"
cd $FIP1dir #moving to a directory
echo "Saving file list at $OPdir/$dironefile"
find > $OPdir/$dironefile
echo "Moveing Back to Initial Directory"
cd $lcldir #moveing back to original directory
echo -n "hit enter to continue" ; read HTENTER
scanmnu=""
function13
}

function5()
{
echo "Moving to Second Dir"
cd $FIP2dir
echo "Saving file list at $OPdir/$dirtwofile"
find > $OPdir/$dirtwofile
echo "Moveing Back to Initial Directory"
cd $lcldir
echo -n "hit enter to continue" ; read HTENTER
scanmnu=""
function13
}

function6()
{
echo "Moving to Output Dir if it is Not Initial Dir"
cd $OPdir
function9
}

function7a()
{
clear
echo "Settings:"
echo "1.Set The Output Directory (if it isn't the current directory) "
echo "2.Set The First Directory For Comparing"
echo "3.Set The Second Directory For Comparing"
echo "4.Back to Main Menu"
echo -n "Please Select a Menu Item:" ; read mnu
scanmnu=""
mainmnu=""
function7
}


function7()
{
if [ "$mnu" = "" ]
then
   function7a
elif [ "$mnu" = "1" ] 
then
   function1
elif [ "$mnu" = "2" ] 
then
   function2
elif [ "$mnu" = "3" ] 
then
   function3
elif [ "$mnu" = "4" ]
then
   function0
clear
else
   function7a
fi
}

function8()
{
if [ "$mainmnu" = "" ]
then
   function0
elif [ "$mainmnu" = "1" ] 
then
   function14
elif [ "$mainmnu" = "2" ] 
then
   function7
elif [ "$mainmnu" = "3" ] 
then
   clear
   exit
else
   function0
fi
}
function8

function9()
{
if [ "$FIP1dir" = "" ]
then
   clear
   echo "Please Run Setup, There is no Primary Directory set for comparing"
   echo -n "Would you like to enter the Setup now?(default:Yes)" ; read YN1
   function11
else
   function10
fi
}

function10()
{
if [ "$FIP2dir" = "" ]
then
   clear
   echo "Please Run Setup, There is no Secondary Directory set for comparing"
   echo -n "Would you like to enter the Setup now?(default:Yes)" ; read YN1
   function11
else
   function12
fi
}

function11()
{
if [ "$YN1" = "" ]
then
   mnu=""
   function7a
elif [ "$YN1" = "Yes" ]
then
   mnu=""
   function7a
elif [ "$YN1" = "Y" ]
then
   mnu=""
   function7a
elif [ "$YN1" = "y" ]
then
   mnu=""
   function7a
elif [ "$YN1" = "yes" ]
then
   mnu=""
   function7a
else
   function0
fi
}

function12()
{
clear
echo "Comparing File Lists"
diff $OPdir/$dironefile $OPdir/$dirtwofile > $OPdir/$outputfile #useing diff in correct mannor to find all the diferences betwean the two directories
echo "Here is a list of files are in one dir but not in the other,"
cat $OPdir/$outputfile #showing the output of the program on the screen 
echo "If the 'Arrow' before the file name points LEFT then the file is in the First dir and not the Second Dir."
echo "If it points RIGHT then the file is in the Second Dir but not in the First Dir."
echo -n "hit enter to continue" ; read HTENTER
rm $OPdir/$dironefile
rm $OPdir/$dirtwofile
scanmnu=""
function8
}
I realize that my functions don't follow the number order but if function14 and function13 are not at the start then it comes up with a command doesn't exist error so i am leaving things as they are for now.

I need to know how to save the settings(that are held in variables at the moment)
so as they can be loaded again.
I was thinking XML but I am not sure how to retrieve the variables after I have saved them.
note. I am trying to run this as a NO DEPENDENCY PROGRAM. so please non of the XSH or similar. as this will mean that users will need to install things if they don't already have them.

edit: crashes on compare full stop I will fix this and swap the code for a working one within 30 mins.
edit: I did the above and then I went further, doing the save settings and a bit more still. so the below code is the finished code for now thanks for any help, suggestions are always welcome.

new code:
Code:
#!/bin/sh
# This script was written for the purpose of comparing 2 folders so as you can check to see what files 
# are present in the first compared to those in the second.
# Showing this by the use of the </> arrows. < meaning in the first folder but not the second folder
# and > meaning in the second folder but not the first folder.
# outputting to a text file named Output.txt
#setting an optional variable as it is inputted by the user (echo "<place text here>" ; read <env variable> is used as an equivalent to <env variable>=raw_input("<place text here>") as in python)
#echo is the shell equivalent to print "" in python
#start of file
#setting initial variables
lcldir="`pwd`"
outputfile=Output.txt
dironefile=dirone.txt
dirtwofile=dirtwo.txt
echo -e "\033[44;37;2m"
loccheck="`ls | grep cmpdirs.sh`"
if [ "$OPdir" = "" ]
then
   OPdir=$lcldir 
fi

LocationCheck()
{
if [ "$loccheck" = "" ]
then
   echo -e "\033[0m "
   echo "program must be run from the directory that contains it please cd to that directory and try again"
   echo -n "Press the Enter Key to exit" ; read HTENTER
   clear
   exit
fi
}
LocationCheck

ScanMenuControler()
{
if [ "$scanmnu" = "1" ] 
then
   CheckPri
elif [ "$scanmnu" = "2" ] 
then
   CheckSec
elif [ "$scanmnu" = "3" ]
then
   Compare
elif [ "$scanmnu" = "4" ] 
then
   MainMenu
else
   ScanMenu
fi
}

ScanMenu()
{
clear
echo 
DirsAre
echo "                                                                                "
echo "Scan Menu:                                                                      "
echo "1, Scan First Dir                                                               "
echo "2, Scan Second Dir                                                              "
echo "3, Compair Scans                                                                "
echo "4, Back to Main Menu                                                            "
echo
echo -e "\033[5mNOTE:\033[0m\033[44;37;2m Both scans will output a file list called either dirone.txt or dirtwo.txt."
echo "These files must be in the same output dir that is set when doing the compair   "
echo "otherwise the compair WILL NOT WORK. After compairing there will be a new file  "
echo "called Output.txt which will be a complete copy of the file list that appears "
echo "on the screen."
echo
echo -n "Please Select a Menu Item:" ; read scanmnu 
echo

mnu=""
mainmnu=""
ScanMenuControler
}

Compare()
{
clear
echo "Comparing File Lists                                                             "
diff $OPdir/$dironefile $OPdir/$dirtwofile > $OPdir/$outputfile #using diff in correct mannor to find all the differences betwean the two directories
echo "Saved as Output.txt in the output directory."
echo "Here is a list of files are in one dir but not in the other,"
cat $OPdir/$outputfile #showing the output of the program on the screen 
echo "If the 'Arrow' before the file name points LEFT then the file is in the First dir and not the Second Dir."
echo "If it points RIGHT then the file is in the Second Dir but not in the First Dir."
echo  -e "\033[5mNOTE:\033[0m\033[44;37;2m if a file doesn't appear in the Output but is in the file lists then it is"
echo "in both directories."
echo -n "hit enter to continue" ; read HTENTER
scanmnu=""
ScanMenu
}

MainMenu()
{
clear
echo "DirectComparison 1.0.7.06"
echo
DirsAre
echo
echo "Main Menu:"
echo "1, Compare Directories"
echo "2, Setup"
echo "3, Exit"
echo -n "Please Choose a Menu Item:" ; read mainmnu
echo
scanmnu=""
mnu=""
MainMenuControler
}


SetOutput()
{
echo -n "What is the Output Directory(Full or Local Dir Names)?" ; read OPdir
echo "Setting the Output Directory to $OPdir "
echo "Set Output Dir as $OPdir"
echo -n "hit enter to continue" ; read HTENTER
mnu=""
SetupMenu
}


SetFirst()
{
echo -n "What is the First Directory For Compairing(Full or Local Dir Names)?" ; read FIP1dir
echo "Setting First Directory as $FIP1dir"
echo "Set First Directory as $FIP1dir"
mnu=""
SetupMenu
}


SetSecond()
{
echo -n "What is the Second Directory For Compairing(Full or Local Dir Names)? " ; read FIP2dir
echo "Setting the Second Dir as $FIP2dir"
echo "Set Second Dir as $FIP2dir"
mnu=""
SetupMenu
}


ScanFirst()
{
echo "Moving to First Dir"
cd $FIP1dir #moving to a directory
echo "Saving file list at $OPdir/$dironefile"
find > $OPdir/$dironefile
echo "Moving Back to Initial Directory"
cd $lcldir #moving back to original directory
echo -n "hit enter to continue" ; read HTENTER
scanmnu=""
ScanMenu
}

ScanSecond()
{
echo "Moving to Second Dir"
cd $FIP2dir
echo "Saving file list at $OPdir/$dirtwofile"
find > $OPdir/$dirtwofile
echo "Moving Back to Initial Directory"
cd $lcldir
echo -n "hit enter to continue" ; read HTENTER
scanmnu=""
ScanMenu
}

Compair()
{
echo "Moving to Output Dir if it is Not Initial Dir"
cd $OPdir
function9
}

SetupMenu()
{
clear
echo
DirsAre
echo
echo "Setup Menu:"
echo "1.Set The Output Directory (if it isn't the current directory) "
echo "2.Set The First Directory For Comparing"
echo "3.Set The Second Directory For Comparing"
echo "4.Save(Ony run this if you intend on useing the program under the same" 
echo "setup more than once ie once on one machine and again on another or "
echo "once before backup and once after restore to see if files have copied correctly)"
echo "5.Load(Only run this if you have a saved config, or program will crash)"
echo "6.Back to Main Menu"
echo -n "Please Select a Menu Item:" ; read mnu
scanmnu=""
mainmnu=""
SetupMenuControler
}


SetupMenuControler()
{
if [ "$mnu" = "1" ] 
then
   SetOutput
elif [ "$mnu" = "2" ] 
then
   SetFirst
elif [ "$mnu" = "3" ] 
then
   SetSecond
elif [ "$mnu" = "4" ]
then
   RunSave
elif [ "$mnu" = "5" ]
then
   Load
elif [ "$mnu" = "6" ]
then
   MainMenu
clear
else
   SetupMenu
fi
}

MainMenuControler()
{
if [ "$mainmnu" = "1" ] 
then
   ScanMenu
elif [ "$mainmnu" = "2" ] 
then
   SetupMenu
elif [ "$mainmnu" = "3" ] 
then
   echo -e "\033[0m"
   clear
   exit
else
   MainMenu
fi
}

DirsAre()
{
OpIs
PriIs
SecIs
}

OpIs()
{
echo "The Output Directory is set to: $OPdir"
}

PriIs()
{
if [ "$FIP1dir" = "" ]
then
   echo "There is no First Directory set"
else
   echo "The First Directory is set to: $FIP1dir"
fi
}

SecIs()
{
if [ "$FIP2dir" = "" ]
then
   echo "There is no Second Directory set"
else
   echo "The Second Directory is set to: $FIP2dir"
fi
}

CheckPri()
{
if [ "$FIP1dir" = "" ]
then
   clear
   echo "Please Run Setup, There is no Primary Directory set for comparing"
   echo -n "Would you like to enter the Setup now?(default:Yes)" ; read YN1
   YesNo
else
   ScanFirst
fi
}

CheckSec()
{
if [ "$FIP2dir" = "" ]
then
   clear
   echo "Please Run Setup, There is no Secondary Directory set for comparing"
   echo -n "Would you like to enter the Setup now?(default:Yes)" ; read YN1
   YesNo
else
   ScanSecond
fi
}

YesNo()
{
if [ "$YN1" = "" ]
then
   mnu=""
   SetupMenu
elif [ "$YN1" = "Yes" ]
then
   mnu=""
   SetupMenu
elif [ "$YN1" = "Y" ]
then
   mnu=""
   SetupMenu
elif [ "$YN1" = "y" ]
then
   mnu=""
   SetupMenu
elif [ "$YN1" = "yes" ]
then
   mnu=""
   SetupMenu
else
   ScanMenu
fi
}

SaveBackend()
{
echo "#!/bin/sh"
echo -n "export FIP1dir=" ; echo $FIP1dir
echo -n "export FIP2dir=" ; echo $FIP2dir
echo -n "export OPdir=" ; echo $OPdir
echo 'export save="done"'
echo './cmpdirs.sh'
}

SaveFrontend()
{
export save=""
SaveBackend > $OPdir/cmpdirs.cfg
chmod a=rwx $OPdir/cmpdirs.cfg
RunSave
}

RunSave()
{
if [ "$save" = "done" ]
then
   clear
   echo "Saved"
   echo -n "hit enter to continue" ; read HTENTER
else
   SaveFrontend
fi
}

Load()
{
./cmpdirs.cfg
}
MainMenu
any help on the variable saveing would be greatly appreciated
thanks
As I have said be for all help is very much appreciated

Last edited by hoodedmanwithsythe; 06-10-2007 at 04:58 PM.
 
  


Reply



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
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
Shell scripting: How to redirect output from within the script itself? Arodef Linux - General 4 05-23-2006 07:30 PM
Shell scripting help -- newbie rnj Linux - Newbie 1 09-12-2005 12:08 AM
Shell Scripting problems (newbie) yawgmoth81 Programming 11 02-24-2003 02:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:46 PM.

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
Open Source Consulting | Domain Registration