ssh remote file execution is not workingApplication deployment over sshExport mysql to remote server using...
Crime rates in a post-scarcity economy
Is it a good idea to copy a trader when investing?
My parents are Afghan
Why doesn't increasing the temperature of something like wood or paper set them on fire?
Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?
Light Switch Neutrals: Bundle all together?
Is it safe to keep the GPU on 100% utilization for a very long time?
Are there vaccine ingredients which may not be disclosed ("hidden", "trade secret", or similar)?
Gift for mentor after his thesis defense?
How is it believable that Euron could so easily pull off this ambush?
Why did Yoast put a no-index tag in my XML sitemap?
What happens when the drag force exceeds the weight of an object falling into earth?
Mindfulness of Watching Youtube
99 coins into the sacks
Employee is self-centered and affects the team negatively
Is it possible to do moon sighting in advance for 5 years with 100% accuracy?
What's the difference between "ricochet" and "bounce"?
Visualize multiple string segments
Why are thrust reversers not used down to taxi speeds?
Creating Stored Procedure in local db that references tables in linked server
Is this strange Morse signal type common?
Illegal assignment from Id to List
Is there an application which does HTTP PUT?
Can I bring back Planetary Romance as a genre?
ssh remote file execution is not working
Application deployment over sshExport mysql to remote server using one SSH sessionSSH Remote Execution - checking server can do it?Issue with resize and stty on remote ssh script?Sudo with password and append to file via SSHpassphraseless access to rsync with ssh through cron failsssh as proxy server does not workHow to ssh to a remote host using from within a bash script function?Color codes for echo don't work when running a script over sshHow to safely pass password to a remote server to execute sudo commands
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a bash script test.sh that contains the following commands
#!/bin/bash
PASSWORD=""
USERNAME=""
REM_HOSTNAME='localhost'
FILES_TO_COPY="remote_exec.sh"
function scptmp {
exec sshpass -p $PASSWORD scp -o "ConnectTimeout 3"
-o "StrictHostKeyChecking no"
-o "UserKnownHostsFile /dev/null"
"$@"
}
echo -e "tCopying files to remote host..."
scptmp -r -q $FILES_TO_COPY $USERNAME@$REM_HOSTNAME:/tmp
echo -e "tSet execution privs on remote file..."
sshpass -p "$PASSWORD" ssh -t -oStrictHostKeyChecking=no $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S chmod +x /tmp/$FILES_TO_COPY"
echo -e "Execute..."
sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -t $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S bash /tmp/$FILES_TO_COPY"
And the remote_exec.sh with the following content:
#!/bin/bash
hostname=`hostname`
mkdir $hostname
When I execute the script with
bash test.sh
I don't receive any error, but the remote_exec.sh doesn't seem to be executed on the host since no directory is created.
Does anyone have an idea what the problem might be?
ssh sshpass
bumped to the homepage by Community♦ 3 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
|
show 2 more comments
I have a bash script test.sh that contains the following commands
#!/bin/bash
PASSWORD=""
USERNAME=""
REM_HOSTNAME='localhost'
FILES_TO_COPY="remote_exec.sh"
function scptmp {
exec sshpass -p $PASSWORD scp -o "ConnectTimeout 3"
-o "StrictHostKeyChecking no"
-o "UserKnownHostsFile /dev/null"
"$@"
}
echo -e "tCopying files to remote host..."
scptmp -r -q $FILES_TO_COPY $USERNAME@$REM_HOSTNAME:/tmp
echo -e "tSet execution privs on remote file..."
sshpass -p "$PASSWORD" ssh -t -oStrictHostKeyChecking=no $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S chmod +x /tmp/$FILES_TO_COPY"
echo -e "Execute..."
sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -t $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S bash /tmp/$FILES_TO_COPY"
And the remote_exec.sh with the following content:
#!/bin/bash
hostname=`hostname`
mkdir $hostname
When I execute the script with
bash test.sh
I don't receive any error, but the remote_exec.sh doesn't seem to be executed on the host since no directory is created.
Does anyone have an idea what the problem might be?
ssh sshpass
bumped to the homepage by Community♦ 3 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
What you get if you runset -xbefore running the script? Do you have the shebang on the first line of your script?
– Jakuje
May 23 '17 at 12:57
Before running which script? Thetest.sh?
– wasp256
May 23 '17 at 13:01
I run theset -xnow in the terminal before executingbash test.shbut it just returns+ bash linux_pentest.sh
– wasp256
May 23 '17 at 13:04
Try to put it into the script on the line before thesshpass.
– Jakuje
May 23 '17 at 13:05
I did but no difference!?
– wasp256
May 23 '17 at 13:18
|
show 2 more comments
I have a bash script test.sh that contains the following commands
#!/bin/bash
PASSWORD=""
USERNAME=""
REM_HOSTNAME='localhost'
FILES_TO_COPY="remote_exec.sh"
function scptmp {
exec sshpass -p $PASSWORD scp -o "ConnectTimeout 3"
-o "StrictHostKeyChecking no"
-o "UserKnownHostsFile /dev/null"
"$@"
}
echo -e "tCopying files to remote host..."
scptmp -r -q $FILES_TO_COPY $USERNAME@$REM_HOSTNAME:/tmp
echo -e "tSet execution privs on remote file..."
sshpass -p "$PASSWORD" ssh -t -oStrictHostKeyChecking=no $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S chmod +x /tmp/$FILES_TO_COPY"
echo -e "Execute..."
sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -t $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S bash /tmp/$FILES_TO_COPY"
And the remote_exec.sh with the following content:
#!/bin/bash
hostname=`hostname`
mkdir $hostname
When I execute the script with
bash test.sh
I don't receive any error, but the remote_exec.sh doesn't seem to be executed on the host since no directory is created.
Does anyone have an idea what the problem might be?
ssh sshpass
I have a bash script test.sh that contains the following commands
#!/bin/bash
PASSWORD=""
USERNAME=""
REM_HOSTNAME='localhost'
FILES_TO_COPY="remote_exec.sh"
function scptmp {
exec sshpass -p $PASSWORD scp -o "ConnectTimeout 3"
-o "StrictHostKeyChecking no"
-o "UserKnownHostsFile /dev/null"
"$@"
}
echo -e "tCopying files to remote host..."
scptmp -r -q $FILES_TO_COPY $USERNAME@$REM_HOSTNAME:/tmp
echo -e "tSet execution privs on remote file..."
sshpass -p "$PASSWORD" ssh -t -oStrictHostKeyChecking=no $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S chmod +x /tmp/$FILES_TO_COPY"
echo -e "Execute..."
sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -t $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S bash /tmp/$FILES_TO_COPY"
And the remote_exec.sh with the following content:
#!/bin/bash
hostname=`hostname`
mkdir $hostname
When I execute the script with
bash test.sh
I don't receive any error, but the remote_exec.sh doesn't seem to be executed on the host since no directory is created.
Does anyone have an idea what the problem might be?
ssh sshpass
ssh sshpass
edited May 25 '17 at 10:46
wasp256
asked May 23 '17 at 12:50
wasp256wasp256
175211
175211
bumped to the homepage by Community♦ 3 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 3 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
What you get if you runset -xbefore running the script? Do you have the shebang on the first line of your script?
– Jakuje
May 23 '17 at 12:57
Before running which script? Thetest.sh?
– wasp256
May 23 '17 at 13:01
I run theset -xnow in the terminal before executingbash test.shbut it just returns+ bash linux_pentest.sh
– wasp256
May 23 '17 at 13:04
Try to put it into the script on the line before thesshpass.
– Jakuje
May 23 '17 at 13:05
I did but no difference!?
– wasp256
May 23 '17 at 13:18
|
show 2 more comments
What you get if you runset -xbefore running the script? Do you have the shebang on the first line of your script?
– Jakuje
May 23 '17 at 12:57
Before running which script? Thetest.sh?
– wasp256
May 23 '17 at 13:01
I run theset -xnow in the terminal before executingbash test.shbut it just returns+ bash linux_pentest.sh
– wasp256
May 23 '17 at 13:04
Try to put it into the script on the line before thesshpass.
– Jakuje
May 23 '17 at 13:05
I did but no difference!?
– wasp256
May 23 '17 at 13:18
What you get if you run
set -x before running the script? Do you have the shebang on the first line of your script?– Jakuje
May 23 '17 at 12:57
What you get if you run
set -x before running the script? Do you have the shebang on the first line of your script?– Jakuje
May 23 '17 at 12:57
Before running which script? The
test.sh?– wasp256
May 23 '17 at 13:01
Before running which script? The
test.sh?– wasp256
May 23 '17 at 13:01
I run the
set -x now in the terminal before executing bash test.sh but it just returns + bash linux_pentest.sh– wasp256
May 23 '17 at 13:04
I run the
set -x now in the terminal before executing bash test.sh but it just returns + bash linux_pentest.sh– wasp256
May 23 '17 at 13:04
Try to put it into the script on the line before the
sshpass.– Jakuje
May 23 '17 at 13:05
Try to put it into the script on the line before the
sshpass.– Jakuje
May 23 '17 at 13:05
I did but no difference!?
– wasp256
May 23 '17 at 13:18
I did but no difference!?
– wasp256
May 23 '17 at 13:18
|
show 2 more comments
2 Answers
2
active
oldest
votes
Single quotes inhibit evaluation of variables inside them. Try double quotes:
sshpass -p $PASSWORD ssh -t user@host "echo $PASSWORD | sudo -S bash /tmp/remote_exec.sh"
I changed it to double quotes but it still doesn't work...
– wasp256
May 24 '17 at 7:44
Does it work if you just type the above command line in, replacing both instances of $PASSWORD by the actual password (as well as the user and host placeholders)? If not, then something else is wrong. If yes, I'm not sure why the above would not work.
– NickD
May 24 '17 at 12:04
Yes it works when I execute it in a terminal! I have now double checked everything and found a possible problem (Updated the initial post)
– wasp256
May 24 '17 at 12:09
add a comment |
Try the following:
sshpass -p $PASSWORD ssh -t user@host<<EOF
echo uname -a
cd /tmp/ || exit 1
echo $PASSWORD | sudo -S bash ./remote_exec.sh
exit $?
EOF
I have tried the above code but I receive the following errortest.sh: line 47: warning: here-document at line 34 delimited by end-of-file (wantedEOF') test.sh: line 48: syntax error: unexpected end of file
– wasp256
May 24 '17 at 7:44
removed the space before the <<EOF but should be working just tested with passwordless connectivity
– GiannakopoulosJ
May 24 '17 at 12:11
Yeah I fixed then already when I tried it, but nevertheless didn't work
– wasp256
May 24 '17 at 12:14
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f366769%2fssh-remote-file-execution-is-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Single quotes inhibit evaluation of variables inside them. Try double quotes:
sshpass -p $PASSWORD ssh -t user@host "echo $PASSWORD | sudo -S bash /tmp/remote_exec.sh"
I changed it to double quotes but it still doesn't work...
– wasp256
May 24 '17 at 7:44
Does it work if you just type the above command line in, replacing both instances of $PASSWORD by the actual password (as well as the user and host placeholders)? If not, then something else is wrong. If yes, I'm not sure why the above would not work.
– NickD
May 24 '17 at 12:04
Yes it works when I execute it in a terminal! I have now double checked everything and found a possible problem (Updated the initial post)
– wasp256
May 24 '17 at 12:09
add a comment |
Single quotes inhibit evaluation of variables inside them. Try double quotes:
sshpass -p $PASSWORD ssh -t user@host "echo $PASSWORD | sudo -S bash /tmp/remote_exec.sh"
I changed it to double quotes but it still doesn't work...
– wasp256
May 24 '17 at 7:44
Does it work if you just type the above command line in, replacing both instances of $PASSWORD by the actual password (as well as the user and host placeholders)? If not, then something else is wrong. If yes, I'm not sure why the above would not work.
– NickD
May 24 '17 at 12:04
Yes it works when I execute it in a terminal! I have now double checked everything and found a possible problem (Updated the initial post)
– wasp256
May 24 '17 at 12:09
add a comment |
Single quotes inhibit evaluation of variables inside them. Try double quotes:
sshpass -p $PASSWORD ssh -t user@host "echo $PASSWORD | sudo -S bash /tmp/remote_exec.sh"
Single quotes inhibit evaluation of variables inside them. Try double quotes:
sshpass -p $PASSWORD ssh -t user@host "echo $PASSWORD | sudo -S bash /tmp/remote_exec.sh"
answered May 23 '17 at 14:49
NickDNickD
1,7481414
1,7481414
I changed it to double quotes but it still doesn't work...
– wasp256
May 24 '17 at 7:44
Does it work if you just type the above command line in, replacing both instances of $PASSWORD by the actual password (as well as the user and host placeholders)? If not, then something else is wrong. If yes, I'm not sure why the above would not work.
– NickD
May 24 '17 at 12:04
Yes it works when I execute it in a terminal! I have now double checked everything and found a possible problem (Updated the initial post)
– wasp256
May 24 '17 at 12:09
add a comment |
I changed it to double quotes but it still doesn't work...
– wasp256
May 24 '17 at 7:44
Does it work if you just type the above command line in, replacing both instances of $PASSWORD by the actual password (as well as the user and host placeholders)? If not, then something else is wrong. If yes, I'm not sure why the above would not work.
– NickD
May 24 '17 at 12:04
Yes it works when I execute it in a terminal! I have now double checked everything and found a possible problem (Updated the initial post)
– wasp256
May 24 '17 at 12:09
I changed it to double quotes but it still doesn't work...
– wasp256
May 24 '17 at 7:44
I changed it to double quotes but it still doesn't work...
– wasp256
May 24 '17 at 7:44
Does it work if you just type the above command line in, replacing both instances of $PASSWORD by the actual password (as well as the user and host placeholders)? If not, then something else is wrong. If yes, I'm not sure why the above would not work.
– NickD
May 24 '17 at 12:04
Does it work if you just type the above command line in, replacing both instances of $PASSWORD by the actual password (as well as the user and host placeholders)? If not, then something else is wrong. If yes, I'm not sure why the above would not work.
– NickD
May 24 '17 at 12:04
Yes it works when I execute it in a terminal! I have now double checked everything and found a possible problem (Updated the initial post)
– wasp256
May 24 '17 at 12:09
Yes it works when I execute it in a terminal! I have now double checked everything and found a possible problem (Updated the initial post)
– wasp256
May 24 '17 at 12:09
add a comment |
Try the following:
sshpass -p $PASSWORD ssh -t user@host<<EOF
echo uname -a
cd /tmp/ || exit 1
echo $PASSWORD | sudo -S bash ./remote_exec.sh
exit $?
EOF
I have tried the above code but I receive the following errortest.sh: line 47: warning: here-document at line 34 delimited by end-of-file (wantedEOF') test.sh: line 48: syntax error: unexpected end of file
– wasp256
May 24 '17 at 7:44
removed the space before the <<EOF but should be working just tested with passwordless connectivity
– GiannakopoulosJ
May 24 '17 at 12:11
Yeah I fixed then already when I tried it, but nevertheless didn't work
– wasp256
May 24 '17 at 12:14
add a comment |
Try the following:
sshpass -p $PASSWORD ssh -t user@host<<EOF
echo uname -a
cd /tmp/ || exit 1
echo $PASSWORD | sudo -S bash ./remote_exec.sh
exit $?
EOF
I have tried the above code but I receive the following errortest.sh: line 47: warning: here-document at line 34 delimited by end-of-file (wantedEOF') test.sh: line 48: syntax error: unexpected end of file
– wasp256
May 24 '17 at 7:44
removed the space before the <<EOF but should be working just tested with passwordless connectivity
– GiannakopoulosJ
May 24 '17 at 12:11
Yeah I fixed then already when I tried it, but nevertheless didn't work
– wasp256
May 24 '17 at 12:14
add a comment |
Try the following:
sshpass -p $PASSWORD ssh -t user@host<<EOF
echo uname -a
cd /tmp/ || exit 1
echo $PASSWORD | sudo -S bash ./remote_exec.sh
exit $?
EOF
Try the following:
sshpass -p $PASSWORD ssh -t user@host<<EOF
echo uname -a
cd /tmp/ || exit 1
echo $PASSWORD | sudo -S bash ./remote_exec.sh
exit $?
EOF
edited May 24 '17 at 12:12
answered May 23 '17 at 15:00
GiannakopoulosJGiannakopoulosJ
462213
462213
I have tried the above code but I receive the following errortest.sh: line 47: warning: here-document at line 34 delimited by end-of-file (wantedEOF') test.sh: line 48: syntax error: unexpected end of file
– wasp256
May 24 '17 at 7:44
removed the space before the <<EOF but should be working just tested with passwordless connectivity
– GiannakopoulosJ
May 24 '17 at 12:11
Yeah I fixed then already when I tried it, but nevertheless didn't work
– wasp256
May 24 '17 at 12:14
add a comment |
I have tried the above code but I receive the following errortest.sh: line 47: warning: here-document at line 34 delimited by end-of-file (wantedEOF') test.sh: line 48: syntax error: unexpected end of file
– wasp256
May 24 '17 at 7:44
removed the space before the <<EOF but should be working just tested with passwordless connectivity
– GiannakopoulosJ
May 24 '17 at 12:11
Yeah I fixed then already when I tried it, but nevertheless didn't work
– wasp256
May 24 '17 at 12:14
I have tried the above code but I receive the following error
test.sh: line 47: warning: here-document at line 34 delimited by end-of-file (wanted EOF') test.sh: line 48: syntax error: unexpected end of file– wasp256
May 24 '17 at 7:44
I have tried the above code but I receive the following error
test.sh: line 47: warning: here-document at line 34 delimited by end-of-file (wanted EOF') test.sh: line 48: syntax error: unexpected end of file– wasp256
May 24 '17 at 7:44
removed the space before the <<EOF but should be working just tested with passwordless connectivity
– GiannakopoulosJ
May 24 '17 at 12:11
removed the space before the <<EOF but should be working just tested with passwordless connectivity
– GiannakopoulosJ
May 24 '17 at 12:11
Yeah I fixed then already when I tried it, but nevertheless didn't work
– wasp256
May 24 '17 at 12:14
Yeah I fixed then already when I tried it, but nevertheless didn't work
– wasp256
May 24 '17 at 12:14
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f366769%2fssh-remote-file-execution-is-not-working%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
What you get if you run
set -xbefore running the script? Do you have the shebang on the first line of your script?– Jakuje
May 23 '17 at 12:57
Before running which script? The
test.sh?– wasp256
May 23 '17 at 13:01
I run the
set -xnow in the terminal before executingbash test.shbut it just returns+ bash linux_pentest.sh– wasp256
May 23 '17 at 13:04
Try to put it into the script on the line before the
sshpass.– Jakuje
May 23 '17 at 13:05
I did but no difference!?
– wasp256
May 23 '17 at 13:18