Additional Scripts For User.Scripts Plugin


Recommended Posts

42 minutes ago, johnnie.black said:

There's not, that's only for a parity protected array, and if you don't want to re-sync parity when shrinking the array.

I wish any of the documentation had told me that before!

 

I can't find a way to create an account and be able to fix the unraid wiki...

Link to comment
On 8/8/2017 at 2:17 AM, Squid said:

Automatically save syslog onto flash drive

 

Set the script to run at First Only Array Start in the background


#!/bin/bash
mkdir -p /boot/logs
FILENAME="/boot/logs/syslog-$(date +%s)"
tail -f /var/log/syslog > $FILENAME

 

My first script. Slightly improved/different version that is run on array stopping and zipped. Would be nice if there's a shutdown event instead.

#!/bin/bash
#description=Zips the syslog to flash
#name=Syslog Backup
cp /var/log/syslog syslog.txt
mkdir -p /boot/logs
FILENAME="/boot/logs/syslog-$(date +%y%m%d-%H%M)"
zip $FILENAME syslog.txt
rm syslog.txt
Link to comment

I have the following script:

 

#!/bin/bash
#arrayStarted=true

# copy configs and restart zsh
cp /mnt/user/test/.zshrc ~ && cp /mnt/user/test/.p10k.zsh ~ && exec zsh

# install youtube-dl with softlink
cp /mnt/user/test/youtube-dl/youtube-dl /usr/local/bin && chmod +x /usr/local/bin/youtube-dl

# install bashtop and +x
cp /mnt/user/test/bashtop/bashtop /usr/local/bin && chmod +x /usr/local/bin/bashtop 

It's set to run "At First Array Start Only".

 

The first command always seems to run fine. The other two never do.

 

How come? And how do it get it work?

Link to comment

its the exec line. exec stops the current process and replaces it whatever you exec'd - so in this script. once it exec's the zsh, then the entire script stops and a zsh process runs and exits.

 

Reading the script indicates exec'ing zsh is point less. why are you trying to reload zsh? its not even running as the #! of the script is bash.

  • Thanks 1
Link to comment
8 hours ago, ken-ji said:

its the exec line. exec stops the current process and replaces it whatever you exec'd - so in this script. once it exec's the zsh, then the entire script stops and a zsh process runs and exits.

 

Reading the script indicates exec'ing zsh is point less. why are you trying to reload zsh? its not even running as the #! of the script is bash.

Thanks. I'll move that last. A previous script changes shell to zsh.

Link to comment
  • 4 weeks later...
On 11/16/2018 at 6:15 PM, oliverde8 said:

Hi, 

 

First of all thanks alot for all these community tools. 

 

I ended up here looking for a way to make my KVM work with unraid, everytime I switched PC's the VM which has unraid on it lost the usb devices which was quote annoying. 

 

I ended up finding the "USB Hot Plug for VM's with no passthrough" script. I had 2 issues.

  • For some reasons, I have everything in a single bus and I wanted to ignore some of the usb devices. 
  • The KVM switches 3 devices, the kvm, mouse & keyboard.  Having 3 of them switch simultaneously seems to create issues as one of them don't work randomly in windows

I fixed these by

  • Adding a $ignoredDevices variable with the name of the devices I want to ignore
  • Added a $waitBetweenPlugs delay, basically for plugging and unplugging it will wait a bit in between. 

#!/usr/bin/php
<?PHP
#backgroundOnly=true
#description=A script designed to monitor a USB hub or a particular USB bus for changes and then attach or detach devices to an applicable VM

/*
 * Configuration's
 */
$vmName = "Windows 10";  // must be the exact name
$pollingTime = 10;       // the interval between checks in seconds
$startupDelay = 300;     // startup delay before monitoring for changes in seconds (set to enough time for the VM to get up and running)
$waitBetweenPlugs = 10;  // If using a device such a KVM mounting multiple usb drives at once can cause some issues with the host. Wait in between.

$ignoredDevices = [      // List of device names that should be ignored.
	'Ours Technology, Inc. Transcend JetFlash 2.0 / Astone USB Drive / Intellegent Stick 2.0' // must be exact as listed via lsusb
];

