Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. 🚫 No AI-generated (LLM) posts allowed. Share your own thoughts and experience — accounts may be terminated for violations.

cron job help

Status
Not open for further replies.

PaullasPaullas is verified member.

Acorn Moderator
Nominet Member
Nominet Registrar
Hosting Provider
Domain Marketplace
Parking Service
Joined
Jul 13, 2004
Posts
5,859
Reaction score
395
Hi

I am looking for a way to get one of my servers delete certain files at certain times of the day. Can any help me on this.
 
Sure...

What do you want to delete? File, directories?

Who owns the files?

How often do you want to run the file?

Jee
 
hi, cheers for replying.

i am wanting to delete 4 files once a day. the files are on my servers.

thanks

paul
 
WHen I say own, i meant which user owns the files? I'll assume that your user does.

Create a text file called delete.sh with this:

#!/bin/sh
/bin/rm -rf /home/user/file1.html
/bin/rm -rf /home/user/file2.html
/bin/rm -rf /home/user/file3.html
/bin/rm -rf /home/user/file4.html

Upload it to your user directory (in this case, /home/user) and chmod it 755

Then you need to create the cronjob. The easiest way is via shell:

$ crontab -e

enter this:

01 02 * * * /home/user/delete.sh

Save and exit. If you haven't got shell, or aren't comfortable using that, then your control panel should have something to help you.

The above cron line will run the delete.sh file once a day at 2:01am. I would test this out before committing it to real files, but its working fine for me!

Make sure you have backups ;)

Jee
 
:) cheers, ill give that a go.

thanks for help
 
hi

ok done that. but when i try and run it i get

: bad interpreter: No such file or directory

I am running it manual with this command ./delete.sh
 
paullas said:
hi

ok done that. but when i try and run it i get

: bad interpreter: No such file or directory

I am running it manual with this command ./delete.sh

try replacing the /bin/sh with /bin/bash.

I'm assuming you're using linux?

S
 
Try

delete.sh

rm -f /path/to/file/remove.file

chmod 777 delete.sh

./delete.sh
 
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.
      Helmuts @ HelmutsHelmuts is verified member.: Good morning all
      Top Bottom