Jump to content

Unassigned Devices - Mount zu bestimmter Uhrzeit an bestimmtem Tag


sasbro97
Go to solution Solved by hawihoney,

Recommended Posts

In Anlehnung an mein Thema

frage ich mich, ob und wenn ja, wie es geht, dass ich einen angeschlossenen USB-Stick automatisch bspw. jeden 01. des Monats um 02:00 mounten lasse und dann eben ein Backup Skript laufen lasse und wieder unmounte. Wäre das dann ein Device Script und wie würde es aussehen? Hab noch keinen Beitrag mit diesen Anforderungen gesehen.

Link to comment

The script that runs when the device is plugged in is the device script.  Plug the device in and then click the Edit Device Settings icon (three gears).  Then click the 'Default' script button and fill in your commands in the appropriate event section.

 

Once you are happy with the script, switch on the 'Auto Mount' switch and then when you plug in the USB device the script will run.  You can unmout the disk in the script when it has completed the operations.

Link to comment
1 hour ago, dlandon said:

The script that runs when the device is plugged in is the device script.  Plug the device in and then click the Edit Device Settings icon (three gears).  Then click the 'Default' script button and fill in your commands in the appropriate event section.

 

Once you are happy with the script, switch on the 'Auto Mount' switch and then when you plug in the USB device the script will run.  You can unmout the disk in the script when it has completed the operations.

 

I understand his question in another way: He wants to keep the Stick in the pc permanently.

 

But in Windows you can eject the Stick and the OS does not see it, even if it is connected.

He wants this state in unraid also:

So he wants to let the os detect the stick triggered with a script/timer,

than it should run a backup

and after that the device should be ejected again, without really disconnecting.

 

Link to comment
3 hours ago, sasbro97 said:

Hab noch keinen Beitrag mit diesen Anforderungen gesehen.

gib dem Gerät mal einen Namen in UAD, bitte ohne Leer oder Sonderzeichen, Bsp. "USBHDD"

 

dann teste mal im Unraid Terminal wie folgt und beobachte ob die disk unmounted, mounted wird ...

 

/usr/local/sbin/rc.unassigned unmount name=USBHDD

/usr/local/sbin/rc.unassigned mount name=USBHDD

 

wenn ja, wäre der Rest jetzt ein script zu erstellen was dann die Aufgabe übernimmt in user scripts, oder mal testen was passiert mit einem UAD script wenn die Platte per Befehl mounted wird ... dann wäre es ja nur der mount Befehl in user scripts.

Link to comment

What you want to do is to install the "User Scripts" plugin and set up a script to run at a set time.  I use this script to mount a disk, do a backup, and unmount the disk when it's done.

#!/bin/bash
#description=Backup Music Folder.
#backgroundOnly=true
#arrayStarted=true
#clearLog=true
#
LOGFILE="/tmp/unassigned.devices/logs/Music_Backup.log"

# Mount the backup disk
/usr/local/sbin/rc.unassigned mount name=MusicBk

# Backup the Music folder to the backup disk
rsync -av --delete --exclude .Recycle.Bin '/mnt/user/Music' '/mnt/disks/Music Backup/' 2>&1 >> $LOGFILE

# Unmount the disk
/usr/local/sbin/rc.unassigned umount name=MusicBk

 

You can have the disk detach by loading the default script in UD and uncomment the line to detach it:

 'REMOVE' )
    # do your stuff here

    # Spin down disk - uncomment this if you want the disk to be spun down after the disk is unmounted
   /usr/local/sbin/rc.unassigned spindown $DEVICE

    # Detach the disk - uncomment this if you want the USB disk to be detached after it is unmounted
   /usr/local/sbin/rc.unassigned detach $DEVICE

    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Device unmounted" -i "normal"
  ;;

 

  • Like 1
  • Thanks 2
Link to comment
20 hours ago, DataCollector said:

He wants to keep the Stick in the pc permanently.

Yes.

 

19 hours ago, alturismo said:

dann teste mal im Unraid Terminal wie folgt und beobachte ob die disk unmounted, mounted wird

Klappt. Command ist nur wie in Linux umount und nicht unmount.

 

13 hours ago, dlandon said:

I use this script to mount a disk, do a backup, and unmount the disk when it's done.

This is perfect!

  • Like 1