// only use one or the other of the following lines not both  See thread for details
#$hubName = "Texas Instruments, Inc. TUSB2046 Hub";  // must be exact as listed via lsusb
$bus  = "003";                                       // see thread for details

/**
 * Code don't change from here on.
 */
 
function getDeviceList($bus, $ignoredDevices) {
  exec("lsusb | grep 'Bus $bus'",$allDevicesOnBus);
  foreach ($allDevicesOnBus as $Devices) {
    $deviceLine = explode(" ",$Devices);
	if (!in_array($deviceLine[5], $ignoredDevices)) {
		$initialState[$deviceLine[5]] = $deviceLine[5];
	} else {
		logger("Ignoring device $Devices");
	}
    var_dump();
  }
  return $initialState;
}  

function createXML($deviceID, $waitBetweenPlugs) {
  sleep($waitBetweenPlugs);
  $usb = explode(":",$deviceID);
  $usbstr .= "<hostdev mode='subsystem' type='usb'>
                <source>
                  <vendor id='0x".$usb[0]."'/>
                  <product id='0x".$usb[1]."'/>
                </source>
              </hostdev>";
  file_put_contents("/tmp/USBTempXML.xml",$usbstr);
}

function logger($string) {
  echo "$string\n";
  shell_exec("logger ".escapeshellarg($string));
}
              
# Begin Main

logger("Sleeping for $startupDelay before monitoring $bus for changes to passthrough to $vmName");
sleep($startupDelay);

$hubBus = $bus;
if ( ! $hubBus ) {
  $hub = explode(" ",exec("lsusb | grep '$hubName'"));
  $hubBus = $hub[1];
}

logger("Monitoring $hubBus for changes");

$initialState = getDeviceList($hubBus, $ignoredDevices);

while (true) {
  $unRaidVars = parse_ini_file("/var/local/emhttp/var.ini");
  if ($unRaidVars['mdState'] != "STARTED") {
    break;
  }
  $currentDevices = getDeviceList($hubBus, $ignoredDevices);
  
  foreach ($currentDevices as $Device) {
    if ( ! $initialState[$Device] ) {
      logger("$Device Added to bus $hubBus  Attaching to $vmName");
      createXML($Device, $waitBetweenPlugs);
      exec("/usr/sbin/virsh attach-device '$vmName' /tmp/USBTempXML.xml 2>&1");
      $initialState[$Device] = $Device;
    }
  }
  foreach ($initialState as $Device) {
    if ( ! $currentDevices[$Device] ) {
      logger("$Device Removed from bus $hubBus  Detaching from $vmName");
      createXML($Device, $waitBetweenPlugs);
      exec("/usr/sbin/virsh detach-device '$vmName' /tmp/USBTempXML.xml 2>&1");
      unset ($initialState[$Device]);
    }
  }
  sleep($pollingTime);
}

?>

The KVM fix isn't perfect sometimes it still doesn't work I am going to try and spend some more time for maybe a better solution then a sleep. 

 

Lastly wouldn't it be better to have these scripts in github somewhere? grouped in one project?

Hey, @oliverde8 I am messing with your revision of @Squid 's cool hot swap script. I am trying to hot swap a keyboard and mouse through a hub (similar to your KVM situation). For reference the script is named "KM Script." I am running into an issue where it works for a few seconds and then everything automatically disconnects. I have tried both via the bus option and with the hubname option with both the same result. Additionally, I keep getting the following error every few seconds in the logs. Attached is my version of the script and a snip from my logs. Any insight would be appreciated.

 

V/R

 

Revrto

 

LSUSB:

 

Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 002: ID 0781:5571 SanDisk Corp. Cruzer Fit
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 05e3:0612 Genesys Logic, Inc. Hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 051d:0003 American Power Conversion UPS
Bus 003 Device 009: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 8087:0aa7 Intel Corp. 
Bus 001 Device 003: ID 1e71:170e NZXT NZXT USB Device
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

 

MY VERSION OF SCRIPT:

 

#!/usr/bin/php
<?PHP
#backgroundOnly=true
#description=A script designed to monitor a USB hub or a particular USB bus for changes and then attach or detach devices to an applicable VM

/*
 * Configuration's
 */
