akshay
07-31-2002, 09:10 AM
Hey Guys....
I am really stuck here i am trying to practice shell scripting and i am very new to linux.
Here i have a code and it is not working can any one suggest me where is the problem in the code and rectify the code i would be very very much grateful to you.
1 #!/bin/bash
2 # Script: delete.sh
3 # Author: Kieren Jamieson
4 # Purpose: Provides a safe alternative to "rm" as
5 # each file is moved to a "trashcan" folder
6 # before it is deleted.
7 # Flies are "cleaned" each time delete is run (
8 # three days old). Files are stored by their original
12 Usage: delete.sh <file1> [file2] ... [filen]
13 $JUNKDIR=/tmp/trashcan.$LOGNAME
15 DATE='date +%Y-%m-%d_%H%M%S'
16
17 if [ not -d $JUNKDIR ]
18 then
19 echo "$JUNKDIR does not exist, creating..."
20 mkdir -p $JUNKDIR
21 if [ $? -ne 0 ]
22 then
23 echo "Error making directory $JUNKDIR - file not deleted"
24 exit 1
25 fi
26 chmod 755 $JUNKDIR
27 endif
28 for file in $#
29 do
30 newfile=`basename $file`
31 if [ -r file ]
32 then
33 mv $file $JUNKDIR/${newfile}.$DATE
34 else
35 echo `$file does not exist!`
36 fi
37 end
38
39 # Now check for cleanup
40
41 find $JUNKDIR -mtime +3 -exec rm {} ;
since i couldn't attach the .sh file i have written the code above.
can anyone please help
I am really stuck here i am trying to practice shell scripting and i am very new to linux.
Here i have a code and it is not working can any one suggest me where is the problem in the code and rectify the code i would be very very much grateful to you.
1 #!/bin/bash
2 # Script: delete.sh
3 # Author: Kieren Jamieson
4 # Purpose: Provides a safe alternative to "rm" as
5 # each file is moved to a "trashcan" folder
6 # before it is deleted.
7 # Flies are "cleaned" each time delete is run (
8 # three days old). Files are stored by their original
12 Usage: delete.sh <file1> [file2] ... [filen]
13 $JUNKDIR=/tmp/trashcan.$LOGNAME
15 DATE='date +%Y-%m-%d_%H%M%S'
16
17 if [ not -d $JUNKDIR ]
18 then
19 echo "$JUNKDIR does not exist, creating..."
20 mkdir -p $JUNKDIR
21 if [ $? -ne 0 ]
22 then
23 echo "Error making directory $JUNKDIR - file not deleted"
24 exit 1
25 fi
26 chmod 755 $JUNKDIR
27 endif
28 for file in $#
29 do
30 newfile=`basename $file`
31 if [ -r file ]
32 then
33 mv $file $JUNKDIR/${newfile}.$DATE
34 else
35 echo `$file does not exist!`
36 fi
37 end
38
39 # Now check for cleanup
40
41 find $JUNKDIR -mtime +3 -exec rm {} ;
since i couldn't attach the .sh file i have written the code above.
can anyone please help