You are not logged in.

#1 2009-10-29 00:15:36

syn
Member
Registered: 2009-08-22
Posts: 43

Bash/Placement

I feel like an idiot for posting something so basic here, but I want to write a small bash script.

Basically, I want it to--when I plug in my MicroSD card that I use for my NDS into my laptop--copy all the ROM save files on that disk into a remote folder for backup.

It'd be something like:

cp -r /media/vdisk/*.sav /my/backup/folder

But, I can't figure out any way to make it run automatically in the background whenever I put the card in. Advice?

(Also, to the mods, I wasn't sure where to put this, sorry. sad )

Offline

#2 2009-10-29 00:44:19

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: Bash/Placement

You could have a background process watch /media/vdisk/ to see if it's mounted, and if so, do what you described.

#!/bin/bash
while true; do
  if mountpoint -q /media/vdisk; then
    # do stuff
  fi
  sleep 3 # keep it from eating CPU
done

Should work, though I haven't tested it.

There's probably a more elegant solution involving hal, but meh.

Last edited by Peasantoid (2009-10-29 00:47:54)

Offline

#3 2009-10-29 05:52:48

seiichiro0185
Member
From: Leipzig/Germany
Registered: 2009-04-09
Posts: 226
Website

Re: Bash/Placement

the "best" solution IMHO would be to have an udev rule which executes a mount & copy script on card insertion. A good starting point for writing udev rules can be found here


My System: Dell XPS 13 | i7-7560U | 16GB RAM | 512GB SSD | FHD Screen | Arch Linux
My Workstation/Server: Supermicro X11SSZ-F | Xeon E3-1245 v6 | 64GB RAM | 1TB SSD Raid 1 + 6TB HDD ZFS Raid Z1 | Proxmox VE
My Stuff at Github: github
My Homepage: Seiichiros HP

Offline

Board footer

Powered by FluxBB