$vmName = "Truff-Metal";  // must be the exact name
$pollingTime = 10;       // the interval between checks in seconds
$startupDelay = 10;     // startup delay before monitoring for changes in seconds (set to enough time for the VM to get up and running)
$waitBetweenPlugs = 10;  // If using a device such a KVM mounting multiple usb drives at once can cause some issues with the host. Wait in between.

$ignoredDevices = [       // List of device names that should be ignored.
    'American Power Conversion UPS / Linux Foundation 2.0 root hub' // must be exact as listed via lsusb
];

// only use one or the other of the following lines not both  See thread for details
$hubName = "Genesys Logic, Inc. 4-port hub"; // must be exact as listed via lsusb
#$bus = "003";                                       // see thread for details

/**
 * Code don't change from here on.
 */
 
function getDeviceList($bus, $ignoredDevices) {
  exec("lsusb | grep 'Bus $bus'",$allDevicesOnBus);
  foreach ($allDevicesOnBus as $Devices) {
    $deviceLine = explode(" ",$Devices);
    if (!in_array($deviceLine[5], $ignoredDevices)) {
        $initialState[$deviceLine[5]] = $deviceLine[5];
    } else {
        logger("Ignoring device $Devices");
    }
    var_dump();
  }
  return $initialState;
}  

function createXML($deviceID, $waitBetweenPlugs) {
  sleep($waitBetweenPlugs);
  $usb = explode(":",$deviceID);
  $usbstr .= "<hostdev mode='subsystem' type='usb'>
                <source>
                  <vendor id='0x".$usb[0]."'/>
                  <product id='0x".$usb[1]."'/>
                </source>
              </hostdev>";
  file_put_contents("/tmp/USBTempXML.xml",$usbstr);
}

function logger($string) {
  echo "$string\n";
  shell_exec("logger ".escapeshellarg($string));
}
              
# Begin Main

logger("Sleeping for $startupDelay before monitoring $bus for changes to passthrough to $vmName");
sleep($startupDelay);

$hubBus = $bus;
if ( ! $hubBus ) {
  $hub = explode(" ",exec("lsusb | grep '$hubName'"));
  $hubBus = $hub[1];
}

logger("Monitoring $hubBus for changes");

$initialState = getDeviceList($hubBus, $ignoredDevices);

while (true) {
  $unRaidVars = parse_ini_file("/var/local/emhttp/var.ini");
  if ($unRaidVars['mdState'] != "STARTED") {
    break;
  }
  $currentDevices = getDeviceList($hubBus, $ignoredDevices);
  
  foreach ($currentDevices as $Device) {
    if ( ! $initialState[$Device] ) {
      logger("$Device Added to bus $hubBus  Attaching to $vmName");
      createXML($Device, $waitBetweenPlugs);
      exec("/usr/sbin/virsh attach-device '$vmName' /tmp/USBTempXML.xml 2>&1");
      $initialState[$Device] = $Device;
    }
  }
  foreach ($initialState as $Device) {
    if ( ! $currentDevices[$Device] ) {
      logger("$Device Removed from bus $hubBus  Detaching from $vmName");
      createXML($Device, $waitBetweenPlugs);
      exec("/usr/sbin/virsh detach-device '$vmName' /tmp/USBTempXML.xml 2>&1");
      unset ($initialState[$Device]);
    }
  }
  sleep($pollingTime);
}

?>

 

LOG:

 

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35
046d:c07e Added to bus Attaching to Truff-Metal
04d9:a0d1 Added to bus Attaching to Truff-Metal
05e3:0610 Added to bus Attaching to Truff-Metal

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35
046d:c07e Removed from bus Detaching from Truff-Metal
04d9:a0d1 Removed from bus Detaching from Truff-Metal

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

 

Link to comment
  • 4 weeks later...

Here's a very simple script to clear out the index database of a Syncthing docker container.  The reason for this script is dependent on your usage of Syncthing.  For me, I wanted to be able to clear out all the "local additions" and out of sync files listed.  In my scenario I don't care about any of the stuff Syncthing thinks is out of sync, and want it removed.

 


#!/bin/bash
find /mnt/user/appdata/syncthing/ -name "index*" -print0 | xargs -r0 -- rm -r
docker restart syncthing

 

