ssh and create directory if it doesn't exist
Hi guys,
i finally figured out how to ssh and check if a directory exists. now i'd like to create a directory if it doesn't. here's my script: Code:
#!/bin/bash i tried creating the the dir in the else if dir doesn't exist statement but obviously that doesn't work. (ut created it in the local server) how can i do this? any hint, tips, code etc. is much appreciated! |
You can just:
Code:
ssh $i /bin/mkdir -p .ssh |
What macemoneta says should work. Keep us posted on whether or not you had any success please.
|
thanks guys that works but i do want to do a little bit more.
how would i incorporate the following: scp ~/.ssh/id_dsa.pub server1:~/.ssh/authorized_keys so basically the logic is: 1. create directory if it doesn't exist on server1 which now i know can be done via: Code:
ssh $i /bin/mkdir -p .ssh which also can be done via: Code:
scp ~/.ssh/id_dsa.pub server1:~/.ssh/authorized_keys so my questions is how do i combine the two in a script? :) |
You just need to:
Code:
ssh-copy-id server1 |
Quote:
I did: Code:
ssh-copy-id -i ~/.ssh/id_dsa.pub server1 quick question, does this always rename the file id_dsa.pub to authorized_keys in the remote server? will look into rsa too, thanks. |
It doesn't rename, it appends the key to authorized_keys. The authorized_keys file can contain many keys.
|
All times are GMT -5. The time now is 06:50 PM. |