[Plugin] CA User Scripts


Recommended Posts

Just a simple little plugin to act as a front end for any little scripts that you may have that you may need to run every once in a while, and don't feel like dropping down to the command line to do it.  (Or anything that I happen to run across here on the forum that will be of use to some people)

 

Install it via Community Applications

 

Only a couple included scripts:

 

- Delete .DS_Store files from the array

- Delete any dangling images from the docker.img file

- Display the size of the docker container's log files (to see if a docker app is filling up the image file through excessive logging)

 

Additional Scripts from myself (and hopefully other users) can be found here:

 

To add your own scripts:

 

Within the flash drive folder config/plugins/user.scripts/scripts create a new folder (each script is going to have its own folder) - The name doesn't matter but it can only contain the following characters: letters ([A-Za-z]), digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), periods ("."), and spaces (" ")

 

Or, you can hit the button that says "Add Script", then give the script a name.  Hovering over the script's name will then give you additional options.  Including online editing...

Create a file called description that contains the description of the script.

Create a file called script this will be the actual script.

 

Few notes:

 

So as to make things easier for people:

  • The script file can be created with any text editor you choose.  DOS line endings will be automatically converted to Linux style endings prior to execution.
  • #!bin/bash is automatically added to every script prior to execution to help out the noobies EDIT: This is only added if no interpreter is specified (ie: #!/bin/bash)  If an interpreter is already specified (ie: #!/usr/bin/php), then line is not added

 

Techie Notes: 

 

The scripts are actually copied and executed from /usr/local/emhttp/plugins/user.scripts/ /tmp/user.scripts/tmpScripts so if there are dependencies (other scripts, etc) stored in the same folder as the script file, you will need to specify the full path to them.

 

 

Interactive (ie: answering yes/no to a question) scripts will not work.

 

  • Like 6
  • Thanks 2
  • Upvote 3
Link to comment

The script file also supports some inline variables which will customize the GUI for the script in question

 

description This is the description of the script - ie: what will show up on the UI for the plugin

foregroundOnly Setting this to be true disallows background running (and scheduling) of the script

backgroundOnly Setting this to be true disallows foreground running of the script

arrayStarted Setting this to be true will only run the script (foreground or background or scheduled) if the array is up and running

name this is the name of the script.  Without this variable, the GUI will display the folder's name

argumentDescription if present this will bring up a pop up asking the user for the argument list for the script.  Note that currently arguments do not accept spaces contained within one argument (ie: quoting and escaping spaces does NOT work)

argumentDefault this is the default arguments for the above

clearLog Set to be true to have the log deleted prior to execution of the script (ie: logs are only for the last execution of the script)

noParity Set to be try if the script is not allowed to run when a parity check / rebuild is in progress

 

 

How to implement these variables:  Immediately after the interpreter line (eg: immediately after the #!/bin/bash line), add these lines if you choose (you do not need to add all of them if you don't require them)

#description=this is the description of the script

#foregroundOnly=true

#backgroundOnly=true

#arrayStarted=true

#name=blah blah blah

#clearLog=true

#argumentDescription=This is the description of the argument(s)

#argumentDefault=defaultArg1 defaultArg2 etc

#noParity=true

 

After the first non comment line within any script, parsing for these variables stops.  (IE: they have to be right at the top of the script file)

 

Note that you do NOT have to have any or all of the lines contained within any particular script.  (Also, if you do have the description file present, then its contents takes precedence over the description variable)

 

*PHP scripters:  You can also place these variable lines immediately after the <? or <?PHP line

Edited by Squid
add in clearLog variable
  • Upvote 2
Link to comment

How about the option to run the script in the background so the webgui does not get tied up with the script.

 

I just created a script to back up my VM and it takes a while.  I'd like to be able to run the script and move on to other things while it runs.  I will add a notification event to the script let me know it is done.

Link to comment

How about the option to run the script in the background so the webgui does not get tied up with the script.

 

I just created a script to back up my VM and it takes a while.  I'd like to be able to run the script and move on to other things while it runs.  I will add a notification event to the script let me know it is done.

This should work as a script then:

echo "Starting the real script"
echo "/path/to/the/actual/script.sh" | at NOW -M > /dev/null 2>&1

Link to comment

How about the option to run the script in the background so the webgui does not get tied up with the script.

 

I just created a script to back up my VM and it takes a while.  I'd like to be able to run the script and move on to other things while it runs.  I will add a notification event to the script let me know it is done.

This should work as a script then:

echo "Starting the real script"
echo "/path/to/the/actual/script.sh" | at NOW -M > /dev/null 2>&1

 

I think this should be included in the plugin as a template.  It's a good point and will definitely increase "usability"

Link to comment

Maybe add a second button to run the script in the background.  That way the user could choose how to run the script without having to make script changes.

let me finish my coffee, and then finish up a CA update so I can give CHBMB a good laugh 

 

EDIT: You guys are killing me...  Anyone know what the odds are of a PID being reused after the script is completed?

Link to comment

echo "Starting the real script"
echo "/path/to/the/actual/script.sh" | at NOW -M > /dev/null 2>&1

 

or

echo "Starting the real script"
at -f/path/to/the/actual/script.sh now 2>&1 /dev/null

Doesn't matter now.  Adding a background button, along with status monitoring of background task, and an abort button
Link to comment

Updated with ability to run the script as a background process, and monitoring of whether its running or not, along with the option to abort the script.

 

BTW, if you want to format the output on any script, you would use standard HTML.

Link to comment

Updated with ability to run the script as a background process, and monitoring of whether its running or not, along with the option to abort the script.

 

BTW, if you want to format the output on any script, you would use standard HTML.

 

Very nice.

Link to comment

Updated with ability to run the script as a background process, and monitoring of whether its running or not, along with the option to abort the script.

 

BTW, if you want to format the output on any script, you would use standard HTML.

 

Very nice.

You want me to redirect the output of the script to a log file with the option to display it?
Link to comment

Updated with ability to run the script as a background process, and monitoring of whether its running or not, along with the option to abort the script.

 

BTW, if you want to format the output on any script, you would use standard HTML.

 

Very nice.

You want me to redirect the output of the script to a log file with the option to display it?

 

Hmm.  Yes, I like that idea.

Link to comment

 

Updated with ability to run the script as a background process, and monitoring of whether its running or not, along with the option to abort the script.

 

BTW, if you want to format the output on any script, you would use standard HTML.

 

Very nice.

You want me to redirect the output of the script to a log file with the option to display it?

 

Lol, squid your so good at this point, you can anticipate user requests before they are even asked.

Link to comment

Updated with ability to run the script as a background process, and monitoring of whether its running or not, along with the option to abort the script.

 

BTW, if you want to format the output on any script, you would use standard HTML.

 

Very nice.

You want me to redirect the output of the script to a log file with the option to display it?

 

Hmm.  Yes, I like that idea.

Couple of days...  GoT night

 

Sent from my LG-D852 using Tapatalk

 

 

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.