You'd only have to change the path to your syncthing appdata location if it has a different name, and then the docker name if it's different.

  • Like 1
Link to comment
  • 3 months later...

  

On 6/10/2020 at 8:29 PM, Revrto said:

Hey, @oliverde8 I am messing with your revision of @Squid 's cool hot swap script. I am trying to hot swap a keyboard and mouse through a hub (similar to your KVM situation). For reference the script is named "KM Script." I am running into an issue where it works for a few seconds and then everything automatically disconnects. I have tried both via the bus option and with the hubname option with both the same result. Additionally, I keep getting the following error every few seconds in the logs. Attached is my version of the script and a snip from my logs. Any insight would be appreciated.

 

V/R

 

Revrto

 

LSUSB:

 

Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 002: ID 0781:5571 SanDisk Corp. Cruzer Fit
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 05e3:0612 Genesys Logic, Inc. Hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 051d:0003 American Power Conversion UPS
Bus 003 Device 009: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 8087:0aa7 Intel Corp. 
Bus 001 Device 003: ID 1e71:170e NZXT NZXT USB Device
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

 

MY VERSION OF SCRIPT:

 

#!/usr/bin/php
<?PHP
#backgroundOnly=true
#description=A script designed to monitor a USB hub or a particular USB bus for changes and then attach or detach devices to an applicable VM

/*
 * Configuration's
 */
$vmName = "Truff-Metal";  // must be the exact name
$pollingTime = 10;       // the interval between checks in seconds
$startupDelay = 10;     // startup delay before monitoring for changes in seconds (set to enough time for the VM to get up and running)
$waitBetweenPlugs = 10;  // If using a device such a KVM mounting multiple usb drives at once can cause some issues with the host. Wait in between.

$ignoredDevices = [       // List of device names that should be ignored.
    'American Power Conversion UPS / Linux Foundation 2.0 root hub' // must be exact as listed via lsusb
];

// only use one or the other of the following lines not both  See thread for details
$hubName = "Genesys Logic, Inc. 4-port hub"; // must be exact as listed via lsusb
#$bus = "003";                                       // see thread for details

/**
 * Code don't change from here on.
 */
 
function getDeviceList($bus, $ignoredDevices) {
  exec("lsusb | grep 'Bus $bus'",$allDevicesOnBus);
  foreach ($allDevicesOnBus as $Devices) {
    $deviceLine = explode(" ",$Devices);
    if (!in_array($deviceLine[5], $ignoredDevices)) {
        $initialState[$deviceLine[5]] = $deviceLine[5];
    } else {
        logger("Ignoring device $Devices");
    }
    var_dump();
  }
  return $initialState;
}  

function createXML($deviceID, $waitBetweenPlugs) {
  sleep($waitBetweenPlugs);
  $usb = explode(":",$deviceID);
  $usbstr .= "<hostdev mode='subsystem' type='usb'>
                <source>
                  <vendor id='0x".$usb[0]."'/>
                  <product id='0x".$usb[1]."'/>
                </source>
              </hostdev>";
  file_put_contents("/tmp/USBTempXML.xml",$usbstr);
}

function logger($string) {
  echo "$string\n";
  shell_exec("logger ".escapeshellarg($string));
}
              
# Begin Main

logger("Sleeping for $startupDelay before monitoring $bus for changes to passthrough to $vmName");
sleep($startupDelay);

$hubBus = $bus;
if ( ! $hubBus ) {
  $hub = explode(" ",exec("lsusb | grep '$hubName'"));
  $hubBus = $hub[1];
}

logger("Monitoring $hubBus for changes");

$initialState = getDeviceList($hubBus, $ignoredDevices);

while (true) {
  $unRaidVars = parse_ini_file("/var/local/emhttp/var.ini");
  if ($unRaidVars['mdState'] != "STARTED") {
    break;
  }
  $currentDevices = getDeviceList($hubBus, $ignoredDevices);
  
  foreach ($currentDevices as $Device) {
    if ( ! $initialState[$Device] ) {
      logger("$Device Added to bus $hubBus  Attaching to $vmName");
      createXML($Device, $waitBetweenPlugs);
      exec("/usr/sbin/virsh attach-device '$vmName' /tmp/USBTempXML.xml 2>&1");
      $initialState[$Device] = $Device;
    }
  }
  foreach ($initialState as $Device) {
    if ( ! $currentDevices[$Device] ) {
      logger("$Device Removed from bus $hubBus  Detaching from $vmName");
      createXML($Device, $waitBetweenPlugs);
      exec("/usr/sbin/virsh detach-device '$vmName' /tmp/USBTempXML.xml 2>&1");
      unset ($initialState[$Device]);
    }
  }
  sleep($pollingTime);
}

