---
My notes on the scripts:
*DO NOT REPLACE rm WITH THESE. Call them delete or recycle. Other
scripts may call rm when they want something deleted forever. Also,
daemons/scripts may not put files in /home/user/.recycle, but in /.recycle.
*Delete now checks if .recycle and restored/ work.
*The scripts first tar and compress the file, then put it in ~/.recycle
with its name being utime-rand (utime is Unix time, rand is a random number)
*If your tar doesn't support z, get one that does, or run gzip.
*Run deld as a cron job, it deletes files that are 21, 22, or 23 days old.
*I put deld in /usr/local so it wouldn't be in PATH, so I could use Tab
to autocomplete delete after typing 'del'
*[hermie@gandalf hermie]$ ls -al /bin/sh
lrwxrwxrwx 1 root root 4 Jun 10 08:37 /bin/sh -> bash
*Recycleutill is a front end for undeleting. It needs some work. Users
enter which file they want examined, it it tells them its contents.
*Enjoy! Let me know how useful they are, and if I forgot to include
anything.
--------------------
[hermie@gandalf hermie]$ cat /usr/bin/delete
#!/bin/sh
# Delete Script - Nick Bachmann (June 21, 2001)
if [ ! -d ~/.recycle ]; then
mkdir ~/.recycle
fi
if [ ! -d ~/restored ]; then
mkdir ~/restored
fi
/usr/bin/utime >/tmp/temp_$$
read TIME </tmp/temp_$$
rm /tmp/temp_$$
printf "$TIME / 86400\n quit" >/tmp/temp_$$
bc -q /tmp/temp_$$ >/tmp/temp__$$
read DAYS </tmp/temp__$$
rm /tmp/temp_$$ /tmp/temp__$$
/usr/bin/random >/tmp/temp_$$
read RAND </tmp/temp_$$
rm /tmp/temp_$$
tar --remove-files -c -z -f ~/.recycle/$DAYS-$RAND $1 2>/dev/null
-----------------
/* /usr/bin/utime -- gives unix time for deleting */
#include <stdio.h>
#include <time.h>
main()
{
time_t time_a;
time(&time_a);
printf("%i\n",time_a);
}
------------
[hermie@gandalf hermie]$ cat /usr/local/deld
#!/bin/sh
# Delete Daemon - Nick Bachmann (June 21, 2001)
cd ~/.recycle
/usr/bin/utime >/tmp/temp_$$
read TIME </tmp/temp_$$
rm /tmp/temp_$$
printf "$TIME / 86400\n quit" >/tmp/temp_$$
bc -q /tmp/temp_$$ >/tmp/temp__$$
read DAYS </tmp/temp__$$
rm /tmp/temp_$$ /tmp/temp__$$
printf " $DAYS - 21\n quit" >/tmp/temp_$$
bc -q /tmp/temp_$$ >/tmp/temp__$$
read DAYSA </tmp/temp__$$
printf " $DAYS - 22\n quit" >/tmp/temp_$$
bc -q /tmp/temp_$$ >/tmp/temp__$$
read DAYSB </tmp/temp__$$
printf " $DAYS - 23\n quit" >/tmp/temp_$$
bc -q /tmp/temp_$$ >/tmp/temp__$$
read DAYSC </tmp/temp__$$
rm -f $DAYSA* $DAYSB* $DAYSC*
---------------------
/* /usr/bin/random - a 2/3 digit random number generator */
#include <stdio.h>
#include <stdlib.h>
#include <time.h> //for seeding randomizer
int rnd(void);
void seedrnd(void);
main()
{
int x;
seedrnd();
printf("%i\n",rnd());
}
int rnd(void)
{
int r;
r=rand(); //spit up random num.
r=r%1000;
return(r);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
-------------------
[hermie@gandalf hermie]$ cat /usr/bin/recycleutil
#!/bin/sh
while true
do
while true
do
echo "The files in the recycler are: "
echo "The number (xxxxx-xxx) is the recycle ID.
Remember the order!"
ls -al ~/.recycle
echo "What file should be examined? Please enter it's recycle ID: "
read IDNO
if [ $IDNO = "quit" ];
then
exit 0
fi
if [ $IDNO = "rm" ];
then
echo "Are you sure? y for yes"
read SURE
if [ $SURE = "y" ];
then
/bin/rm -f ~/.recycle/*
break
fi
fi
cd ~/restored
tar -tvzf ~/.recycle/$IDNO
echo "Restore into ~/restored ? y for yes "
read ANS
if [ $ANS = y ]; then
cd ~/restored/
tar -xxvzf ~/.recycle/$IDNO
rm ~/.recycle/$IDNO
fi
done
done
--
Regards,
N
-----------------------------------
Nicholas Bachmann
nabac...@yahoo.com
"To Boldly Go Where Angels Fear To Tread"
-From the Infocom Game "Stationfall"
----------------------------------