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 2.6.20.14. 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. Thanks, Unnikrishnan |
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.
|
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? |
I had created a separate rule file named "10-arinc.rules" under ../rules.d folder. here is the content
KERNEL="sd*", RUN+="/usr/bin/script.sh" The "script" file contains the following lines which will mount the USB device and create one empty file in the USB disk. #!/bin/sh 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. |
All times are GMT -5. The time now is 08:10 PM. |