Automatic script


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Automatic script
# 1  
Old 06-05-2008
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  
Old 06-05-2008
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  
Old 06-05-2008
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.
# 4  
Old 06-05-2008
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...
# 5  
Old 06-05-2008
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  
Old 06-05-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automatic scp Script

I need a script to automatically scp the latest files on DIR1,DIR2 and DIR3 from Source to destination server at same place(DIR1,DIR2 and DIR3) . Further details are: Source Server (192.168.1.5) DIR1 DIR2 DIR3 Destination Server (192.168.1.10) DIR1 DIR2 DIR3 (7 Replies)
Discussion started by: refra
7 Replies

2. Shell Programming and Scripting

Automatic script trigger

Hi, I'm looking for a way to solve the following scenario: A shell should automatically trigger / run when a text file is placed or present at a specific location. My idea - to create a cron / anacron for every minute and inside that i will call a temp script. Temp script will move to my... (9 Replies)
Discussion started by: Gautham
9 Replies

3. Shell Programming and Scripting

script for automatic table filtering

Hello everyone! i I'm trying to write a script that can filter data in a text file. the source file looks like this the result file should look like this As you can see mostly i need to delete fields like _219402757693 and date - time 12.07.2012 8:49:06 i know that it's possible to... (0 Replies)
Discussion started by: o28
0 Replies

4. UNIX for Dummies Questions & Answers

Automatic counter script

Hello, I am having trouble calculating some numbers and I was hoping someone could help me solve this. I have one file with 1 column and what I'm trying to do is add up the lines until a certain value is reach, then jump to where it last finished counting and continue. so for ex: if I... (27 Replies)
Discussion started by: verse123
27 Replies

5. Shell Programming and Scripting

Script for Automatic Backup System

Hi Guys/ULF, Good day! Can anyone help me on how to create a program which will be used for our backup process and that will run automatically say every 30th day of the Month. Below is the given command to perform a backup process among all nodes/servers within the same cluster. ns cluster... (2 Replies)
Discussion started by: rymnd_12345
2 Replies

6. SCO

Automatic FTP script

We are using SCO OS 5.05 server and we are doing a manual ftp to another SCO OS 5.05 server to backup our database. We are using the Bourne shell. We would like to automate the ftp backup of our database instead of doing it manually. It would be nice to run a script. Also would there be anyway... (4 Replies)
Discussion started by: texastig
4 Replies

7. Solaris

Script for automatic count the file i have

Hi I have a folder will all the file ftp in everyday. I have to go in every morning to check to see everynight have all the 2000+ file have been all FTP in. so every morning i will check like this # ls -l *_20080904*_20080904* |wc if there is 2714 that mean is correct. File name:... (13 Replies)
Discussion started by: summerpeh
13 Replies

8. Solaris

Script for automatic deletion of old folder

Hi, I have a folder with limited space. So i have to delete folder which are more than 5 days old automatically. So my script should be like delete the folder more than 5 days old. Can someone help me to generate a script for this. Thank you... Cheer Summer (5 Replies)
Discussion started by: summerpeh
5 Replies

9. Shell Programming and Scripting

Script for automatic deletion of old files

Hi, I have a folder with limited space. I do not have provisions to increase the space for this folder. So i have to delete files which are more than 1 month old automatically. But, i need to maintain the files created by 4 users and delete all the other files automatically which is more than 1... (4 Replies)
Discussion started by: vivek_scv
4 Replies

10. Shell Programming and Scripting

Automatic login script

Hi, I'm a beginner in unix.As a part of my script i need to remote logon using ssh. my script run as being asked for password and logons only after the user enters the password correctly. But my script stops executing after that as I login to a different server(different shell if i'm right).... (3 Replies)
Discussion started by: dayanand
3 Replies
Login or Register to Ask a Question