Orbi WiFi 7 RBE973
Reply

Eject USB Drive from command line (ReadyNAS 102)

ColinG
Aspirant

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

Message 1 of 3
StephenB
Guru

Re: Eject USB Drive from command line (ReadyNAS 102)

Thx for sharing it.

Message 2 of 3
JennC
NETGEAR Employee Retired

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,

 

 

Message 3 of 3
Top Contributors
Discussion stats
  • 2 replies
  • 3040 views
  • 0 kudos
  • 3 in conversation
Announcements