The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[REQ] Automatic script kill process onisoc Shell Programming and Scripting 3 05-25-2009 06:17 AM
Script for automatic deletion of old files vivek_scv Shell Programming and Scripting 4 09-09-2007 01:57 AM
Automatic FTP Script from windows to unix machine bmkreddy Shell Programming and Scripting 3 05-10-2007 11:30 AM
Automatic download of csv file using a shell script figaro Shell Programming and Scripting 1 01-13-2007 08:53 PM
Automatic login script dayanand Shell Programming and Scripting 3 01-08-2006 07:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-05-2008
TShirt TShirt is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 5
Automatic script

Hi,
is it possible to automatically run a script (bash) when an event occurs?
I mean, let's say that I (or one of my users) plug in a flash memory (USB) ... is it possible to run a script every time I do this action (let's say to log user, date and other infos on a file)?

Thanks!


Bye...
  #2 (permalink)  
Old 06-05-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
It depends on your USB subsystem. Many of them are eminently scriptable and work exactly as you describe. Look at hotplug and hal for a start if you are on Linux. If you examine your system log when you insert a removable storage device, you should get some hints about where to look, as well.

("User" is not well defined in this context, by the by; the insertion of a USB stick is not necessarily performed by a user who exists on the system, much less one who is logged in; of course, if only one user is logged in, you can make some conjectures, but that's heuristics.)
  #3 (permalink)  
Old 06-05-2008
TShirt TShirt is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 5
Unfortunately I'm not under Linux! I'm using Mac OS X but I'm a newbie so ... I think it's in the UNIX side!

Bye...
  #4 (permalink)  
Old 06-05-2008
zaxxon's Avatar
zaxxon zaxxon is online now Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
You can write a cronjob that is started every minute and checks for a new usb device like "lsusb" on Linux and if their is an additional device it will collect your data and copy it on the usb stick.
To have the time between the minute checked too, you can call this test in a while loop every 2 seconds and count up to 29 for example. Place a file under /tmp as lock maybe, so your script knows, that a copy is in progress. When the device is removed, the check for usb devices should remove that lockfile too.
  #5 (permalink)  
Old 06-05-2008
TShirt TShirt is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 5
Hi zaxxon,
I had the same initial idea! But I would like to avoid continuous submissions! I think that the OS already does it (when I plug the flash it's immediately mounted) so it would be better to append to it!


Bye...
  #6 (permalink)  
Old 06-05-2008
zaxxon's Avatar
zaxxon zaxxon is online now Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Yes, but some mechanism has to do your copy jobs and I doubt, that the same part that realizes that there is a new usb device can do any actions like copy stuff for you etc. on it's own by passing that as parameter or in some config file.
But I have no clue about Mac OS X either.
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0