LinuxQuestions.org
Visit Jeremy's Blog.
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


Closed Thread
  Search this Thread
Old 03-14-2006, 11:31 AM   #1
Colly McKenna
LQ Newbie
 
Registered: Mar 2006
Posts: 2

Rep: Reputation: 0
Urgent - Duplicate Script File


Hi Guys,

I am having difficulty in getting a duplicate script file running. The criteria for it is listed below:

Produce a well commented script called dupefile that takes some arguments such as those listed below; the script should search a filesystem, from a given start point (set using -s option) and find all duplicate files as per a given criteria (-c option). It presents the output in a variety of formats (-f option) and optionally takes action according to the -a option. The program should also deal with -v, -V and -h options.


The output formats should include generating a "script" containing the duplicate files, one per line, with comments on the line above
and starting with the special sequence #rm -f ( a user can then edit this line by removing the '#' and then execute it). Another output format
will be a .html file containing a form... this only makes sense if we arrange the linux box running the script to also run a webserver
that contains a cgi script with fairly powerful access rights, it will need password access and other safeguards so do not worry too much
about testing the html file - just produce the version listed below. We will be using an embedded webserver in the second assigment.


Note the options below are case sensitive, there must be 1 or more space(s) after a single - option but no spaces in a double -- option

-h or --help Lists help (all other options should be ignored, apart from -v)
-v or --version Gives the version number of the program, like other unix commands
(all other options should be ignored, apart from -h)


-V or --Verbose Output verbose messages to stderr when running, inform the user of where searching, what comparing etc.,
-s pathname
--start=pathname Pathname should be either absolute (beginning with a slash /)
or relative, beginning with a current subfolder or . or ..
Any pathname containing spaces must be enclosed in double or single quotes
-c ns or --criteria=name
-c nsm or --criteria=modtime
-c nsi or --criteria=identical Files should be considered the same if they have the same filename and of same size.
Optionally the time and date of the last modification to the file should be compared IN ADDITION to name and size
Finally a complete byte by byte comparison of the contents can be done, IF FILENAME AND SIZE are the same.
-f t or --format=text




-f h or --format=html
For the text file format create one line for each duplicate file sorted so that identical files occur together.
The text file should start with a line #!/bin/sh (i.e it should be a script) and have its executeable bit set.
Each file should be prefixed by a comment stating its mod time and size
Each line containing a file should begin #rm -f "pathname/filename" The user can then edit the file by removing n-1
# symbols, so if there are three identical files he or she can choose to delete two (one or none) of them.


-a or --action=now If present, disallow -f and -a. output each duplicate pathname and filename. Then output the first and then prompt for
Yes or No, output the second duplicate and prompt for yes or no, if there happen to be three identical files then output the
third and subsequent copies prompting each line for yes or no. Delete each file answered with yes. If the user has not
permission to delete a file then inform him or her
-o filename
--outputfile=filename Specifiy an output filename, the user will add an extension if he or she wishes. If there is no -o then output to stdout


I have started and this is the script so far:

#!/bin/bash


#################################################
# #
# F U N C T I O N S #
# #
#################################################

function help
# This function show the help message which gives
# a brief description of how to use dupefile

{
echo ""
echo "Usage: $0 -h|--help"
echo " or: $0 -v|--version"
exit 1
}


function version
# This function shows the version of dupefile and its author

{
echo ""
echo "dupefile version 1.0"
echo "Written by Colin McKenna"
echo "Course: BEng (Hons) Electroincs & Software"
echo "Student Reg No: 12077102"
echo ""
echo "Warning: Using dupefile may or may not damage you computer"
echo ""
exit 1
}

#################################################
# #
# I N I T A L I S E #
# #
#################################################
show_help=0 # These three variables are flags that
show_version=0 # store information on how the user
sup_errors=0 # wants filecat to behave


# If no arguments are given on the command line, then show the help message
if [ $# -lt 1 ]; then
help
fi
while getopts hv:s: opt # Use get opts to process the options
do # and arguments given on the command line
case "$opt" in
h) show_help=1;; # If arguments are given a variable is created
v) show_version=1;; # which to hold that argument
s) sup_errors=1;;
\?) help;;
esac
done

