Creating a file within a folder then writing to that file with SSH





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







1















I am trying to use write a script that uses SSH to create a new directory and write to a text file in it. I've got 1 master on a network, and then 3 nodes that I want to create the directory on. These 4 machines are hosted on VMware.



#node1
ssh node1@192.168.1.102 'sudo touch /temp_dirname/host.txt'
ssh node1@192.168.1.102 'echo "node1" | sudo tee /temp_dirname/host.txt'

#node2
ssh node1@192.168.1.103 'sudo touch /temp_dirname/host.txt'
ssh node1@192.168.1.103 'echo "node1" | sudo tee /temp_dirname/host.txt'

#node3
ssh node3@192.168.1.104 'sudo touch /temp_dirname/host.txt'
ssh node3@192.168.1.104 'echo "node1" | sudo tee /temp_dirname/host.txt'


When I run this I get different errors for each node... for nodes 1 and 2 I get



touch: cannot touch '/temp_dirname/host.txt': no such file or directory


and



tee: temp_dirname/host.txt: no such file or directory


and node 3 I get:



touch: setting times of '/temp_dirname/ no such file or directory


and



tee: temp_dirname/host.txt: no such file or directory


I am absolutely confused with this as I thought touch created files - so why is it no such file or directory.










share|improve this question









New contributor




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
















  • 1





    Possibly related: Create file and its parent directory

    – steeldriver
    9 hours ago


















1















I am trying to use write a script that uses SSH to create a new directory and write to a text file in it. I've got 1 master on a network, and then 3 nodes that I want to create the directory on. These 4 machines are hosted on VMware.



#node1
ssh node1@192.168.1.102 'sudo touch /temp_dirname/host.txt'
ssh node1@192.168.1.102 'echo "node1" | sudo tee /temp_dirname/host.txt'

#node2
ssh node1@192.168.1.103 'sudo touch /temp_dirname/host.txt'
ssh node1@192.168.1.103 'echo "node1" | sudo tee /temp_dirname/host.txt'

#node3
ssh node3@192.168.1.104 'sudo touch /temp_dirname/host.txt'
ssh node3@192.168.1.104 'echo "node1" | sudo tee /temp_dirname/host.txt'


When I run this I get different errors for each node... for nodes 1 and 2 I get



touch: cannot touch '/temp_dirname/host.txt': no such file or directory


and



tee: temp_dirname/host.txt: no such file or directory


and node 3 I get:



touch: setting times of '/temp_dirname/ no such file or directory


and



tee: temp_dirname/host.txt: no such file or directory


I am absolutely confused with this as I thought touch created files - so why is it no such file or directory.










share|improve this question









New contributor




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
















  • 1





    Possibly related: Create file and its parent directory

    – steeldriver
    9 hours ago














1












1








1








I am trying to use write a script that uses SSH to create a new directory and write to a text file in it. I've got 1 master on a network, and then 3 nodes that I want to create the directory on. These 4 machines are hosted on VMware.



#node1
ssh node1@192.168.1.102 'sudo touch /temp_dirname/host.txt'
ssh node1@192.168.1.102 'echo "node1" | sudo tee /temp_dirname/host.txt'

#node2
ssh node1@192.168.1.103 'sudo touch /temp_dirname/host.txt'
ssh node1@192.168.1.103 'echo "node1" | sudo tee /temp_dirname/host.txt'

#node3
ssh node3@192.168.1.104 'sudo touch /temp_dirname/host.txt'
ssh node3@192.168.1.104 'echo "node1" | sudo tee /temp_dirname/host.txt'


When I run this I get different errors for each node... for nodes 1 and 2 I get



touch: cannot touch '/temp_dirname/host.txt': no such file or directory


and



tee: temp_dirname/host.txt: no such file or directory


and node 3 I get:



touch: setting times of '/temp_dirname/ no such file or directory


and



tee: temp_dirname/host.txt: no such file or directory


I am absolutely confused with this as I thought touch created files - so why is it no such file or directory.










share|improve this question









New contributor




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












I am trying to use write a script that uses SSH to create a new directory and write to a text file in it. I've got 1 master on a network, and then 3 nodes that I want to create the directory on. These 4 machines are hosted on VMware.



#node1
ssh node1@192.168.1.102 'sudo touch /temp_dirname/host.txt'
ssh node1@192.168.1.102 'echo "node1" | sudo tee /temp_dirname/host.txt'

#node2
ssh node1@192.168.1.103 'sudo touch /temp_dirname/host.txt'
ssh node1@192.168.1.103 'echo "node1" | sudo tee /temp_dirname/host.txt'

#node3
ssh node3@192.168.1.104 'sudo touch /temp_dirname/host.txt'
ssh node3@192.168.1.104 'echo "node1" | sudo tee /temp_dirname/host.txt'


When I run this I get different errors for each node... for nodes 1 and 2 I get



touch: cannot touch '/temp_dirname/host.txt': no such file or directory


and



tee: temp_dirname/host.txt: no such file or directory


and node 3 I get:



touch: setting times of '/temp_dirname/ no such file or directory


and



tee: temp_dirname/host.txt: no such file or directory


