websoftexpert Posted October 4, 2010 Share Posted October 4, 2010 Hi I have shell script (.sh). I have execute it via php file. How to do this? And how to pass variable in shell script. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/215108-how-to-execute-shell-script-vai-php/ Share on other sites More sharing options...
trq Posted October 4, 2010 Share Posted October 4, 2010 Take a look at shell_exec. Quote Link to comment https://forums.phpfreaks.com/topic/215108-how-to-execute-shell-script-vai-php/#findComment-1118818 Share on other sites More sharing options...
websoftexpert Posted October 4, 2010 Author Share Posted October 4, 2010 Hi Do you have any example? Please see below. <?php system("your.sh"); ?> Am I right? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/215108-how-to-execute-shell-script-vai-php/#findComment-1118819 Share on other sites More sharing options...
trq Posted October 4, 2010 Share Posted October 4, 2010 Do I have an example? The link I gave you has plenty of examples, and explains what arguments the function accepts as well as what it returns. Your post above uses the system function, which can also execute external programs. Read the manual, it is the definitive guide. Quote Link to comment https://forums.phpfreaks.com/topic/215108-how-to-execute-shell-script-vai-php/#findComment-1118828 Share on other sites More sharing options...
The Letter E Posted December 5, 2010 Share Posted December 5, 2010 Hi Do you have any example? Please see below. <?php system("your.sh"); ?> Am I right? Thanks Here's a basic example, using the shell_exec() function mentioned. For the purpose of keeping it simple I've used a basic command to check the version of rails installed on a server. <?php $shell = "rails -v"; $cmd = shell_exec($shell); echo $shell.' <br>'.$cmd; ?> This will output: rails -v Rails 3.2.1 (whatever version you have...) I'm not sure what the restrictions are to running shells on this function, if any. Refer to the php.net example as mentioned by thorpe. I have successfully created a shell interface that acts similar to your basic shell client. I can create files and edit files...(no pico/gedit capabilities yet) I can run dir, cat, and most other basic linux commands, haven't run into any commands that I cannot use yet. This is a very basic example. php.net is the place to go for more detail. http://php.net/shell_exec Quote Link to comment https://forums.phpfreaks.com/topic/215108-how-to-execute-shell-script-vai-php/#findComment-1143124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.