?>

 

LOG:

 

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35
046d:c07e Added to bus Attaching to Truff-Metal
04d9:a0d1 Added to bus Attaching to Truff-Metal
05e3:0610 Added to bus Attaching to Truff-Metal

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35
046d:c07e Removed from bus Detaching from Truff-Metal
04d9:a0d1 Removed from bus Detaching from Truff-Metal

Warning: var_dump() expects at least 1 parameter, 0 given in /tmp/user.scripts/tmpScripts/KM Switch/script on line 35

 

Not sure if you ended up fixing this but thought I'd chime in anyway as I just experienced the same issue. Essencially the var_dump() in getDeviceList expects an argument but the script isn't providing one. I don't really understand PHP but from what I have read I think this function is used to dump information about a variable, I don't know what dump means in this context but I'm getting the feeling it's used for debugging or logging.

I've fixed the issue by removing the var_dump call but I'm desperatly hoping that this function isn't some sort of garbage collection and I'm just creating a memory leak for myself, is anyone able to confirm please?

 

Edited by Trozmagon
Had wrong quote.
Link to comment
  • 2 months later...

Haven't come across anyone making a script like this before so I did it for myself ....... finally got around to making a basic script to back up Plex's databases (only).  I've always had Plex's appdata folder excluded from CA Backup because I didn't want 100000000000000000's of artwork/info files to be backed up, but I realized that it would be prudent to at least have the databases backed up (library contents, play history, etc).  Artwork and info can be recreated when needed.

 

So this is what I quickly did and suits my personal needs... 

 


#!/bin/bash

mkdir -p "/mnt/user/backups/Plex/$(date +"%d-%m-%Y")"
tar -cvaf /mnt/user/backups/Plex/$(date +"%d-%m-%Y")/Plex_Data_Backup.tar "/mnt/user/appdata/PlexMediaServer/Library/Application Support/Plex Media Server/Plug-in Support/Databases"

 

If anyone wants to use this you'll just change the appropriate path names to reflect your system.  I have it scheduled to run nightly.  There is obviously a need to delete old backups after a period of time as these backups can be multi-gigs in size.

  • Like 1
Link to comment

Hello Squid,

 

im a new user from Unraid and be amazed how good it works. I found now the user scripts and will try youre Move_share script. I added it with the new script button after unzip it in the destination you suggested. But it not works. Is there a documentation for the right steps to do? 

 

What is youre suggestion about the appdata share? Cache only? I cant find any clear advise what is better for the performance. 

 

Many greets

 

Martin

Link to comment
3 hours ago, Knigge said:

What is youre suggestion about the appdata share? Cache only? I cant find any clear advise what is better for the performance. 

Better for performance if appdata, domains, and system shares are all on cache since dockers/VMs won't have parity involved or keep array disks spinning.

 

Possibly you don't even need a script if that is what you are interested in but there may be more involved than this script can help with since open files cannot be moved.

 

I am guessing you are referring to these scripts in this old post, but it isn't clear to me that these scripts stop dockers and VMs as would be required if you wanted to move the shares I mentioned to cache.

 

 

Link to comment
5 hours ago, trurl said:

Better for performance if appdata, domains, and system shares are all on cache since dockers/VMs won't have parity involved or keep array disks spinning.

 

Possibly you don't even need a script if that is what you are interested in but there may be more involved than this script can help with since open files cannot be moved.

 

I am guessing you are referring to these scripts in this old post, but it isn't clear to me that these scripts stop dockers and VMs as would be required if you wanted to move the shares I mentioned to cache.

 

 

Hello trurl!

 

Thanks alot for youre explanation. After a bit more of exploration i understand how unraid with the docker works.

 

Greetings from Germany

 

Martin

Link to comment

