[Plugin] CA User Scripts


Recommended Posts

Great plugin but now I am running into problems with a new script I have created. Keep in mind I don't really know what I am doing.

The script's purpose is to start inotifywait and watch a folder and when the correct files are found call another script to deal with it. When I run the script either by manually clicking the "run in background" button or if I run the script from terminal it runs perfectly. However if I set the script to run on array start and do a reboot of unraid the following happens.

- unraid boots but the webgui does not start and none of my shares are mapped.

- I can see and access the flash share 

- I can see my share created by the unassigned device plugin but I can not access it.

- I can ping and ssh into the server

In order to get the server to start correctly I have to go into the user.scripts schedule.json file and change the schedule for the script to disabled and reboot.

Script is below.

Any ideas?

 

#!/bin/bash

#backgroundOnly=true
#arrayStarted=true

#grabdir=/mnt/disks/appshare/apps/downloads/seedbox/tmp_process/grab
watchdir="/mnt/disks/appshare/apps/downloads/seedbox/tmp_process/start/"
tvlftp=/mnt/disks/appshare/apps/scripts/son_rad_arr_scripts/tv_lftp.sh
movielftp=/mnt/disks/appshare/apps/scripts/son_rad_arr_scripts/movie_lftp.sh
logdir="/mnt/disks/appshare/apps/scripts/son_rad_arr_scripts/logs"
dt=$(date '+%m/%d/%Y %H:%M:%S');

echo "$dt" inotifywait started >> $logdir/torrent_notify.log

inotifywait -m -e moved_to --format %f $watchdir | while read f; do echo "$f";


if [[ $f == *.tvstart ]]
	then
	"$tvlftp" $f

elif [[ $f == *.moviestart ]]
	then
	"$movielftp" $f
fi

done

 

Link to comment

The reason why is because the script never ends.  I'm going to have to look at the code again as scripts started with the arry are not supposed to hang the system until they complete

 

Your easiest way to get it to start is to rename the file script within the appropriate folder on the flash drive /config/plugins/user.scripts/scripts

Link to comment
3 hours ago, Squid said:

Your easiest way to get it to start is to rename the file script within the appropriate folder on the flash drive /config/plugins/user.scripts/scripts

That's too bad.  Any ideas how i can get this inotify script to auto run on boot with or without your userscript plugin? Well I ended up adding it to the go file and all seems to be working.

Also, 

Im not sure I understand this last bit of your response.  "to get it to start" meaning to get the server to start properly or the script to start properly I can change the name of the script file.  I assume you mean to get the server to start correctly since changing the name will break the userscript plugin from starting it. 

Edited by shinedou
Link to comment
19 hours ago, itimpi said:

I was wongering if there is any chance of getting some more standard scheduling options added to correspond to Unraid events such as 'starting' ,  'stopping' and 'stopped'.   I was was thinking that this would allow me do via User Scripts commands that I currently do via the 'go' and 'stop' files.   Some of the other event types might also be worth considering if you think this is feasible but the ones I mentioned are of interest to me at the moment.

My request is similar.  I have a pfsense VM which means my server doesn't have connectivity until the VM has started up.  This means I currently run some scripts as */5 * * * * to give the VM 5 mins to startup.

 

What I really want to do is run the script just once xx mins after array start, rather than having it run every 5 mins forever.  On reflection, I guess I could add a sleep 300 to my array start script, but it'd be nice if I could control this in my scheduling.

Link to comment
21 hours ago, itimpi said:

I was wongering if there is any chance of getting some more standard scheduling options added to correspond to Unraid events such as 'starting' ,  'stopping' and 'stopped'.   I was was thinking that this would allow me do via User Scripts commands that I currently do via the 'go' and 'stop' files.   Some of the other event types might also be worth considering if you think this is feasible but the ones I mentioned are of interest to me at the moment.

That actually is on the todo list...  Supporting most of the built-in events, rather than just disks_mounted  Pretty painless for me to add to it.  

 

Of course, that brings up some caveats for the users as it's a pain to understand the subtleties between some of them.  Maybe I'd just have certain of the events listed as "recommended".

 

2 hours ago, DZMM said:

My request is similar.  I have a pfsense VM which means my server doesn't have connectivity until the VM has started up.  This means I currently run some scripts as */5 * * * * to give the VM 5 mins to startup.

 

What I really want to do is run the script just once xx mins after array start, rather than having it run every 5 mins forever.  On reflection, I guess I could add a sleep 300 to my array start script, but it'd be nice if I could control this in my scheduling.

Having something run 5 minutes after array start I just don't foresee happening anytime soon.  The sleep is the way to do it.  Of course it does appear that there's an issue with scripts running at array start hanging the system, so I've got to figure that out over the next few days....

Link to comment
47 minutes ago, Squid said:

Of course, that brings up some caveats for the users as it's a pain to understand the subtleties between some of them.  Maybe I'd just have certain of the events listed as "recommended".