Link to comment
14 hours ago, dlandon said:
 'REMOVE' )
    # do your stuff here

    # Spin down disk - uncomment this if you want the disk to be spun down after the disk is unmounted
   /usr/local/sbin/rc.unassigned spindown $DEVICE

    # Detach the disk - uncomment this if you want the USB disk to be detached after it is unmounted
   /usr/local/sbin/rc.unassigned detach $DEVICE

    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Device unmounted" -i "normal"
  ;;

This doesn't work for me. Am I doing it right?

image.thumb.png.07cfa39ce15a606bd839725a5402cf19.png

It shows the following error logs:

/tmp/unassigned.devices/scripts/SanDisk_Ultra.sh: line 1: syntax error near unexpected token `)'
/tmp/unassigned.devices/scripts/SanDisk_Ultra.sh: line 1: ` 'REMOVE' )'

 

Okay got it working with the template now. The device completely disappeared from Unassigened Devices. Should this happen? It's now a historial device. I cannot mount it anymore. Command show true but nothing is mounted.

Edited by sasbro97
Link to comment
35 minutes ago, sasbro97 said:

Okay got it working with the template now. The device completely disappeared from Unassigened Devices. Should this happen? It's now a historial device. I cannot mount it anymore. Command show true but nothing is mounted.

You need to use the complete 'Default' script and change the 'REMOVE' section. The script you have is not complete.

 

You asked for the device to be detached.  Click on the three gears on the Historical device and click the "Attach" button and the device will then show up in UD.

Link to comment
35 minutes ago, dlandon said:

You need to use the complete 'Default' script and change the 'REMOVE' section. The script you have is not complete.

 

You asked for the device to be detached.  Click on the three gears on the Historical device and click the "Attach" button and the device will then show up in UD.

Can I attach it via a script again then?

 

My script looks like this:

#!/bin/bash
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
## Available variables:
# ACTION - if mounting, ADD; if unmounting, UNMOUNT; if unmounted, REMOVE; if error, ERROR_MOUNT, ERROR_UNMOUNT
# DEVICE - partition device, e.g. /dev/sda1
# UD_DEVICE - unassigned devX designation
# SERIAL - disk serial number
# LABEL - partition label
# LUKS - if the device is encrypted, this is the partition device, e.g. /dev/sda1
# FSTYPE - partition filesystem
# MOUNTPOINT - where the partition is mounted
# OWNER - "udev" if executed by UDEV, otherwise "user"
# PROG_NAME - program name of this script
# LOGFILE - log file for this script

case $ACTION in
   'REMOVE' )
      # do your stuff here

      # Spin down disk - uncomment this if you want the disk to be spun down after the disk is unmounted
     /usr/local/sbin/rc.unassigned spindown $DEVICE

      # Detach the disk - uncomment this if you want the USB disk to be detached after it is unmounted
     /usr/local/sbin/rc.unassigned detach $DEVICE

      /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Device unmounted" -i "normal"
  ;;
esac

 

Link to comment
  • Solution
On 8/16/2023 at 3:37 AM, sasbro97 said:

frage ich mich, ob und wenn ja, wie es geht, dass ich einen angeschlossenen USB-Stick automatisch bspw. jeden 01. des Monats um 02:00 mounten lasse und dann eben ein Backup Skript laufen lasse und wieder unmounte. Wäre das dann ein Device Script und wie würde es aussehen?

 

Für diese Anforderung machst Du das mit dem User Script Plugin und nicht mit dem Device Script. Die Kommandos hierzu findest Du oben sowie in der Hilfe der Unassigned Devices Seite:

 

Unbenannt1.thumb.jpg.cecbe147feb9323c9fc27d09dceaf2d2.jpg

 

Du musst das in etwa so machen:

 

#!/bin/bash
#backgroundOnly=true
#clearLog=true

# Mounten
/usr/local/sbin/rc.unassigned mount name=diskname

### Hier machst Du was immer Du machen willst
### rsync -avPX --delete-during /mnt/user/<Deine Quelle>/ /mnt/disks/<Dein USB Stick>/

# Und wieder unmounten
/usr/local/sbin/rc.unassigned umount name=diskname

 

