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 am doing daily backups to S3. I would only like to consume upload bandwidth only from 8 PM - 8 AM. Any individual run could take longer than 12 hours because our upload is crappy. I'm not worried about killing s3cmd arbitrarily because it will correctly recover on the next run.

My crontab would look like this:

# 0 20 * * * s3cmd sync FOO s3://MyBucket

How do I test and make it stop if it is 8 AM. Ideally, I wish I could do something like:

# 0 20 * * * time --limit 12H "s3cmd sync FOO s3://MyBucket"

I am using Ubuntu Server.

Thank!

EDIT:

Based on quanta's answer. For multiple upload commands I think I should do?

# 0 20 * * * s3cmd sync FOO s3://MyBucket; s3cmd sync BAR s3://MyBucket; s3cmd sync FOOBAR s3://MyBucket;
# 0 8 * * * pkill s3cmd; sleep 1; pkill s3cmd; sleep 1; pkill s3cmd;

?

EDIT:

NM, I like timeout better.

EDIT:

Here is a weakness of the timeout solution. If I have 12 backups to do and a 12 hour window to do it, I don't necessarily need to allocate 1 hour per backup. Some backups might take 5 hours, some 20 minutes. I don't care. All I care about is at 8 AM everything stops. I don't believe the timeout option allows this flexibility to adaptively set the timeout value. The kill option based on quanta's answer should be able to handle this.

share|improve this question
1  
regarding your edit. I'd put the 12 backups into one script so they execute one after another, and run it with a 12 hour timeout. Job done. –  Sirex Oct 20 '11 at 10:59
1  
great. just FYI, at least in ubuntu 10.04, you have to supply seconds you can't put 12h. –  engineerchuan Feb 13 '12 at 4:06
add comment

1 Answer

up vote 4 down vote accepted

you are likely wanting the timeout command.

timeout 12h s3cmd sync FOO s3://MyBucket

man timeout for more information.

at least in fedora this is installed with the "coreutils" package, which you should have by default.

share|improve this answer
add comment

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.