#################################################

#################################################
# #
# V A L I D A T E A N D #
# P R O C E S S O P T I O N S #
# #
# In this section of the code, the input #
# options that were given in the command #
# line are validated and processed. If #
# invalid options are recieved a specific #
# error message is shown along with the #
# general help message. The program then #
# exits. When valid arguments are recieved #
# the appropriate actions are taken with #
# regard to them. #
# #
#################################################

# Begin to process the command line arguments
# Firstly check if the user wants to see the help message
if [ $show_help -eq 1 ]; then
help
# If not, check to see if they requested to see the version number
elif [ $show_version -eq 1 ]; then
version
fi
# If errors are to be suppressed, then redirect them to /dev/null
if [ $sup_errors -eq 1 ]; then
exec 2>/dev/null
fi


Any help would be greatly appreciated as i am stuck!!

Many thanks.

Colly
 
Old 03-14-2006, 12:12 PM   #2
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 10, Linux Mint 11
Posts: 148

Rep: Reputation: 18
Boy, are you going to get blasted for asking a homework question here ...

But as you have most of the script done, and just can't get it to run (VERY vague), I will mention that when you are defining your functions improperly. It should look like


Code:
Function_Something()
{
 echo in the function
}
Not

Code:
Function Function_Something
{
 echo in the function
}
I didn't notice anything else that was glaringly obvious as far as being wrong.
 
Old 03-14-2006, 12:56 PM   #3
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 61
Quote:
Boy, are you going to get blasted for asking a homework question here ...
...not to mention putting Urgent in the title. It may be urgent to you, colly, but it ain't to us. OTOH, it appears you have done a significant amount of work on your own, ... that's good.
 
Old 03-14-2006, 09:31 PM   #4
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 57
Quote:
Boy, are you going to get blasted for asking a homework question here ...
Not in this case. Putting urgent in the title is going to piss a certain moderator off (yeah, you know who you are!) but this dude has actually put in some effort and done some work. People wanting someone to do their homework need their kneecaps kicked in but asking for help, well I was under the impression that was the whole point of this site

It does however, look like you haven't done any of the *actual* work. The uhh, help and version display is done but nothing else. Chances are that is the reason it isn't running properly although I admit I'm no expert. If you want help, the -s, -c, -f, and -a options can all be done by find. 'man find' for more info there.
 
Old 03-14-2006, 09:36 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I don't mind helping with homework if there is evidence that the OP has actually done some work already.
What we might prefer is that these student TELL US that is homework, what school, etc. Might make us a bit more friendly.

Classic case was maybe a month ago---assignment simply pasted into a thread. Help was not flowing freely....
 
Old 03-15-2006, 07:54 AM   #6
Colly McKenna
LQ Newbie
 
Registered: Mar 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Kind helpful people

Last edited by Tinkster; 03-16-2006 at 02:17 AM. Reason: mod edit
 
Old 03-15-2006, 04:15 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Until one of this forums mods deals with you and your thread I'd like to take the opportunity to say that looking at your script you should be intelligent enough to realise venting your frustration this way does not help you or this community. Please edit your post to reflect the fact that you would like to remain a part of this community and to show your respect for your fellow LQ members. Please read the LQ Rules (which you agreed to adhere to when you signed up).
 
Old 03-15-2006, 06:14 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Concur with unSpawn ...
 
Old 03-16-2006, 02:18 AM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Homework A N D swearing?

I don't think so - closed.
 
  


Closed Thread


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
duplicate directory tree for only certain file types curmudgeon42 Linux - Software 13 01-22-2005 03:38 PM
Why when editing files does Linux create a duplicate file with a ~ in the extension? bugbite99 Linux - General 6 01-17-2005 03:21 PM
editor saves duplicate file with tilde after it smaudlin Red Hat 2 12-29-2004 05:37 PM
duplicate file names? BajaNick Linux - Software 3 08-25-2003 05:00 PM
How 2 find a duplicate word in a text file cowardnewbie Programming 1 09-17-2001 12:57 AM


All times are GMT -5. The time now is 01:53 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration