Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have written a script using shell and uemcli(Unity/EMC), which executes fine from backend. But, when I execute the same script using php i.e frontend, it fails.
Below is the code:
shell script code-
uemcli -d 11.11.22.33 -u test -p test@123 /env/sp show
uemcli -d 11.11.22.33 -u test -p test@123 /env/disk show
These are the commands that works fine in black screen. But it doesn't execute when called using php. There is no error being shown in apache error logs or in /var/log/messages.
Hi Everyone,
I have written a script using shell and uemcli(Unity/EMC), which executes fine from backend. But, when I execute the same script using php i.e frontend, it fails. Below is the code:
Code:
uemcli -d 11.11.22.33 -u test -p test@123 /env/sp show
uemcli -d 11.11.22.33 -u test -p test@123 /env/disk show
These are the commands that works fine in black screen. But it doesn't execute when called using php. There is no error being shown in apache error logs or in /var/log/messages. Below is the code of php file
Code:
{ shell_exec("/usr/bin/sh /test/test.sh"); }
Please use CODE tags.
Aside from the INCREDIBLY BAD security for such a thing, you should be able to just put "#!/bin/sh" as the first line of your script, as said by Turbocapitalist. However, why /bin/sh, as opposed to the MUCH more common /bin/bash? And you are just putting 'uemcli' in...you probably need to use a fully-qualified path, such as /usr/bin/uemcli (or wherever that program lives; run 'which uemcli' to find out). Is that script executable??? What are the permissions, and who owns it? Since you're running a shell script through PHP, your web server needs permissions to run that file and/or the subsequent commands IN that script. So if you need sudo rights to run uemcli...it'll die right there.
And you won't get PHP errors, since your PHP code is working just fine...it's the shell script that's not. Run it from the command line to see what you get, with something like "php /path/to/file.php".
As per your suggestion, I have added the full path for uemcli i.e. /usr/bin/uemcli (got this o/p by running cmd whereis uemcli). Changed the first line to #!/bin/bash from #!/bin/sh
Permission of apache service is wwwrun, so this ownership is already provided to the php and shell script files. 755 permission is set for shell script.
Still the code doesn't work. No error logs. Shell script runs fine from command line.
FYI, php page has a refresh button. Once that is hit, shell script is been invoked. Here it gets failed.
Hi TB0ne,
As per your suggestion, I have added the full path for uemcli i.e. /usr/bin/uemcli (got this o/p by running cmd whereis uemcli). Changed the first line to #!/bin/bash from #!/bin/sh
Permission of apache service is wwwrun, so this ownership is already provided to the php and shell script files. 755 permission is set for shell script. Still the code doesn't work. No error logs. Shell script runs fine from command line. FYI, php page has a refresh button. Once that is hit, shell script is been invoked. Here it gets failed.
Again, does that command need sudo rights to run from the command line?? And can you run that PHP script (*NOT* the shell script), from the command line by invoking it with "php /some/path/to/script.php"??? There are many guides on how to debug a PHP script: https://www.php.net/manual/en/debugger.php
Without any error messages to go by, there is absolutely nothing we can tell you. And have you verified that the uemcli command syntax is correct? Because it's different in the EMC documentation. And if the ENTIRETY of your PHP 'program' is a one-line call to a shell script...what do you think is going to happen?? It's spawning that system call, and returning. You're not capturing any data/variables, or putting them to the screen. It's doing exactly what you told it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.