Recycle Bin Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Recycle Bin Script
# 1  
Old 05-21-2009
Recycle Bin Script

Hello,

I have having problems with an assignment and am pretty desperate. My assignment is to create a shell script that does a Recycle_Bin tasks. You can only open this with PuTTY software or Knoppix. Perhaps on other software that are able to read linux language.

My part is stuck in accepting the date values and use those values into the next command based on which option the user selects.

recycle_bin [ -dyymm ] [ -yyy ] [ -mmm ] [-h] [-c] [-v] [directory]


Have enclosed details of my assignment below and the code that i have done so far in a following post.


Thanks in advance for any help recieved





Details of the Assignment are as follows:
The aim of this assignment is to develop a shell script (Bourne Shell syntax) which meets the following specification.

Develop a script which performs the function of a recycle bin.
However, this recycle bin utility takes a date as an argument and a directory and moves all those files in that specified directory that are not modified after the specified date, to a directory called recycle under your home directory.
In other words, all those files which are older than the specified date are moved to the recycle directory.
Of course, if the recycle directory does not exist, then the script should automatically create one, possibly with a message to the user.
The date and the directory name may be specified in a variety of formats as shown below.
However, if the directory is not specified, then use the current working directory.
In addition to these arguments, there are other valid arguments that can be specified to the script
whose meaning is described in the following.

Usage:
recycle_bin [ -d yymm ] [ -y yy ] [ -m mm ] [-h ] [ -c ] [ -v ] [directory]
OR
recycle_bin [ -dyymm ] [ -yyy ] [ -mmm ] [-h ] [ -c ] [ -v ] [ directory ]

The difference between the above two syntax is the way a value to an argument is
specified. In the first form the argument and the value are separated by one or more space or tab. Choose one of these syntax for implementation (choose the one that is easy to implement!).

The semantics of the options are:
• A date can be specified either as -d yymm (year and month in digits, e.g. 0903) or, -y yy
(year) or -m mm (month). The current year will be used, if year is not specified (namely when
-y or -d option is not specified). Similar assumption can be made for month, if required. Also
assume that year and month specifications are independent.
2 of 4
• -h option - head option, if specified will display the first 5 lines of the file that will be moved
to the recycle directory. Optionally after displaying the top 5 files, you can ask the user to
confirm the move (Microsoft style).
• -c option prints a final count of the number of files that is moved to the recycle directory.
• -v option invokes the script in verbose mode - it lists the name and the date of last
modification for each of the file that is being moved (see the examples below).
• -x option (no value to this option) prints one line on how to use the script (basically listing
the above syntax ).

Of course a user need not specify all the options while invoking the script, in which case, you need to assume default values for the missing options. Clearly state your default value for each of the options for your script.

Examples (In the following examples, the command is given in italics and the output
in bold):

$ recycle_bin -y08 -v UnixPrograming
or
$ recycle_bin -y 08 -v UnixProgramming

(Move files which are modified before March 2008,
assuming March is the current month as -m option is not
specified from the UnixProgramming directory - which has
to be a sub-directory of the current directory and print
the last modification of each of the file that is movedbecause
of -v option)

exercise1: modified 2007 MAY moved
trial: modified 2001 JAN moved
core: modified 2003 FEB moved
exercise5: modified 2004 DEC moved

$ recycle_bin -d0902 -c Tutorial

(Non-verbose mode, but display a count of files moved)

10 files moved

$ recycle_bin -m02 -h -c

(same as above + display top 5 lines of each file that is moved)
file1: modified 2003 JAN
This is a test file
It does not contain any useful information
Created to practice vi editing
3 of 4
(2 more lines will be displayed, if exists)
move file1 [y/n]? y
temp.c: modified 2006 JAN
/* Checking the character operations */
int main()
{
char c;
move temp.c [y/n]? y
2 files moved
$ recycle_bin -x
Usage: recycle_bin [ -d yymm ] [ -y yy ] [ -m mm ]
[-h ] [ -c ] [ -v ] [ directory ]
$



Testing and evaluation:
You need to devise a test plan to test the script. For each test data, you need to specify which
part of the script will be tested, what action/output is expected and what was actually outputted.
Also you need to justify that your test plan has tested your program fully (all the parts of the
script).
In order to test your program, you need to create some dummy files with various creation dates.
You can use the touch command to change the modification date of a file. See the manual
page for touch.
# 2  
Old 05-21-2009
code so far

Code:
#! /bin/sh



#-----------RECYCLE BIN------------

#set default
count=false
verbose=false
dir=`pwd`

#set date format
#month= `date +%m`
#year= `date +%Y`

#date= ` expr $year \*100 + $month `

#user input
in_date=false
in_year=false
in_month=false

#if no argument
if [ $# -lt 1 ]
   then
        echo "Usage: recycle_bin [ -dyymm ] [ -yyy ] [ -mmm ] [-h] [-v] [-c] [-x] [directory]"
fi

#when there is argument
while getopts :d:y:m:shcvs:x: $1
        do
                #create recycle directory
                #mkdir recycle
        case $1 in
                d) #search files by date yymm
                  echo "Files by Date YYMM"
                  date = $OPTARG
                  in_date=true
                  gyear=" ` expr substr $date 3 2` "
                  gmonth=" ` expr substr $date 1 2` "
                  ;;
                y) #search files by year yy
                  echo "Files by Year YY"
                  year = $OPTARG
                  in_year=true
                  yyear=" `expr substr $year 1 2` "
                  ymonth="`date +%m`"
                  ;;
                m) #search files by month mm
                  echo "Files by Month MM"
                  month = $OPTARG
                  in_month=true
                  mmonth=" `expr substr $month 1 2` "
                  myear="`date +%Y`"
                  ;;
                h) #list 5lines of files
                  echo "Files by Lines"
                  headFiles
                  {
                        file= `find $dir -maxdepth 1 -type f -mtime +$day -print`
                        count=0
                  }
                  ;;
                c) #number of files removed
                  echo "Total Number of Files"
                  count=true
                  countFile
                  {
                        if [ count != 0 ]
                           then
                                echo $count files moved
                        fi
                  }
                   ;;
                v) #search by modification
                   #echo "Verbose Option"
                   #verboseM
                   #{
                        #if [ $1 = ]
                   #}
                   echo "File(s) by modification"
                   ;;
                x) #no value
                   echo "Usage: recycle_bin [ -dyymm ] [ -yyy ] [ -mmm ] [-h] [-c] [-v] [directory]"
                   exit 0
                   ;;
        esac
        done


