Udev Rules and script issues - shell

So I want to make a udev rule which does, when I connect my usb key to my computer the rule mounts my usb key, takes a file from my computer, copies it to my usb key and then unmounts my usb.
So I did my udev rule like that:
ACTION=="add" SUBSYSTEM=="BLOCK", ENV{ID_VENDOR_ID}=="0718", ENV{ID_MODEL_ID}=="0618", ENV{ID_SERIAL_SHORT}=="CB00524932077759", RUN+="/bin/mount /dev/sda1 /media/usb"
ACTION=="add" SUBSYSTEM=="BLOCK", ENV{ID_VENDOR_ID}=="0718", ENV{ID_MODEL_ID}=="0618", ENV{ID_SERIAL_SHORT}=="CB00524932077759", RUN+="/bin/ScriptCopy"
And I wrote a script, in /bin, called ScriptCopy:
#!/bin/sh
cp /root/average.db /media/usb/database/average.db
ldconfig
echo "Done!"
exit 0
So the first part of my udev rule works, it mounts the usb key, but then my script does not work, I do not really understand why. Can someone explain it to me? Thx
edit 1:
when I am running my script in the terminal, doing
./ScriptCopy
it works! so I must have a problem in my udev rule.
edit 2:
I found out something really strange (at least, that I don't understand at all), my rule works if I am plugging my USB key while I am on the GUI (XFCE) on my banana pi. But I am working with ssh, so normaly I don't open the GUI. I want to do is, to run some commands with the ssh, trigger my python script and then I take the data with my usb key once every two days. But when I plug my usb while banana pi is not on the GUI (while I triggered my script from another computer using ssh), it does not transfert the data to my usb key. I don't know if it was understandable.
Edit 3:
Ok I had an error of path in my UDEV rule because on ssh, I was not in the same user. I am closing the topic.

I found that I had an error of path in my script/udev rule.

Related

How to find COM port for PuTTy (Mac)

I am doing a lab for my class using Code Composer Studio and the Tiva Launchpad. I am using a macbook and I have downloaded PuTTy using MacPorts. Now that PuTTy is running I have to type in the serial line to communicate with CCS and the Launchpad.
It is necessary to type in the serial line for connection to work,
PuTTy Serial line
Any help or direction is very appreciated! First time posting sorry if I am unclear at any point.
Here's an easy way to find the device special file for any device.
Unplug the device and reboot your system.
Get a list of all device special files in /tmp/a
ls /dev > /tmp/a
Now plug in your device and wait a few seconds, and get a list of the device special files again, this time in /tmp/b:
ls /dev > /tmp/b
Now compare /tmp/a with /tmp/b:
opendiff /tmp/a /tmp/b # Yes, you could use "opendiff /tmp/[ab]"
Whatever is new in file /tmp/b corresponds to what you plugged in.

Wiping entire usb drive on Mac OS X

Is there a command for the apple terminal to brute force a wipe of everything including all partitions, master boot records, and data on a usb flash drive?
Just a little information about the situation:
I just got a stick from a friend which seems to be damaged but it isnt a physical defect. I guess he just removed the stick while formatting or so.
I already tried to repartition, reformat and erase the stick with the Mac Disc Utility and I tried to format it on windows. Nothing of it worked, so I decided to use terminal for it (im just getting used to terminal/bash, so im a complete newbie at this) and tried the commands (all with sudo and diskutil in front of them ofc) repairDisk, reformat, partitionDisk, eraseDisk or zeroDisk, but nothing worked. Im getting this error message now: Error: -69759: Securely erasing data to prevent recovery failed
Underlying error: 5: POSIX reports: Input/output error
So my final thought is now that I have to clean everything from this drive as it seems there is something broken on a very low level and i would assume that completely wiping it will result in my diskutil to install a complete new partition scheme and everything on the drive so it will eventually start working again..
Thank you all in advance!
Screenshots:
Try this in Terminal if you are CERTAIN it is disk3:
sudo dd if=/dev/zero of=/dev/rdisk3 bs=65536 count=1000
If it says the disk is busy, make it un-busy!
sudo diskutil unmountDisk /dev/disk3
First, check what disk# your usb is (to be certain) in a terminal:
sudo diskUtil list
then
sudo dd if=/dev/urandom of=/dev/<your_usb_disk_here> bs=1m
If you get busy error and/or if the usb is in use elsewhere, stop what you are doing there and unmount it first as Mark Setchell said
sudo diskutil unmountDisk /dev/<your_usb_disk_here>
If you get a funky name from using bootcamp assistant or something, and you cannot get dd or even Disk Utility to wipe it for some reason, like "permission" problem, use:
diskutil eraseVolume HFS+ NAME <your_usb_disk_here>
Note that the last arg is not e.g. /dev/disk2 , but just the last part, disk2

Most efficient way to copy data to multiple USB drives in OS X

I have a need to duplicate about 10 USB thumb drives a day from a Dropbox folder that changes slightly each day (about 10GB of data). I considered the $300 "Aleratec 1:10 USB 3.0 Copy Cruiser" but upon study, realized it's no more than a USB 3.0 hub and some basic copying software. I can do this with my own USB 3.0 hub and Terminal in OS X! (Windows 10 is also available if there's an easier way.)
Question: Since the bus is faster than my drives, is there a way I can execute this command to write to all the drives simultaneously? Or any other creative suggestions appreciated. Thanks.
You can format them in parallel quite easily, if you make a little script. Say your drives have the word USB in their names, you could write something like this:
#!/bin/bash
# Don't barf if no drives mounted, or if USB is lowercase
shopt -s nullglob
shopt -s nocaseglob
# Iterate through all mounted USB drives
for drive in /Volumes/*USB* ; do
# rsync source to USB drive in background
echo rsync <options> <YOURSOURCE> "$drive" &
done
# wait for all parallel rsyncs to finish
wait
You would save that on your Desktop, as DuplicateUSB and then you make it executable like this in Terminal:
chmod +x "$HOME/Desktop/DuplicateUSB"
Then you can run it by double-clicking it, or going in Terminal and typing:
$HOME/Desktop/DuplicateUSB
At the moment, it only echoes what it would do, but doesn't actually do anything. When it looks to be correct, and you are happy with what it is doing, you can remove the word echo from the line with rsync in it so it actually does the rsync.

Unmount my external hard drive in bash

So, this should apparently be really simple, but had trouble finding any good answers online.
I have a mounted external usb hard drive.
I would like to unmount it, using bash. (Essentially I'm just looking for the equivalent bash command for right clicking on my external hard drive in nautilus and selecting 'unmount')
How can I achieve this?
Searching for "Unmount Hard Drive Terminal" yields http://ubuntuforums.org/showthread.php?t=842698.
russlar provides a solution:
open terminal, and run df -h. this will tell you all the hard drives mounted. then, run sudo umount /dev/<something>, where <something> is the name of the hard drive that you want to unmount.

Mount command failing on 10.7.5

I have a shell script that mounts an smb share. It works perfectly on all macs with every OS revision except 10.7.5
The offending command is simply:
mount -t smbfs -o nobrowse //test:test#servername/sharename /my/mnt/point
When I attempt this command on a 10.7.5 mac, it fails either with a "broken pipe" or "authentication failed" error. However, it works fine on macs running 10.7.4, 10.6, 10.8 etc.
Can anyone successfully use this command on 10.7.5?
Is there any alternative way of achieving this, or troubleshooting exactly why this error is happening? I'm running out of ideas!
Since feature requests to mark a comment as an answer remain declined, I copy the above solution here.
Thanks for the replies. The problem was two fold: firstly, for some reason you cannot run this command as root in 10.7.5, and secondly you cannot mount outisde of /Volumes. Strangely this seems to work in all other OS revisions. I have worked around this problem by mounting my share in /Volumes and then creating a sym link to the desired mount point:
mkdir -p /Volumes/share
sudo -u localadminuser mount -t smbfs -o nobrowse //user:pass#server/share /Volumes/share
ln -s /Volumes/share /location/that/I/prefer/to/mnt
I hope this helps someone out. No idea why 10.7.5 changes this. – BSUK
There are many reasons why the mount will not work. Some of the reasons include:
Time between server and client being too different
Workgroup name not specified on the mac
Local hostname uses non-latin characters
Encryption is too strict between the mac and the server
To solve the time; set the time.
I've seen broken pipe/authentication errors most often when you don't use a workgroup name for the connection. A connection string looking like generally works better than one without any workgroup:
//WORKGROUP;user:50000#192.168.2.1/Share
... assuming that the 50000 is the password for the user user should allow the connection. Generally, you just need to have a string before the semi-colon, it can read anything; it just needs to be there.
To solve the local hostname issue click on an interface, choose advanced go to the WINS tab and make sure that the name doesn't have any foreign characters there.
If the encryption is too strict, you will need to edit the nsmb.conf. I have a set of lines looking like:
[server1]
minauth=none
for an ancient BSD server which cannot deal with encrypted passwords. You can have this in either an /etc/nsmb.conf or ~/Library/Preferences/nsmb.conf file.
This may not address your issue, but it may help you in trying to proceed.
Unfortunately, saying it works on box x and not on box y doesn't really help, as there could be any arbitrary configuration difference between them.

Resources