How to run bash script with curl from php
I can not start a bash script from PHP using CURL
Currently I use shell_exec like this:
script.sh:
#!/bin/sh
echo -e "This is my script"
sudo apt-get update -y
test.php:
<?php
...
$my_script = shell_exec ("curl -s http://domain/script.sh | bash -s var1". $var2);
echo $run_script;
..
?>
From the terminal I call "curl -s http://domain/test.php", the output is "This is my script", the command "apt-get update" is not executed
If from a terminal I call the script directly this way: "curl -s http://domain/script.sh | bash -s", the command is correctly executed.
I tried to use "curl_init" but I do not know how to run a bash script:
<?php
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, "http://domain/script.sh | bash -s var1");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
if (curl_errno ($ch)) {
echo 'Error:'. curl_error ($ch);
}
curl_close ($ch);
?>
"| bash -s" is not supported within the call.
If it can be useful, use nginx on ubuntu and i have ssh access if is needed
An solution could be exec("ssh username @ server command -arg1 -arg2 ..."); which requires the removal of the password. I can not remove my password for security reasons.
I do not want to run a script on server B by launching the command from server A.I want to run a script on server A using a script on server B
Before considering it a duplicate, or to say that in another post there is already the solution, try to understand what I'm asking.
Thank you
php bash nginx curl
add a comment |
I can not start a bash script from PHP using CURL
Currently I use shell_exec like this:
script.sh:
#!/bin/sh
echo -e "This is my script"
sudo apt-get update -y
test.php:
<?php
...
$my_script = shell_exec ("curl -s http://domain/script.sh | bash -s var1". $var2);
echo $run_script;
..
?>
From the terminal I call "curl -s http://domain/test.php", the output is "This is my script", the command "apt-get update" is not executed
If from a terminal I call the script directly this way: "curl -s http://domain/script.sh | bash -s", the command is correctly executed.
I tried to use "curl_init" but I do not know how to run a bash script:
<?php
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, "http://domain/script.sh | bash -s var1");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
if (curl_errno ($ch)) {
echo 'Error:'. curl_error ($ch);
}
curl_close ($ch);
?>
"| bash -s" is not supported within the call.
If it can be useful, use nginx on ubuntu and i have ssh access if is needed
An solution could be exec("ssh username @ server command -arg1 -arg2 ..."); which requires the removal of the password. I can not remove my password for security reasons.
I do not want to run a script on server B by launching the command from server A.I want to run a script on server A using a script on server B
Before considering it a duplicate, or to say that in another post there is already the solution, try to understand what I'm asking.
Thank you
php bash nginx curl
To make that work need to add the user that executes the web server to/etc/sudoers
file, what is a very bad idea
– isalgueiro
Nov 15 '18 at 18:53
1
Every part of this is an awful, inadvisable idea. What are you trying to do and why?
– Sammitch
Nov 15 '18 at 19:00
It already works if I call the sh file directly from the terminal, if I call the php file it does not work, maybe because "curl_setopt" does not support "| bash -s".
– giacomosilli
Nov 15 '18 at 22:29
@Sammitch Why is it terrible? I need to be able to start a script on another server, without having to download it. I call the script on server B and the commands are executed on server A. It works with shell_exec, but not with php-curl. Which is the best solution to reach my goal?
– giacomosilli
Nov 16 '18 at 14:39
add a comment |
I can not start a bash script from PHP using CURL
Currently I use shell_exec like this:
script.sh:
#!/bin/sh
echo -e "This is my script"
sudo apt-get update -y
test.php:
<?php
...
$my_script = shell_exec ("curl -s http://domain/script.sh | bash -s var1". $var2);
echo $run_script;
..
?>
From the terminal I call "curl -s http://domain/test.php", the output is "This is my script", the command "apt-get update" is not executed
If from a terminal I call the script directly this way: "curl -s http://domain/script.sh | bash -s", the command is correctly executed.
I tried to use "curl_init" but I do not know how to run a bash script:
<?php
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, "http://domain/script.sh | bash -s var1");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
if (curl_errno ($ch)) {
echo 'Error:'. curl_error ($ch);
}
curl_close ($ch);
?>
"| bash -s" is not supported within the call.
If it can be useful, use nginx on ubuntu and i have ssh access if is needed
An solution could be exec("ssh username @ server command -arg1 -arg2 ..."); which requires the removal of the password. I can not remove my password for security reasons.
I do not want to run a script on server B by launching the command from server A.I want to run a script on server A using a script on server B
Before considering it a duplicate, or to say that in another post there is already the solution, try to understand what I'm asking.
Thank you
php bash nginx curl
I can not start a bash script from PHP using CURL
Currently I use shell_exec like this:
script.sh:
#!/bin/sh
echo -e "This is my script"
sudo apt-get update -y
test.php:
<?php
...
$my_script = shell_exec ("curl -s http://domain/script.sh | bash -s var1". $var2);
echo $run_script;
..
?>
From the terminal I call "curl -s http://domain/test.php", the output is "This is my script", the command "apt-get update" is not executed
If from a terminal I call the script directly this way: "curl -s http://domain/script.sh | bash -s", the command is correctly executed.
I tried to use "curl_init" but I do not know how to run a bash script:
<?php
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, "http://domain/script.sh | bash -s var1");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
if (curl_errno ($ch)) {
echo 'Error:'. curl_error ($ch);
}
curl_close ($ch);
?>
"| bash -s" is not supported within the call.
If it can be useful, use nginx on ubuntu and i have ssh access if is needed
An solution could be exec("ssh username @ server command -arg1 -arg2 ..."); which requires the removal of the password. I can not remove my password for security reasons.
I do not want to run a script on server B by launching the command from server A.I want to run a script on server A using a script on server B
Before considering it a duplicate, or to say that in another post there is already the solution, try to understand what I'm asking.
Thank you
php bash nginx curl
php bash nginx curl
asked Nov 15 '18 at 18:42
giacomosilligiacomosilli
626
626
To make that work need to add the user that executes the web server to/etc/sudoers
file, what is a very bad idea
– isalgueiro
Nov 15 '18 at 18:53
1
Every part of this is an awful, inadvisable idea. What are you trying to do and why?
– Sammitch
Nov 15 '18 at 19:00
It already works if I call the sh file directly from the terminal, if I call the php file it does not work, maybe because "curl_setopt" does not support "| bash -s".
– giacomosilli
Nov 15 '18 at 22:29
@Sammitch Why is it terrible? I need to be able to start a script on another server, without having to download it. I call the script on server B and the commands are executed on server A. It works with shell_exec, but not with php-curl. Which is the best solution to reach my goal?
– giacomosilli
Nov 16 '18 at 14:39
add a comment |
To make that work need to add the user that executes the web server to/etc/sudoers
file, what is a very bad idea
– isalgueiro
Nov 15 '18 at 18:53
1
Every part of this is an awful, inadvisable idea. What are you trying to do and why?
– Sammitch
Nov 15 '18 at 19:00
It already works if I call the sh file directly from the terminal, if I call the php file it does not work, maybe because "curl_setopt" does not support "| bash -s".
– giacomosilli
Nov 15 '18 at 22:29
@Sammitch Why is it terrible? I need to be able to start a script on another server, without having to download it. I call the script on server B and the commands are executed on server A. It works with shell_exec, but not with php-curl. Which is the best solution to reach my goal?
– giacomosilli
Nov 16 '18 at 14:39
To make that work need to add the user that executes the web server to
/etc/sudoers
file, what is a very bad idea– isalgueiro
Nov 15 '18 at 18:53
To make that work need to add the user that executes the web server to
/etc/sudoers
file, what is a very bad idea– isalgueiro
Nov 15 '18 at 18:53
1
1
Every part of this is an awful, inadvisable idea. What are you trying to do and why?
– Sammitch
Nov 15 '18 at 19:00
Every part of this is an awful, inadvisable idea. What are you trying to do and why?
– Sammitch
Nov 15 '18 at 19:00
It already works if I call the sh file directly from the terminal, if I call the php file it does not work, maybe because "curl_setopt" does not support "| bash -s".
– giacomosilli
Nov 15 '18 at 22:29
It already works if I call the sh file directly from the terminal, if I call the php file it does not work, maybe because "curl_setopt" does not support "| bash -s".
– giacomosilli
Nov 15 '18 at 22:29
@Sammitch Why is it terrible? I need to be able to start a script on another server, without having to download it. I call the script on server B and the commands are executed on server A. It works with shell_exec, but not with php-curl. Which is the best solution to reach my goal?
– giacomosilli
Nov 16 '18 at 14:39
@Sammitch Why is it terrible? I need to be able to start a script on another server, without having to download it. I call the script on server B and the commands are executed on server A. It works with shell_exec, but not with php-curl. Which is the best solution to reach my goal?
– giacomosilli
Nov 16 '18 at 14:39
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326006%2fhow-to-run-bash-script-with-curl-from-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326006%2fhow-to-run-bash-script-with-curl-from-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
To make that work need to add the user that executes the web server to
/etc/sudoers
file, what is a very bad idea– isalgueiro
Nov 15 '18 at 18:53
1
Every part of this is an awful, inadvisable idea. What are you trying to do and why?
– Sammitch
Nov 15 '18 at 19:00
It already works if I call the sh file directly from the terminal, if I call the php file it does not work, maybe because "curl_setopt" does not support "| bash -s".
– giacomosilli
Nov 15 '18 at 22:29
@Sammitch Why is it terrible? I need to be able to start a script on another server, without having to download it. I call the script on server B and the commands are executed on server A. It works with shell_exec, but not with php-curl. Which is the best solution to reach my goal?
– giacomosilli
Nov 16 '18 at 14:39