In the "Move Array Only Shares" script, the message "All cache-only shares already only existed on the cache drive" is exactly the same as in the "Move Cache Only Shares".
Maybe it should say "All array-only shares already only existed on the array"?
The same with the message ""All shares set to be cache-only have now had their files previously existing on the array to now be on the cache drive", that should be "All shares set to be array-only have now had their files previously existing on the cache drive to now be on the array"

Link to comment

@RobJ I'm running your clear_array_drive script and have a few questions.

I'm currently looking at the the log file in /tmp/user.scripts/tmpScripts/clear_array_drive/log.txt which indicates the clear is happening at 1.5MB/s. It has churned through 300GB in 55hrs. At this rate it will take another 610 hours to complete.

 

Is this the expected speed with reconstruct_write (turbo write) enabled?

Can the script be safely canceled?

What if any ramifications are there when canceling the script?

Link to comment
On 12/27/2020 at 5:10 AM, ryanhaver said:

I'm currently looking at the the log file in /tmp/user.scripts/tmpScripts/clear_array_drive/log.txt which indicates the clear is happening at 1.5MB/s.

That script is very slow with recent Unraid releases, and the author has not been in the forums for a long time, but you can still do the procedure manually.

Link to comment
1 hour ago, coblck said:

Is these such a script to keep my drives spun up during the day say 9am to 10pm then spin down for the rest of the night ?

I use the second script on here to keep the disks spinning for Plex in the evenings.  Adjust the custom CRON schedule to suit your times and set the frequency of the CRON to retrigger a spin up before they'd naturally spin down.  I currently use */14 19-23 * * *  (every 14 minutes between 19:00 and 23:00)

Link to comment
On 12/27/2020 at 3:09 AM, JorgeB said:

That script is very slow with recent Unraid releases, and the author has not been in the forums for a long time, but you can still do the procedure manually.

Thanks for the info. I opted to just preserve my config, manually move data off a few drives and rebuild parity.

Edited by ryanhaver
Link to comment
  • 4 weeks later...
On 8/17/2019 at 2:53 AM, JoeUnraidUser said:

Script to convert text files from DOS to Unix format.

 

dos2unix 402 B · 188 downloads

 


#!/bin/bash

# Convert text files from DOS to Unix format.

if [ $# -eq 0 ] || [ "$1" == "--help" ]
then
	printf "Usage: dos2unix <files>...\n"
	exit 0
fi

for file in "${@}"
do
	user=$(stat -c '%U' "$file")
	group=$(stat -c '%G' "$file")
	perms=$(stat -c "%a" "$file")

	tmp="$file.$(date +%N)"
	cat "$file" | fromdos > "$tmp"
	mv "$tmp" "$file"

	chown $user:$group "$file"
	chmod $perms "$file"
done

 

Script to convert text files from Unix to DOS format.

 

  unix2dos 400 B · 104 downloads


#!/bin/bash

# Convert text files from Unix to DOS format.

if [ $# -eq 0 ] || [ "$1" == "--help" ]
then
	printf "Usage: unix2dos <files>...\n"
	exit 0
fi

for file in "${@}"
do
	user=$(stat -c '%U' "$file")
	group=$(stat -c '%G' "$file")
	perms=$(stat -c "%a" "$file")

	tmp="$file.$(date +%N)"
	cat "$file" | todos > "$tmp"
	mv "$tmp" "$file"

	chown $user:$group "$file"
	chmod $perms "$file"
done

 

Maybe a silly question, but how do I actually use your dos2unix script as a user script? Are user scripts added to PATH?

 

What I have done now, is create a file called dos2unix.sh somewhere on my array, which I then call in the CLI to do the conversion, but this does not use the User Scripts plugin. So I guess my question is: after adding your dos2unix script to the User Scripts plugin, how do I then actually go about using it?

Link to comment
3 hours ago, sgraaf said:

Maybe a silly question, but how do I actually use your dos2unix script as a user script? Are user scripts added to PATH?

 

What I have done now, is create a file called dos2unix.sh somewhere on my array, which I then call in the CLI to do the conversion, but this does not use the User Scripts plugin. So I guess my question is: after adding your dos2unix script to the User Scripts plugin, how do I then actually go about using it?

Run it from the user scripts plugin page (from settings)

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.