Jump to content
Squid

[Plugin] CA User Scripts

604 posts in this topic Last Reply

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: http://lime-technology.com/forum/index.php?topic=50416.0

 

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

 

Various aspects of the scripts are controlled through variables contained within the scripts themselves.  This includes the description, if they can run in the background, etc.  See this post: http://lime-technology.com/forum/index.php?topic=49992.msg516885#msg516885 for more details

 

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.

 

Edited by Squid
  • Like 2
  • Upvote 3

Share this post


Link to post

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

Share this post


Link to post

Nice.... I'll be using this one.

 

Share this post


Link to post

thanks squid, handy addition!

 

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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"

Share this post


Link to post

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.

Share this post


Link to post

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?

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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?

Share this post


Link to post

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.

Share this post


Link to post

 

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.

Share this post


Link to post

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

 

 

Share this post


Link to post

The more I've been thinking about this plugin the more I like it. 

 

Such a simple idea can't believe it hasn't been thought of before.

 

Squid, what took you so long?!

Share this post


Link to post

I saw a post the other day about unmenu and it popped back into my head about what it did (although iirc this is easier to add your own)

 

Sent from my LG-D852 using Tapatalk

 

 

Share this post


Link to post

I don't remember using it on unmemu, although I remember the button that was basically echo hello world I think.  But I was new to Linux then.....

Share this post


Link to post

I don't remember using it on unmemu, although I remember the button that was basically echo hello world I think.  But I was new to Linux then.....

As was I. 

 

Sent from my LG-D852 using Tapatalk

 

 

Share this post


Link to post

Really?!  Damn I got some catching up to do....

Share this post


Link to post

i hope you enjoyed GoT. It's a great episode. If it were GRR Martin books it would span 3 books and take 16 years to release.

Share this post


Link to post

Pretty much.  Now I have no idea what to do on Sunday for the next 10 months

 

Sent from my LG-D852 using Tapatalk

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now