Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running a bash script on an ubuntu 12.04 through cron. The script works fine for a few weeks (runs daily backups of websites, mysql databases, and copies to Amazon S3).

However, twice now I've noticed that backups stopped happening. Both times the backup script (backupscript.sh) located in my home folder was no longer there. No one else has access to this server, so nothing was manually changed on the server and no one deleted the file by mistake.

The cron job (nano /etc/crontab) still references this script, but the script itself disappears.

What could cause this to happen? Does Ubuntu delete the script if it runs into some sort of error?

share|improve this question
    
Does your cron script have a "rm ..." command anywhere in it? Its likely overwriting the cron script itself. –  Suman Oct 22 '12 at 22:24
    
Did you check the script for obvious things like rm $0? –  Michael Hampton Oct 22 '12 at 22:24
    
Thanks guys... that was the problem. I was running a RM command and my carelessness in the directory choices I made caused the backup script to remove itself. I should have seen that... so thanks for pointing that out. –  Kris Anderson Oct 22 '12 at 22:47
    
Glad it's solved. I've made a full answer out of it. –  Michael Hampton Oct 23 '12 at 2:40
    
possible duplicate of Files disappearing on linux server –  Mircea Vutcovici Oct 23 '12 at 2:54

2 Answers 2

up vote 1 down vote accepted

Did you check the script for obvious things like rm $0? It sounds like the backup script is deleting itself.

share|improve this answer

I suppose you could have also set the file as immutable too?

Chattr + i script.sh

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.