If you want I can create a post in the Programming sub-forum (or a wiki entry if that is deemed better) listing all the current events and their descriptions?   This can then be updated if any new ones are introduced, or with any additional information that comes to light, or to clarify things as a result of user feedback.  You could then add a link pointing to that in the built-in help for the plugin.

  • Thanks 1
Link to comment
50 minutes ago, itimpi said:

If you want I can create a post in the Programming sub-forum (or a wiki entry if that is deemed better) listing all the current events and their descriptions?   This can then be updated if any new ones are introduced, or with any additional information that comes to light, or to clarify things as a result of user feedback.  You could then add a link pointing to that in the built-in help for the plugin.

That's one way to force my hand lol....

Link to comment

Help please.  I'm trying to call another user script from a user script.

 

# script1

#!/bin/bash
some code
exit
# script 2 

#!/bin/bash

source /boot/config/plugins/user.scripts/scripts/script1/script

more code

exit

The problem I'm having is the exit in script 1 i.e. the child is exiting the parent script 2 as well.  Is there a way to avoid this happening and letting the parent resume? 

 

I found this on the net https://unix.stackexchange.com/questions/217650/call-a-script-for-another-script-but-dont-exit-the-parent-if-the-child-calls-e/356018 but when I try ./boot/config/plugins/user.scripts/scripts/script1/script I get 'no such file or directory'.

Link to comment

Squid I’m curious if you could shed some light on this.

I’ve tried setting my unraid server to start at a certain time via the bios. I set the bios to my current local time (PST) but it doesn’t hold even with a fresh battery.  When Unraid starts it corrects the time of course.  The only way I can set my system to come on at a certain time is to -8:00 hours then it come on at my local time.  I understand the MB Bios and Unraid are two different systems.

I’ve never seen this before in any build, I’ve done. It just seems to revert to GMT.

It really has me baffled.

I noticed the below error and tried to correct it.

Any thoughts?

 

“: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized”

server-syslog-20200220-0144.zip

Link to comment
7 hours ago, itimpi said:

Where you have MON it should be a value in the range 1 to 12 for month of the year or * for all months.

The last field should be day of week.  Allowed values are 0-6, 7 for Sunday or SUN-SAT.

 

0 6 * * MON is 06:00 on Monday

 

From the crontab man page crontab(5) :

field          allowed values
-----          --------------
minute         0-59
hour           0-23
day of month   1-31
month          1-12 (or names, see below)
day of week    0-7 (0 or 7 is Sunday, or use names)

 

Edited by JoeUnraidUser
Link to comment
33 minutes ago, JoeUnraidUser said:

The last field should be day of week.  Allowed values are 0-6, 7 for Sunday or SUN-SAT.

 

0 6 * * MON is 06:00 on Monday

 

From the crontab man page crontab(5) :


field          allowed values
-----          --------------
minute         0-59
hour           0-23
day of month   1-31
month          1-12 (or names, see below)
day of week    0-7 (0 or 7 is Sunday, or use names)

 

According to the man page you quoted the last field should be 0 to 7. Monday would be 1 rather than MON.

Link to comment
31 minutes ago, wgstarks said:

According to the man page you quoted the last field should be 0 to 7. Monday would be 1 rather than MON.

"or use names" means SUN-SAT or sun-sat.

 

Example crontab line from man page crontab(5):

5 4 * * sun     echo "run at 5 after 4 every sunday"

Edit:

Also from man page crontab(5):

Names can also be used for the 'month' and 'day of week' fields.  Use
the first three letters of the particular day or month (case does not
matter).  Ranges or lists of names are not allowed.

 

Edited by JoeUnraidUser
Link to comment
2 hours ago, Squid said:

Not 100% sure if MON, TUE etc works within unRaid.  Safest to use the numerals

Your right it doesn't work.  I tested it using "MON" and it failed.  It looks like Unraid is using "crond 4.5 dillon's cron daemon".

 

It's strange because the man page crontab(1) for "dillon's lightweight cron daemon" contains:

a symbolic range for the day of week and  month  in  year
# run at 11 am on the first and last Mon, Tue, Wed of each month
0 11 1,5 * mon-wed date

Edit:

I tested it again using "mon" and it worked.  It must only work with lowercase days of the week.

 

Edited by JoeUnraidUser
Link to comment
9 minutes ago, Squid said:

Use the notify command built in

 

/usr/local/emhttp/plugins/dynamix/scripts/notify

 

By default that shows a red notification as if there's an error.  Is there a way to manipulate the color displayed?

 

Nvmd, was using the old WebGUI notification.  Thanks.

Edited by IamSpartacus
Link to comment
18 minutes ago, IamSpartacus said:

and is there a variable one can use to call the name of the script?

How do you mean?
You can use command substitution if you want the warning to display the output of a command:

WarningText="$(somecommand -someoption somefile.someextension)"
then use "$WarningText" where you would like the output of that command.

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.