LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Give users access to run a script saved on server (http://www.linuxquestions.org/questions/programming-9/give-users-access-to-run-a-script-saved-on-server-4175490570/)

rjo98 01-08-2014 11:13 AM

Give users access to run a script saved on server
 
right now i have a cron'd shell script which does some things and also calls a perl script. Every once in a while we need to run it manually, but right now only IT folks who can log into the server can run it.

Can anyone think of a creative way that would let regular users from their PCs be able to run the shell script, without giving them a logon to the server itself or any permissions (so no webmin access to go to scheduled jobs).

TB0ne 01-08-2014 11:39 AM

Quote:

Originally Posted by rjo98 (Post 5094334)
right now i have a cron'd shell script which does some things and also calls a perl script. Every once in a while we need to run it manually, but right now only IT folks who can log into the server can run it.

Can anyone think of a creative way that would let regular users from their PCs be able to run the shell script, without giving them a logon to the server itself or any permissions (so no webmin access to go to scheduled jobs).

Well, a simple PHP web page with one button on it would do the trick. Running an external script is fairly trivial for PHP, and you could put a simple user ID/password on it with just a .htaccess to keep it simple, if you wanted to 'secure' it a bit. Heck, since it's a perl script, you could just link it to your cgi-bin directory, and run it as-is (possibly).

rjo98 01-08-2014 12:47 PM

OK. I'll have to see if I can find a sample online of a php webpage that would do that, I don't know php myself. glad it's something fairly simple though like that. I think there is an instance of lampp running on the server that contains the scripts, so I guess that could host the page too, assuming I can figure it out haha.

Habitual 01-08-2014 12:55 PM

PHP Code:

<?php
$output 
shell_exec(/path/to/perl /path/to/script.pl);
echo 
"$output" ;
?>

Save as userscript.php and run with http://server.com/userscript.php
Give it the correct owner:perms as with any php file in DocumentRoot...

Should work.

Enjoy.

rjo98 01-08-2014 12:58 PM

wow, thanks! Now it's actually a .sh that as part of it calls a .pl, if that makes a difference?

Habitual 01-08-2014 01:05 PM

You're very welcome.
unless the enviroment "needs" some variables, I'd use just the perl part of it at first.
This suggests you can run a shell script in php.

Good Luck!

Edit:
Can you show us the shell script? (sanitize if necessary)

rjo98 01-08-2014 01:14 PM

OK, I will give it a shot and just put my .sh file name in where you had the .pl in your example

Here's the sanitized .sh file:

Code:

#!/bin/bash
/usr/bin/wget --user=username --password=password 'http://page.com' -O /dir/ect/ory/file.htm
/usr/bin/perl /dir/ect/ory/my_ftp_script.pl

echo done.

then the pl file just connects to the ftp site and does a put of file.htm

Habitual 01-08-2014 01:19 PM

Quote:

Originally Posted by rjo98 (Post 5094400)
then the pl file just connects to the ftp site and does a put of file.htm

a put or a pull?

Unless /usr/bin/perl /dir/ect/ory/my_ftp_script.pl
does some processing based on the file.htm, then it may not be necessary to include it.

Keep us updated on your progress!

rjo98 01-08-2014 01:24 PM

my .sh file grabs a webpage we create then creates this file.htm file I need to send somewhere else, then the .pl does the actual 'put' onto the ftp server where file.htm needs to go.

Habitual 01-08-2014 01:42 PM

Well, I'd try the entire .sh script.
What's the worse that can happen?

Errr, make that "couldn't hurt" ;)


All times are GMT -5. The time now is 11:39 AM.