#--------OPTION D



#--------OPTION M



#--------OPTION Y

# 3  
Old 05-21-2009
School work is not allowed here and PMing members asking to get your thread looked at is not going to win you any friends.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recycle bin.

Hi. I've created scripts for a recycle bin that can list, restore and empty it. I only have the problem of deleting two files with the same name. When I do it one file overwrite the other. What could I do to resolve it? The only thing I can think is asking the user to rename file before moving to... (2 Replies)
Discussion started by: ReonarudoB
2 Replies

2. UNIX for Dummies Questions & Answers

Recycle bin on minix 3.2.1?

Hi. I'm started to use minix 3.2.1 recently and I'm trying to create a recycle bin for it. I'm kinda struggling on how to do it. I searched internet and I found scripts created for it but I actually didn't learn how to create scripts in college and I'm not sure if I understand them. I just wanted... (1 Reply)
Discussion started by: ReonarudoB
1 Replies

3. Shell Programming and Scripting

Recycle Jboss server script

Hello, I need help writing a script to restart our Jboss server when it crashes. I am not very good with scripting but here is the basics. 1) I'm hoping to use KornShell 2) The command to stop the Jboss is "/var/opt/HP/ALM/jboss/bin/run.sh stop" 3) I want to verify the jboss is stopped before... (1 Reply)
Discussion started by: Blogger11
1 Replies

4. Shell Programming and Scripting

Recycle Bin

what is recycle bin mode in unix??? (4 Replies)
Discussion started by: arun508.gatike
4 Replies

5. UNIX for Dummies Questions & Answers

Help with my recycle bin code

Hi~ I have a problem with my recycle bin code. #!/bin/bash if test !-d ~/.recyclebin #if recycle bin does not exists then mkdir ~/.recyclebin # then create recycle bin else mv $1 ~/.recyclebin #else move the deleted file in the recycle bin fi so when I... (10 Replies)
Discussion started by: zel2zel
10 Replies

6. Homework & Coursework Questions

UNIX Recycle Bin - restore function

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: A set of Linux shell scripts is required to allow users to ‘remove' files without them really disappearing until... (8 Replies)
Discussion started by: burn88
8 Replies

7. UNIX for Dummies Questions & Answers

fuser: difference with bin/sh and bin/ksh shell script

Hi, I have a problem I don't understand with fuser. I launch a simple shell script mysleep.sh: I launch the command fuser -fu mysleep.sh but fuser doesn't return anything excepted: mysleep: Then I modify my script switching from #!/bin/sh to #!/bin/ksh I launch the command fuser -fu... (4 Replies)
Discussion started by: Peuj
4 Replies

8. Shell Programming and Scripting

intro to UNIX - making a sort-of recycle bin (for fun)

Hello, I'm only taking Intro to UNIX in school right now, so please bear with me. My problem is with a sort-of recycle-bin rig I've created for fun. I'm using Ubuntu 9.04, I am the admin. (only user, actually) of this computer. I'm using this script in ~/.bashrc # if files exist, remove contents... (6 Replies)
Discussion started by: jzacsh
6 Replies

9. Windows & DOS: Issues & Discussions

Path of Recycle Bin on Windows

hello everybody, I am trying to find the path of the Recycle Bin. I know that it's a temporary storage place, but it should have a path that we can refer to. I want to know it because I sometimes use cygwin to work on Windows, and when you delete something with it, it's gone. I just checked... (4 Replies)
Discussion started by: milhan
4 Replies
Login or Register to Ask a Question