Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-08-2008, 06:53 AM   #1
LQ Newbie
Registered: Jul 2008
Posts: 7

Rep: Reputation: 0
Detectiion and Tranfering files to USB automatically

I am new to linux. for one my new project ,the requirement is

we will have a textfile(.txt) in a local harddisk of the Desktop which is having linux OS(Red Hat Enterprise Linux 4) with kernel version We need to write a small application program in C language which will do the following action:

1) Whenever the USB is connected in the Desktop, the C program has to transfer the textfile to the USB disk automatically.

For executing this we would like to clarify the followings:
a) How to find the presence of USB disk through my C program?
b) How to transfer the textfile to USB disk through my C program automatically after detecting the USB disk?

If any one can give a solution for this, it will be really helpful.

Old 07-08-2008, 07:38 AM   #2
Registered: Mar 2005
Location: North Carolina
Distribution: Arch
Posts: 977

Rep: Reputation: 73
Why not just make a single udev rule that does this? It would be much simpler. Unless this is homework, which from the sounds of it, it is.
Old 07-08-2008, 07:44 AM   #3
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
b) is easy - just copy the file. The least lines of code would be to invoke the cp program with system.

The trick then is monitoring for the connection of a USB device - maybe using dbus?
Old 07-09-2008, 03:43 AM   #4
LQ Newbie
Registered: Jul 2008
Posts: 7

Original Poster
Rep: Reputation: 0
I had created a separate rule file named "10-arinc.rules" under ../rules.d folder. here is the content

KERNEL="sd*", RUN+="/usr/bin/"

The "script" file contains the following lines which will mount the USB device and create one empty file in the USB disk.

mount /dev/sdb usb
cd usb
touch test_file.txt
cd ..
umount /dev/sdb

=> But no action take place. Is there anything wrong in my approach? Please guide me.

Last edited by ukrishnanps; 07-11-2008 at 12:01 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rhythmbox not loading some files automatically mike_morley Linux - Software 0 10-28-2006 11:33 AM
Automatically delete old files depam Linux - Software 1 01-25-2006 08:15 PM
Tranfering files from/to reiserfs and ntfs Nik0s Linux - General 2 01-22-2006 09:31 AM
Question to Linux Elite! - Tranfering X application between X servers on-fly! Alexmipego Linux - Software 2 08-23-2004 04:34 PM
automatically moving files Dr_Travis Linux - General 1 05-27-2002 07:44 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:56 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration