application.executeProgram

Questions, tips and tricks and techniques for scripting in Servoy

application.executeProgram

Postby Gordon McLean » Wed Jan 27, 2016 7:40 pm

Hi
I have what I think is a permissions issue, perhaps some of those more experienced with this function may be able to clarify:

I want to run a bash script which interfaces with imagemagick and fonts on the server. The script can be triggered fine manually from the home directory and all works OK

I have created a simple web-client based admin for the client and I want him to be able to trigger the script from a button. As far as I can tell this should be triggered locally and should call the script from the hone directory as per the path shown here. Is this the case or do I need to run this from within the servoy server and if so where should it be located ?

application.executeProgram('fontmanager.sh',['purple', filename, font_name,font_name+'.jpg']);

Many thanks in advance
Gordon
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: application.executeProgram

Postby Gordon McLean » Thu Jan 28, 2016 1:02 pm

Can I bump this request again as I am making no progress

As an example I have used this from a web client button

application.executeProgram("./",["/Applications/Servoy_7_General/application_server/server/webapps/bash.sh"])

I am getting a permission denied which I guess could be the web client element, is there any way to set the permissions in the script above ie sudo or similar

in order to run this in the shell I am typing:

/Applications/Servoy_7_General/application_server/server/webapps/bash.sh

I am guessing this is either a permissions issue where by
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: application.executeProgram

Postby ROCLASI » Thu Jan 28, 2016 1:11 pm

Hi Gordon,

The shell script will be run under the same system user that Servoy server is run under. Does that user have permissions to do what it tries to do?
I.e. when you running it from the command line yourself are you using the same system user?
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: application.executeProgram

Postby Gordon McLean » Thu Jan 28, 2016 1:17 pm

To be fair Patrick suggested that and the short answer is I am not sure. I have been testing this in my developer version so Servoy is installed as developer in the normal way so I am guessing they are the same thing. Is there a way to check what user Servoy is using I am not sure ?

Cheers
Gordon
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: application.executeProgram

Postby Gordon McLean » Thu Jan 28, 2016 1:21 pm

OK I just typed top -o size into terminal and Servoy is running under user gordonmclean so I guess that is not the problem as terminal is using the same user :(
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: application.executeProgram

Postby ROCLASI » Thu Jan 28, 2016 1:54 pm

Hi Gordon,

I use ImageMagic without issues on my server but I call it directly, I don't use a script.
So what does this script do exactly?
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: application.executeProgram

Postby Gordon McLean » Thu Jan 28, 2016 2:06 pm

Really !!!! How do you do that ?

I have a perl script that does a load of ImageMagick processing for a website based on user inputs. The admin for the site is Servoy and the site its self if going to be run via Velocity. The specific problem here is the guy wants to upload fonts to the server periodically and these are displayed as an image of the font name.

I want trying to get the admin to upload the font then run a bash script to install it on the server. IF Servoy could process the ImageMagick stuff that would be perfect I just could not figure out how to make that work

Gordon
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: application.executeProgram

Postby ROCLASI » Thu Jan 28, 2016 3:22 pm

Hi Gordon,

You keep saying there is a specific problem but never specify what it is. Do you get any errors/output? Or does it simply not work?

Edit: reading up I see you are specifying that you get a 'permission denied'. Do you see any other outputs?

This is what I use to convert an image I uploaded to different formats:
Code: Select all
/**
* @param fileName
*/
function convertMedia(fileName) {
   var _sBasePath = plugins.VelocityReport.getReportFolder() + "/www/MySolution/media",
      _aTarget = [{
         path: '/thumbnail/',
         width: 420,
         height: 300,
         quality: 75
      }, {
         path: '/large/',
         width: 1600,
         height: 1067,
         quality: 75
      }],
      _oFile = plugins.file.convertToJSFile(_sBasePath + '/original/' + fileName),
      _oNewFile,
      _oImage;

   if (_oFile && _oFile.exists()) {
      for (var i = 0; i < _aTarget.length; i++) {
         _oImage = plugins.images.getImage(_oFile);
         _oNewFile = plugins.file.convertToJSFile(_sBasePath + _aTarget[i].path + fileName);
         if (_oImage.getWidth() > _aTarget[i].width) {
            // convert using ImageMagick
            application.executeProgram('/opt/local/bin/convert', ["-geometry", _aTarget[i].width + "x" + _aTarget[i].height, "-quality", "" + _aTarget[i].quality, _oFile.getAbsolutePath(), _oNewFile.getAbsolutePath()])
            if (!_oNewFile.exists()) {
               throw new Error("File couldn't be written");
            } else if (_oNewFile.size() > _oFile.size()) {
               // Filesize is bigger than the original. Why bother, copy the original over
               plugins.file.copyFile(_oFile, _oNewFile);
            }
         } else {
            // Original is smaller than our target size, copy it over
            plugins.file.copyFile(_oFile, _oNewFile);
         }
      }
   } else {
      throw new Error("Can't find file '" + _oFile.getAbsolutePath() + "'");
   }
}
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: application.executeProgram

Postby Gordon McLean » Thu Jan 28, 2016 4:03 pm

Hi
The specific problem is the bash.sh script is not run by the function:
application.executeProgram("./",["/Applications/Servoy_7_General/application_server/server/webapps/bash.sh"])

The bash.sh script is enabled and neither works on my desktop or in the Servoy folder. HOWEVER if I run the script in either location from the terminal it works fine.

Your use of ImageMagick is very interesting thank you for sharing. I need the bash script to work simply to enable the font on the server, I may be able to find an alternative approach if I can't get the bash script to trigger from servoy.

Thanks again much appreciated

Gordon
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: application.executeProgram

Postby ROCLASI » Thu Jan 28, 2016 4:42 pm

Hmm... interesting.

Code: Select all
// returns result!
application.output(application.executeProgram('/usr/bin/env'));

// no result, not even writing a file...
application.output(application.executeProgram('/bin/sh', ['/Users/robert/test.sh']));

When I try to run a shell script this indeed doesn't work. So it seems there is something different when you run a shell script vs a program.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: application.executeProgram

Postby Gordon McLean » Thu Jan 28, 2016 4:44 pm

That is a relief to be honest thought I was going mad !!
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: application.executeProgram

Postby Gordon McLean » Fri Jan 29, 2016 11:28 am

Hi Robert ......and the wider Servoy Community

I finally found a solution to this so for those who may also want to trigger a server side bash script this is the solution. The caveat to this is be careful what your doing and aware of the security risks this could present

The mac is protected with a system integrity check this has to be disabled temporarily to make this solution work see the following
http://osxdaily.com/2015/10/05/disable- ... -mac-os-x/

Having disabled the system integrity check you need to make a symlink to your bash script as follows

sudo ln -s /Applications/Servoy_7_General/application_server/server/webapps/bash.sh /usr/sbin/myscriptname

What this does is to effectively make the bash.sh into an application called in this case myscriptname. Hereafter you can simply type myscriptname into the terminal and it will trigger the script. This enabled Servoy to call the script with application.executeProgram("/usr/sbin/myscriptname") - (this is on the Mac)

I intend to use this on a Linux server and it works in much the same way, but for testing purposes the above was required.

To reiterate the caveat, Apple put the system integrity check in place for a good reason and disabling this needs to be done with caution, and remember to re enable it. Be careful exposing bash scripts in this way generally, and make sure they do exactly what you want before you attempt adding them to Servoy. Finally there may have been very good reasons why Servoy restricted this feature that I am unaware of and taking their advice may be prudent.

Best
Gordon
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: application.executeProgram

Postby swingman » Mon Feb 01, 2016 1:57 pm

Hi Gordon,

I still do not understand why you had to disable SIP. Could you not link that script into /usr/local which is not protected by SIP?
That's where homebrew puts its CELLAR folder for kegs ;-)
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1479
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: application.executeProgram

Postby Gordon McLean » Mon Feb 01, 2016 2:04 pm

No the finder refused to allow me to add a script into this folder and make it executable. However with the SIP removed temporarily it had no problem, I believe this was instigated with Mavericks. Not sure how home-brew do as you say many other installers seem to get around this. I did try with sudo so it should have had root privileges. None the less having got it working it does open up a whole new range of potential server side functions you can do from within Servoy which great for your own local admin if nothing else.
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: application.executeProgram

Postby swingman » Tue Feb 02, 2016 5:59 pm

Hi Gordon,

I'm on El Capitan, I can

Code: Select all
cd /usr/local
touch test.sh
vi test.sh


press I to enter insert mode
Code: Select all
#!/bin/sh
echo "HELLO!"


press esc to exit insert mode
type :wq
to save

then try

Code: Select all
chmod +x test.sh
/usr/local/test.sh


shows HELLO!

I wonder if you have some permissions issue on your Mac.
What does Disk Utility show?
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1479
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Next

Return to Methods

Who is online

Users browsing this forum: No registered users and 5 guests

cron