I am absolutely confused with this as I thought touch created files - so why is it no such file or directory.







18.04 bash ssh






share|improve this question









New contributor




Amy 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




Amy 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








edited 7 hours ago









dessert

25.6k674108




25.6k674108






New contributor




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









asked 10 hours ago









AmyAmy

183




183




New contributor




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





New contributor





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






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








  • 1





    Possibly related: Create file and its parent directory

    – steeldriver
    9 hours ago














  • 1





    Possibly related: Create file and its parent directory

    – steeldriver
    9 hours ago








1




1





Possibly related: Create file and its parent directory

– steeldriver
9 hours ago





Possibly related: Create file and its parent directory

– steeldriver
9 hours ago










1 Answer
1






active

oldest

votes


















2














If /temp_dirname doesn't exist, you can create it with mkdir -p /temp_dirname.



-p works with any arbitrary depth, creating directories as required.






share|improve this answer








New contributor




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
















  • 1





    This works! I could have sworn I tried this earlier with no avail... One question, I do have @vintnes is that /temp_dirname doesn't show up when I do either ls or ls -a

    – Amy
    9 hours ago











  • ls defaults to your current working directory -- usually /home/$USER by default. Specify path, as in ls -a / or ls -a /temp_dir or change your working directory with cd. Get comfortable with man!

    – vintnes
    5 hours ago












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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
});


}
});






Amy 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%2faskubuntu.com%2fquestions%2f1134155%2fcreating-a-file-within-a-folder-then-writing-to-that-file-with-ssh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














If /temp_dirname doesn't exist, you can create it with mkdir -p /temp_dirname.



-p works with any arbitrary depth, creating directories as required.






share|improve this answer








New contributor




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
















  • 1





    This works! I could have sworn I tried this earlier with no avail... One question, I do have @vintnes is that /temp_dirname doesn't show up when I do either ls or ls -a

    – Amy
    9 hours ago











  • ls defaults to your current working directory -- usually /home/$USER by default. Specify path, as in ls -a / or ls -a /temp_dir or change your working directory with cd. Get comfortable with man!

    – vintnes
    5 hours ago
















2














If /temp_dirname doesn't exist, you can create it with mkdir -p /temp_dirname.



-p works with any arbitrary depth, creating directories as required.






share|improve this answer








New contributor




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
















  • 1





    This works! I could have sworn I tried this earlier with no avail... One question, I do have @vintnes is that /temp_dirname doesn't show up when I do either ls or ls -a

    – Amy
    9 hours ago











  • ls defaults to your current working directory -- usually /home/$USER by default. Specify path, as in ls -a / or ls -a /temp_dir or change your working directory with cd. Get comfortable with man!

    – vintnes
    5 hours ago














2












2








2







If /temp_dirname doesn't exist, you can create it with mkdir -p /temp_dirname.



-p works with any arbitrary depth, creating directories as required.






share|improve this answer








New contributor




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










If /temp_dirname doesn't exist, you can create it with mkdir -p /temp_dirname.



-p works with any arbitrary depth, creating directories as required.







share|improve this answer








New contributor




vintnes 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 answer



share|improve this answer






New contributor




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









answered 10 hours ago









vintnesvintnes

362




362




New contributor




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





New contributor





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






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








  • 1





    This works! I could have sworn I tried this earlier with no avail... One question, I do have @vintnes is that /temp_dirname doesn't show up when I do either ls or ls -a

    – Amy
    9 hours ago











  • ls defaults to your current working directory -- usually /home/$USER by default. Specify path, as in ls -a / or ls -a /temp_dir or change your working directory with cd. Get comfortable with man!

    – vintnes
    5 hours ago














  • 1





    This works! I could have sworn I tried this earlier with no avail... One question, I do have @vintnes is that /temp_dirname doesn't show up when I do either ls or ls -a

    – Amy
    9 hours ago











  • ls defaults to your current working directory -- usually /home/$USER by default. Specify path, as in ls -a / or ls -a /temp_dir or change your working directory with cd. Get comfortable with man!

    – vintnes
    5 hours ago








1




1





This works! I could have sworn I tried this earlier with no avail... One question, I do have @vintnes is that /temp_dirname doesn't show up when I do either ls or ls -a

– Amy
9 hours ago





This works! I could have sworn I tried this earlier with no avail... One question, I do have @vintnes is that /temp_dirname doesn't show up when I do either ls or ls -a

– Amy
9 hours ago













ls defaults to your current working directory -- usually /home/$USER by default. Specify path, as in ls -a / or ls -a /temp_dir or change your working directory with cd. Get comfortable with man!

– vintnes
5 hours ago





ls defaults to your current working directory -- usually /home/$USER by default. Specify path, as in ls -a / or ls -a /temp_dir or change your working directory with cd. Get comfortable with man!

– vintnes
5 hours ago










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










draft saved

draft discarded


















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













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












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
















Thanks for contributing an answer to Ask Ubuntu!


  • 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%2faskubuntu.com%2fquestions%2f1134155%2fcreating-a-file-within-a-folder-then-writing-to-that-file-with-ssh%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

GameSpot

日野市

Tu-95轟炸機