Danach noch Cron Einträge für dieses User Script setzen. Die Hilfe hierzu ist auf der User Scripts Seite verlinkt. Deine Anforderung läuft auf "Custom: 0 2 1 * *" hinaus. Einzige Bedingung: Stick bleibt immer stecken wie von Dir angegeben.

 

Ich hänge dazu mal ein Bild vom meinen User Scripts an.

 

Unbenannt.thumb.jpg.32cefa8d44b59cc0f6ba72c35b0c73d4.jpg

 

Edited by hawihoney
  • Like 3
Link to comment
1 hour ago, Greyberry said:

Kann man das User Script irgendwie über das Device Script aufrufen?

 

Keine Ahnung, ich denke nicht. Das sind meinem Verständnis nach zunächst einmal zwei Paar Schuhe:

 

1.) Ein Stick/Device, wie hier in diesem Thread gefordert, steckt immer drin und wird 1x pro Monat automatisch gemounted, beschrieben und wieder abgemeldet

   --> User Script

 

2.) Du willst einen Stick einstecken, dann das Skript automatisch laufen lassen, ...

   --> Device Script

 

Ein Device Skript sieht schon inhaltlich ganz anders aus als ein User Skript. Guck Dir das mal an.

 

Du könntest vielleicht den eigentlichen Job in ein User Script packen und diesen aus dem Device Script aufrufen. Aber so weit bin ich noch nie gegangen. Bei mir rennen manuell/automatisch dutzende Skripte - jeden Tag, jede Woche, jeden Monat, jedes Jahr, beim Start des Arrays, etc. etc. etc. das reicht mir.

 

Edited by hawihoney
Link to comment
18 minutes ago, dlandon said:

Cut and paste the User Script text into the proper action area of the Device Script.

 

Ahem, don't I need the ACTION ADD, etc. stuff then? I simply put a Python script to rsync something from A to B into that Device Script field? And that's all? Who does mount then?

 

If this is true, I never got the help text on that page ...

 

Edited by hawihoney
Link to comment

Try this procedure:

  • Set up your device script to do what you want when the device is plugged in.
  • Use the default script and don't remove any events.  They don't do anything unless you add code, and your code will need to use the correct event.
  • Call your python script in the UD device script.
  • Set the device to auto mount.

Your UD device script will look like this:

#!/bin/bash
#
# Available variables:
#
# ACTION - if mounting, ADD; if unmounting, UNMOUNT; if unmounted, REMOVE; if error, ERROR_MOUNT, ERROR_UNMOUNT
# DEVICE - partition device, e.g. /dev/sda1
# UD_DEVICE - unassigned devX designation
# SERIAL - disk serial number
# LABEL - partition label
# LUKS - if the device is encrypted, this is the partition device, e.g. /dev/sda1
# FSTYPE - partition filesystem
# MOUNTPOINT - where the partition is mounted
# OWNER - "udev" if executed by UDEV, otherwise "user"
# PROG_NAME - program name of this script
# LOGFILE - log file for this script

case $ACTION in
  'ADD' )
    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Device mounted" -i "normal"

    if [ "$OWNER" = "udev" ]; then
        # put your python script execution here
        execute python script					<====== your script
    else
        # do your user initiated stuff here
        sleep 1
    fi
  ;;

  'UNMOUNT' )
    # do your stuff here

    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Device unmounting" -i "normal"
  ;;

  'REMOVE' )
    # do your stuff here

    # Spin down disk - uncomment this if you want the disk to be spun down after the disk is unmounted
   /usr/local/sbin/rc.unassigned spindown $DEVICE

    # Detach the disk - uncomment this if you want the USB disk to be detached after it is unmounted
   /usr/local/sbin/rc.unassigned detach $DEVICE

    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Device unmounted" -i "normal"
  ;;

  'ERROR_MOUNT' )
    # do your stuff here

    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Error mounting device" -i "alert"
  ;;

  'ERROR_UNMOUNT' )
    # do your stuff here

    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Error unmounting device" -i "alert"
  ;;
esac

Now when you plug in the device the script will execute and perform your python stuff.

 

Notice the 'REMOVE' event will spin down and detach your device.  Leave the device installed and detached.

 

Once you have it running, set up a User Script on a cron to attach the device.  The 'Attach' creates a udev hot plug event.  UD will then mount the device (if auto mount is on) and run the device script.  When it's finished the device will be spun down and detached again.

 

  • Like 2
  • Thanks 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...