Script for sending commands via ssh and not wait till and leave the terminalKeep running a script via...

What is a common way to tell if an academic is "above average," or outstanding in their field? Is their h-index (Hirsh index) one of them?

Convert Numbers To Emoji Math

Why does blending blueberries, milk, banana and vanilla extract cause the mixture to have a yogurty consistency?

Can anyone identify this unknown 1988 PC card from The Palantir Corporation?

What detail can Hubble see on Mars?

Is there a reason why Turkey took the Balkan territories of the Ottoman Empire, instead of Greece or another of the Balkan states?

How can I finally understand the confusing modal verb "мочь"?

My large rocket is still flipping over

How to speed up large double sums in a table?

Can an earth elemental drag a tiny creature underground with Earth Glide?

How did the Force make Luke hard to hit in the Battle of Yavin?

How do I, as a DM, handle a party that decides to set up an ambush in a dungeon?

How to preserve a rare version of a book?

Make me a minimum magic sum

Transistor gain, what if there is not enough current?

What is the meaning of 「隣のおじいさんは言いました」

Referring to person by surname, keep or omit "von"?

What is more safe for browsing the web: PC or smartphone?

Why are condenser mics so much more expensive than dynamics?

Changing stroke width vertically but not horizontally in Inkscape

Do Jedi mind tricks work on Ewoks?

Python 3 - simple temperature program version 1.3

Game artist computer workstation set-up – is this overkill?

Subnumcases as a part of align



Script for sending commands via ssh and not wait till and leave the terminal


Keep running a script via sshCan't start presentation on remote computer console session from an SSH sessionExecuting commands with ssh and shell script using variables on a remote machineDebian autossh boot script not working properlyRedirecting the output of a script to the remote server via scp or sshssh then once connected ssh to another server and execute commands and exit bothSSH : launch task and leave it running even if I quit the terminalTerminal commands not workingRemote ssh script execution with EOI or EOSSH adding dots in front of commandsRemote Commands and Restricted Shells via SSH






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have sevarl computers, combined into network with Ethernet switch.
All are running Fedora server and have connection to Internet.



What I need is a script, which:




  • Connects to all nodes from list

  • Send commands (like update all or install some packages)

  • Close the connection, but commands keep running on target machines


Currently, script is:



#!/bin/bash
targets_username='username'
targets_password='password'
targets_IPs=( 192.168.1.100 192.168.1.101 192.168.1.102 )

SCRIPT1='dnf update -y'
SCRIPT2='dnf update -y && poweroff'

echo "$MY_IP"
for IP in ${targets_IPs[@]}; do
export SSHPASS=$targets_password
script="nohup sh -c "( ( $SCRIPT1 & > /dev/null) &)""
echo $IP
echo $script
sshpass -e ssh -o StrictHostKeyChecking=no -l $targets_username@$IP $script
done



The problems are:




  • as soon as connection is closed, running of commands stops

  • if command contains extra command like reboot or poweroff it is forwarded to main computer, from which this script started.


How to fix that?



I found posts here, here and here about possible solutions, but they didn't help.










share|improve this question







New contributor




Yehor Pererva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Do things change if you pass -n -T to ssh ?

    – Stephen Harris
    10 mins ago


















0















I have sevarl computers, combined into network with Ethernet switch.
All are running Fedora server and have connection to Internet.



What I need is a script, which:




  • Connects to all nodes from list

  • Send commands (like update all or install some packages)

  • Close the connection, but commands keep running on target machines


Currently, script is:



#!/bin/bash
targets_username='username'
targets_password='password'
targets_IPs=( 192.168.1.100 192.168.1.101 192.168.1.102 )

SCRIPT1='dnf update -y'
SCRIPT2='dnf update -y && poweroff'

echo "$MY_IP"
for IP in ${targets_IPs[@]}; do
export SSHPASS=$targets_password
script="nohup sh -c "( ( $SCRIPT1 & > /dev/null) &)""
echo $IP
echo $script
sshpass -e ssh -o StrictHostKeyChecking=no -l $targets_username@$IP $script
done



