[Plugin] CA User Scripts


Recommended Posts

53 minutes ago, tschinz said:

Hello guys,

 

i've tried searching within this huge thread but I couldn't find a working answer. I want to call from one user script another user script. For this the following command was used.


echo "/boot/config/plugins/user.scripts/scripts/backup_onedrive/script" | at now

 

But I got following error


sh: line 18: /boot/config/plugins/user.scripts/scripts/backup_onedrive/script: Permission denied

 

I tried via the console to 


sudo chmod +x /boot/config/plugins/user.scripts/scripts/backup_onedrive/script

 

But the execute x flag is never applied.

 

Any tips or hints?

 

Thanks in advance

 

tschinz

Put 'bash' in front of the command. Like 'bash /boot/config/plugins/user.scripts/scripts/backup_onedrive/script'

Link to comment
2 hours ago, ICDeadPpl said:

Put 'bash' in front of the command. Like 'bash /boot/config/plugins/user.scripts/scripts/backup_onedrive/script'

Thanks ICDeadPpl, that worked. I've in one main script multiple sub user scripts I would like to launch. Is it possible to wait for one command to finish before launching the next? Currently both are started at the same time because of the "at now" command. I there a method to launch the second after the first is finished.

 

Thanks for the help

Link to comment
25 minutes ago, tschinz said:

Thanks ICDeadPpl, that worked. I've in one main script multiple sub user scripts I would like to launch. Is it possible to wait for one command to finish before launching the next? Currently both are started at the same time because of the "at now" command. I there a method to launch the second after the first is finished.

 

Thanks for the help

just do everything in one script, dont think there is a easy way. you could save a text file in the sub-scripts and wait for the file to appear in the main script

Link to comment
3 hours ago, Marcel40625 said:

Hey there,

 

i would like to know how i can mail the whole output of

 


rsync -av --delete --ignore-errors -e

 

as notification

 

thanks in advance

You could call '/usr/local/emhttp/webGui/scripts/notify' from your script, and have the message include the output of the rsync job.
The rsync output could be temporarily stored as a file, piped argument, named pipe or whatever.

Run the command '/usr/local/emhttp/webGui/scripts/notify' once without any arguments to see which there are for you to use.

You may want to check the notifications in Unradid Web UI "Settings/Notifications settings" so they are set to send email.

Link to comment
10 minutes ago, ICDeadPpl said:

You could call '/usr/local/emhttp/webGui/scripts/notify' from your script, and have the message include the output of the rsync job.
The rsync output could be temporarily stored as a file, piped argument, named pipe or whatever.

Run the command '/usr/local/emhttp/webGui/scripts/notify' once without any arguments to see which there are for you to use.

You may want to check the notifications in Unradid Web UI "Settings/Notifications settings" so they are set to send email.

 

yeah but how can i attach the file or output from rsync to the notify command

 

/usr/local/emhttp/webGui/scripts/notify -i normal -s "Test" -d "Test" -m < test.txt 

 

does not work the content of the file is not showing in notification

Link to comment
2 minutes ago, Marcel40625 said:

 

yeah but how can i attach the file or output from rsync to the notify command

 


/usr/local/emhttp/webGui/scripts/notify -i normal -s "Test" -d "Test" -m < test.txt 

 

does not work the content of the file is not showing in notification

Try
 

MESSAGE=`rsync -av --delete --ignore-errors -e`
/usr/local/emhttp/webGui/scripts/notify -i normal -s "Test" -d "Test" -m "$MESSAGE"

 

Link to comment
51 minutes ago, ICDeadPpl said:

Try
 


MESSAGE=`rsync -av --delete --ignore-errors -e`
/usr/local/emhttp/webGui/scripts/notify -i normal -s "Test" -d "Test" -m "$MESSAGE"

 

 

thanks, but found out tail works

 

/usr/local/emhttp/webGui/scripts/notify -i normal -s "Test" -d "Test" -m "`tail logfile.log`"

 

Link to comment
3 minutes ago, Marcel40625 said:

thanks, but found out tail works

 

One problem with all of this is that IF there's a double quote within the output of the tail then you'll either get weird results in the message, or the notify command itself will fail.

Link to comment
13 minutes ago, Squid said:

One problem with all of this is that IF there's a double quote within the output of the tail then you'll either get weird results in the message, or the notify command itself will fail.

thanks for the advice, but seems to work in this case :) and doesnt help ` ` for that?

Edited by Marcel40625
Link to comment

plugin: installing: https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg
plugin: downloading https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg
plugin: downloading: https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg ... done

+==============================================================================
| Installing new package /boot/config/plugins/user.scripts/user.scripts-2021.03.10-x86_64-1.txz
+==============================================================================

