Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ubuntu 9.10, connected to external WD 1.5GB USB drive, called "data_3"

I connected the USB cord and all was well for a long time. Ran nightly cron jobs rsyncing data via the internal network.

After a powerout, after which the external USB did not start, the rsync job COPIED the data to /media/data_3, on the INTERNAL drive which is much smaller and ran out of space.

The rsync script points to the supposedly mounted USB drive at /media/data_3, but when it does not exist it writes to /media/data_3, on the internal drive.

How get rsync to write only to the USB disk, and fail if it's not mounted ?

share|improve this question
up vote 0 down vote accepted

You'll need to check beforehand if the disk is mounted (via mount and grep), and then have the script fail if it is not.

share|improve this answer

You can create a file on the external drive and test for its presence before running rsync.

if [ -e /media/data_3/testfile ]; then rsync /source/directory /media/data_3/destination; fi should work as a one line in bash at least. You can add an else condition to send you a mail if the file doesn't exist (meaning the partition isn't mounted, or isn't mounted in the right place).

share|improve this answer

Your Answer


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.