How to invoke modules of marklogic(xqy files) from shell script? - shell

I want to write a shell script in which I can call a .xqy file and import some namespace also in that shell script.

You can use the REST API and some HTTP aware command line client like curl or wget.
There are many examples in the REST API's about how to do this, although it is fairly tedious to call .xqy code, pass it input , arguments and get output - possible.
You can use a program designed to do this such as xmlsh and the marklogic extension
http://www.xmlsh.org
Or you can write a 'simple' generic wrapper function in any of the languages which ML has a supported SDK, and then call that from the shell script.
You can make a 'custom' REST or HTTP endpoint which invokes the xqy and returns the results in the form you want.

Related

How is it possible to have an user action in the "view" directory that trigger an ubus method?

I am trying to implement some code for a GUI using openwrt and luci.
I would like to know how to implement a button or a formulary that trigger a lua command when the user submit it.
I make a lua script using ubus to control gpios and relays and now I am trying to make a GUI in which users will be allowed to control each GPIO and relays through ubus commands.
I know the commands to call ubus methods through the GUI.
I did a new page with several graphic items. Is it possible to implement a button/formulary which changes a variable and this variable will be used by a lua script?
Thank you.
Yes, there's two simple methods that can achieve this:
POST/GET request to controller.
Using Lua functions in the HTM.
The first one should not be hard to understand conceptually and you can read about POST/GET requests in JavaScript (AJAX) here: https://www.w3schools.com/jquery/jquery_ajax_get_post.asp
The second option is fine for something incredibly simple (or for testing purposes), but I would advise against using it over the first one just because there is less to type. All you need to do is simply surround your Lua code with <% (code goes here) %>.
However, there is another way which does not rely on Lua/JavaScript at all. You can make a config file (as it does seem you are saving something to it) and make an init script launch the service/change some parameters after any change to the configuration file using procd. Here's an example of how to do that: https://openwrt.org/docs/guide-developer/procd-init-scripts
Use curl commands, you can trigger a curl command when button is pressed and there by you can achieve your functionality

How do I check that a Rest call is successful in unix shell script?

I would like to invoke a rest Url from Unix shell and verify that call is successful based on return code.
If the call fails, I would like the details to be stored in a variable.
I have tried various options in cURL.

Is there an option to wget to force it to write the response even when it's erroneous?

I have written a Bash SOAP library that uses wget as the interface to HTTP servers. It's intentional to avoid curl, since that is not available or not installed by default on systems where this library is used.
The basis of the library is the query the WSDL, determine the parameters and allow functions / methods to be invoked from the command line, through a simple wrapper to setup the SOAP urls:
$ ./mysoap.sh MyMethod sKey=1234 bAnotherParameter=False sAnotherParam="Hello"
However, when wget receives a 500 response, it doesn't write the response body to the output document defined by -O. The response contains the SOAP errors that the server generated, which is useful to the client. Is there a way to force wget to write the response to the output document, regardless of the state? The documentation seems to be unclear about the function of -O in the event of an error, so to me, it's not working as intended.
This is the option:
Parameter: --content-on-error, available from wget 1.14:
https://superuser.com/a/648466

Validate Boo script syntactically without running it

I have use BOO as an embedded script language in my own program. And I want to check the syntax errors of a script which a user writes. So I don't need to run the script by something like interpreter.Eval method and I need just running the first steps of compiler in order to discover the syntax error in user's script. Is there any way I can do that?
Thanks
http://boo.codehaus.org/How+To+Compile:
There are basically three ways to compile your boo code:
through the booc utility;
through the booc task (one of the nant tasks);
through the Boo.Lang.Compiler API;

Can this be done? Bash script in a web application

I have a bash script (supports linux/unix), that installs an application.
Instead of executing the script in the terminal, I want to deploy it as a web application.
I want to make a web graphical interface for this script, so that the user can give the necessary inputs in the web forms and when ready,then pass these variables into the bash script to be executed.
This script obvious needs root privileges.
I plan to make it with with tomcat 7 / servlet / jsp. I want to deploy it as .war file.
First, can this be done? Is it possible?
Second, is there any example? I didn't find anything.
Third, any alternative method/better idea?
I'd try tomcat's own CGI support.
http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html
Well, it's possible, but keep in mind that sanitizing user input is hard.
What you want to do is use a scripting language or framework (I recommend sinatra), and use a html form to pass arguments to the backend. In the backend, you call your script by passing whatever arguments you want.
Example with sinatra:
post '/whatever' do
# This is dangerous!
`myscript #{params[...]}`
end
Err, but you want this to run on the client side, right?
So you don't really run it as bash on your system, you just template it within your web framework.
If the browser can then display this, it won't just d/l as a file, so you will need to set up a Content-Disposition: attachment header in the response to force a d/l.
You will naturally need the user's cooperation to run this as root on his or her system...

Resources