Verifying package user.scripts-2021.03.10-x86_64-1.txz.
Unable to install /boot/config/plugins/user.scripts/user.scripts-2021.03.10-x86_64-1.txz: tar archive is corrupt (tar returned error code 2)





----------------------------------------------------
user.scripts has been installed.
Copyright 2016-2020, Andrew Zawadzki
Version: 2021.03.10
----------------------------------------------------

plugin: user.scripts.plg installed
 

what is the problem when I install this plugin...pls help, thx

what is the problem when I install this plugin...pls help, thx

what is the problem when I install this plugin...pls help, thx a lot

 

 

Link to comment
  • 2 weeks later...
  • 2 weeks later...
11 minutes ago, ProphetSe7en said:

Thanks. That covers one part of want I want. Still need to figure out how to stop/pause all torrents and then restart them after mover is done

Without delving into whether it's possible to interact with rtorrent at that level, can't you just stop and start the docker with "docker stop <name-of-container>" and "docker start <name-of-container>" commands?

Link to comment
29 minutes ago, ProphetSe7en said:

Probably, but stopping a torrent container can cause problems if a torrent is during dl or recently finished and no session has been saved the last 20 minutes. So I prefere to sett all active torrents in a pause state, run mover then resume all torrents

docker pause <name-of-container> / docker unpause <name-of-container> then?

Link to comment

Hmm. That might work, need to test it first :)

Do you know if it is possible to issue the pause command only if cache is >60% full? No need to pause the container if mover wont run because of cache drive is less the 60% full.

 

I know mover can be started using script, and from mover settings it wont run if cache is less than 60%. But while doing this with a script it will cause rtorrent to pause/resume each time the script runs regardless of mover will be running or not

 

Edit: So I need to add the pause & unpause command to the mover script? Clearly the "docker pause/unpause rtorrentvpn" wont work like this, but what format should it be in to work?
 

if ( $percent > $moveAt ) {
  docker pause rtorrentvpn;
  exec("/usr/local/sbin/mover");
  docker unpause rtorrentvpn;
}

 

Edited by ProphetSe7en
Link to comment
1 hour ago, ProphetSe7en said:

Clearly the "docker pause/unpause rtorrentvpn" wont work like this, but what format should it be in to work?

I'm not at my machine at the moment, but somebody else would know better.  Your script would pause the docker (assuming that's the correct name), but I'm guessing it would unpause it straight away.

 

You'd need a second part to the script in an else block that checks if docker is paused and whether the mover is running.  If the mover has finished, unpause.  Something like...

 

if ( $percent > $moveAt ) {
  docker pause rtorrentvpn;
  exec("/usr/local/sbin/mover");
} else {
  if (!moverRunning && dockerIsPaused) {
    docker unpause rtorrentvpn;
  }
}

...although without researching I don't know how to check if the mover is running and a docker is paused - this is just to illustrate the concept.

Link to comment
6 hours ago, Cessquill said:

I'm not at my machine at the moment, but somebody else would know better.  Your script would pause the docker (assuming that's the correct name), but I'm guessing it would unpause it straight away.

 

You'd need a second part to the script in an else block that checks if docker is paused and whether the mover is running.  If the mover has finished, unpause.  Something like...

 

Hmm. I thought if I put the command under the "if" part of that script it would only be issued if the cache disk is >xx% ful, like the mover would in the script?

 

Maybe I am mistaken, but in this script everything under "if" only runs if the disk threshold is met?

 

#!/usr/bin/php
<?PHP

$moveAt = 70;    # Adjust this value to suit.

$diskTotal = disk_total_space("/mnt/cache");
$diskFree = disk_free_space("/mnt/cache");
$percent = ($diskTotal - $diskFree) / $diskTotal * 100;

if ( $percent > $moveAt ) {
  exec("/usr/local/sbin/mover");
}
?>

 

So I need to figure out on how to combine the script above with these commands.

 

docker exec comand

mover &&

docker exec comand (when mover is finished)

 

Not very elegant, but can I replace  

exec("/usr/local/sbin/mover");

 with

exec("/mnt/user/various/unRaid/script/mover.sh);

 

Then in the mover.sh I have the 

docker exec (command to pause all torrents)
mover &&
docker exec (command to start all torrents)

 

I get it to work, but then I dont have the threshold part in place.

Link to comment

Hey all,

This might be a more generic unix question but is there an easy way to enable timestamps for all logs that a "userscript" would produce?

quick googling i can do things like pipe my commands into various things to achieve this but i was wondering if there was an easy "turn on for everything in unraid" or maybe just "turn on for user scripts logs"?

Thanks in advance!

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.