Operating System - HP-UX
1833589 Members
3759 Online
110061 Solutions
New Discussion

remove files with the use of crontab

 
Remko Oosenbrug
Contributor

remove files with the use of crontab

I want to make a script that checks if there are files named for example xxx in the userdirectories. If the script find somewhere a file xxx i should be deleted.
Can anyone give me some directions how to make a script like that?
OH No. It's happening again
5 REPLIES 5
Vincenzo Restuccia
Honored Contributor

Re: remove files with the use of crontab

Remove all files named a.out or *.o that have not been accessed for a
week:

find / \( -name a.out -o -name '*.o' \) -atime +7 -exec rm {} \;
Stefan Schulz
Honored Contributor

Re: remove files with the use of crontab

I use the following command to delete all DWG drawings in the userdirectorys not modified for 14 days:

find /disc/users -type f -name "*.dwg" -mtime +14 -exec rm -f {} \;

You don't need a script for this as you can put this command directly in the crontab. Just make sure you use the full path for the find and rm commands (/usr/bin/find and /usr/bin/rm).

Hope this helps. Stefan
No Mouse found. System halted. Press Mousebutton to continue.
W. Sikkens
Advisor

Re: remove files with the use of crontab

Hello, we use a script to delete all sorts of files. I will attach it. Maybe its usefull for you.
Wietze.
Abel Berger
Regular Advisor

Re: remove files with the use of crontab

Hi Remco,

try this :
find /userdirectories -type f -name -exec rm -f {} \;

Later, put this in a file ( chmod 755 ) and run in crontab.

For example whitch one hour :
0 * * * * ksh -c /dir/script

I hope help you.

Regards,

Abel Berger



I hope help



Shannon Petry
Honored Contributor

Re: remove files with the use of crontab

The logic in most of these will get the job done. I'd warn however to LOG what you do initially. This will not only assure your users, but you as well that what your doing works. Because the "junk" file market are always growing, I usually use an external control list from the script, and launch a clean script from cron. Another thing I also do is create a list of hosts to run cleanup on, setup credentials for remsh to those hosts, and clean up everyone from one system....
I.E.

>cat /usr/local/etc/cleanup_hosts
host1
host2
host3
>cat /usr/local/etc/junk_file_list
core
idmerr
*.roll
*.save
*.tmp
*.nfs
>cat /usr/local/sbin/cleanup.sh
#!/usr/bin/sh
DATE=`/usr/bin/date +%Y-%m-%d`
HOSTLIST=' /usr/local/etc/cleanup_hosts'
JUNKLIST='/usr/local/etc/junk_file_list'
LOG="/tmp/cleanup$DATE.log"
if [ -f $LOG ] ; then
/sbin/mv $LOG $LOG.old
fi
/usr/bin/touch $LOG

for HOST in `cat $HOSTLIST` ; do
for JUNK in `cat $JUNKLIST` ; do
echo "Removing $JUNK from $HOST" >>$LOG
/usr/bin/remsh $HOST '/usr/bin/find -name $JUNK -exec /usr/bin/rm -f {} \;' >>$LOG
done
done

DONT cut and paste any of this, cuz I wrote it from memory!, but I think you get the idea....
If you can do all your administration tasks from one seat, it makes maintenance much easier!

Regards,
Shannon
Microsoft. When do you want a virus today?