- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Eject USB Drive from command line (ReadyNAS 102)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Eject USB Drive from command line (ReadyNAS 102)
Hardware: Netgear ReadyNAS 102. (firmware 6.4.1)
Overview:
I have my own backup script which writes to an external USB drive, which was ported from a previous NAS server. It is scheduled using cron at midnight.
When the backup completes, it unmounts the USB drive and sends me a mail.
Problem:
This worked fine for a few years, but I experienced a problem with Firmware 6.4.0; Once the backup completes, if I unplugged the external drive without first using the eject feature from the admin web front-end, the NAS became unresponsive and required a reboot.
This issue resolved when I applied firmware 6.4.1. When I looked at the release notes for 6.4.1, it recommended I eject the external drive from the web admin console. Not a major problem, but I'd rather not boot up a PC just to hit the eject in the Web admin console.
Goal:
How do I reproduce, in a shell script, the eject feature on the web admin console.
After a bit of digging, I managed to write a reasable solution.
To save anyone else the pain of solving this, here's the script I use. Usual disclaimers apply.
usb_eject.sh
#!/bin/bash usb_pattern=${1%/} [[ -z ${usb_pattern} ]] && { echo echo "need path to USB device" echo " eg $ usb_eject.sh /media/USB_FLASH_6" echo exit 2 } # Get device from mountpoint eg /media/USB_FLASH_6 USB_device=$(lsblk -P -o NAME,MOUNTPOINT |sed -n "s|^NAME=\"\([^\"]*\)\" *MOUNTPOINT=\"${usb_pattern}\"|\1|p") # Exit if device name not found [[ -z ${USB_device} ]] && { echo "Cannot detect USB device using lsblk -P -o NAME.MOUNTPOINT" exit 1 } # Call event_push to eject the USB device as done from admin console # event_push logs to /var/log/readynasd/event_push.log event_push shell readynasd "<xs:delete-s resource-type=\"HotPlug\" resource-id=\"UsbStorage\" action=\"eject\" device=\"${USB_device}\"></xs:delete-s>" 1 1 exit $?
I hope this is of some use to other forum users.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Eject USB Drive from command line (ReadyNAS 102)
Thx for sharing it.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Eject USB Drive from command line (ReadyNAS 102)
Hello ColinG,
Thanks for sharing your idea.
Feel free to post any questions, inquiries, suggestions, etc.
Regards,