The problems are:




  • as soon as connection is closed, running of commands stops

  • if command contains extra command like reboot or poweroff it is forwarded to main computer, from which this script started.


How to fix that?



I found posts here, here and here about possible solutions, but they didn't help.










share|improve this question







New contributor




Yehor Pererva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Do things change if you pass -n -T to ssh ?

    – Stephen Harris
    10 mins ago














0












0








0








I have sevarl computers, combined into network with Ethernet switch.
All are running Fedora server and have connection to Internet.



What I need is a script, which:




  • Connects to all nodes from list

  • Send commands (like update all or install some packages)

  • Close the connection, but commands keep running on target machines


Currently, script is:



#!/bin/bash
targets_username='username'
targets_password='password'
targets_IPs=( 192.168.1.100 192.168.1.101 192.168.1.102 )

SCRIPT1='dnf update -y'
SCRIPT2='dnf update -y && poweroff'

echo "$MY_IP"
for IP in ${targets_IPs[@]}; do
export SSHPASS=$targets_password
script="nohup sh -c "( ( $SCRIPT1 & > /dev/null) &)""
echo $IP
echo $script
sshpass -e ssh -o StrictHostKeyChecking=no -l $targets_username@$IP $script
done



The problems are:




  • as soon as connection is closed, running of commands stops

  • if command contains extra command like reboot or poweroff it is forwarded to main computer, from which this script started.


How to fix that?



I found posts here, here and here about possible solutions, but they didn't help.










share|improve this question







New contributor




Yehor Pererva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have sevarl computers, combined into network with Ethernet switch.
All are running Fedora server and have connection to Internet.



What I need is a script, which:




  • Connects to all nodes from list

  • Send commands (like update all or install some packages)

  • Close the connection, but commands keep running on target machines


Currently, script is:



#!/bin/bash
targets_username='username'
targets_password='password'
targets_IPs=( 192.168.1.100 192.168.1.101 192.168.1.102 )

SCRIPT1='dnf update -y'
SCRIPT2='dnf update -y && poweroff'

echo "$MY_IP"
for IP in ${targets_IPs[@]}; do
export SSHPASS=$targets_password
script="nohup sh -c "( ( $SCRIPT1 & > /dev/null) &)""
echo $IP
echo $script
sshpass -e ssh -o StrictHostKeyChecking=no -l $targets_username@$IP $script
done



The problems are:




  • as soon as connection is closed, running of commands stops

  • if command contains extra command like reboot or poweroff it is forwarded to main computer, from which this script started.


How to fix that?



I found posts here, here and here about possible solutions, but they didn't help.







shell-script ssh terminal remote






share|improve this question







New contributor




Yehor Pererva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Yehor Pererva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Yehor Pererva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 53 mins ago









Yehor PerervaYehor Pererva

1




1




New contributor




Yehor Pererva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Yehor Pererva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Yehor Pererva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Do things change if you pass -n -T to ssh ?

    – Stephen Harris
    10 mins ago



















  • Do things change if you pass -n -T to ssh ?

    – Stephen Harris
    10 mins ago

















Do things change if you pass -n -T to ssh ?

– Stephen Harris
10 mins ago





Do things change if you pass -n -T to ssh ?

– Stephen Harris
10 mins ago










0






active

oldest

votes












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
});


}
});






Yehor Pererva is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f517308%2fscript-for-sending-commands-via-ssh-and-not-wait-till-and-leave-the-terminal%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








Yehor Pererva is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Yehor Pererva is a new contributor. Be nice, and check out our Code of Conduct.













Yehor Pererva is a new contributor. Be nice, and check out our Code of Conduct.












Yehor Pererva is a new contributor. Be nice, and check out our Code of Conduct.
















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f517308%2fscript-for-sending-commands-via-ssh-and-not-wait-till-and-leave-the-terminal%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...