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

I have to do scheduled backup of servers' databases using a cronjob for the backup task and a bash script for the backup operation. It's a PHP web application. You can choose to store your backup file on the server hard disk or on an external USB flash drive or hard disk.

The user adds a backup task and edit it from the web page application designed to show all saved backup tasks with all their information :

server - database - tables - target server - target storage - day - hour - minute

All this is saved in an xml file and shown in a table. You can add, edit or delete a task from that table in that page.

USB drives should be auto-mounted on the remote servers and the PHP application should then tell the user when a drive is available for the saved tasks with target storage equals usb.

I have a bash script doing this but manually on one server at a time. I'm using CentOS on Virtual Box guests. My Virtual Box host is Ubuntu and I'm still a beginner. I need your help with commands.

I currently have a command that gets the name of usb (not its id) like this:

# Get USB stick count, name and size  
dec_count=`fdisk -l | tr -s ' ' | grep 'Disk /' -c`  
fdisk -l | tr -s ' ' | grep 'Disk /' | cut -f3 -d'/' | cut -f1 -d',' | sed -n "2,$dec_count p"  

This is because I need a unique id for each USB drive, not the name that Linux gives it (like sdb).

Then, how can my PHP application know if there's a USB drive available? Should a cronjob do that or should it be done in PHP?

Am I taking this problem correctly? Any helping links or advises are so welcome. Need to do it fast.

Thanks in advance.

share|improve this question
I'm not sure why you need a timer? Is it for the same purpose of mounting usb disks or should it be a different question? – Tonin Mar 8 '13 at 17:03
I have to check if user plugs-in or plugs-out a usb flash drive every (minute) , I have a saved backup tasks which would save the back up files o that flash so I have to do this check every while and when it's a time of the task I should tell user (by email for example) that there's no flash and you said toy want to do the back up on a flash drive ! – Nancy Smith Mar 8 '13 at 17:07
use CRON job to run the script? – laurent Mar 8 '13 at 17:10
actually I use a cronjob for doing the backup operation . but why I should use a cronjob for checking if there's a usb or not ?? – Nancy Smith Mar 8 '13 at 17:11
cronjob as I know is used when there's a specific time you want to do some task , but in my situation I have to check and reflect result on interface and tell if there's a flash for this task or there is not – Nancy Smith Mar 8 '13 at 17:14

You can use Cron jobs to run the script every minute and not only at scheduled time. The first field is for Minutes.

If you specify * in this field, it runs every minute:

* * * * * /home/user/

If you specify */5 in the 1st field, it runs every 5 minute:

*/5 * * * * /home/user/
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.