SED USE WITH A VARIABLE

Asked

Viewed 174 times

-5

I need to configure two files. sh, the first sshpasssrv.sh file will be responsible for filling in the second file that will be sshpass.sh, the first file when executed, will ask for the ip, then it will fill the following file with the ip I want in the following command line: sshapss -p "password" ssh [email protected] for example, I have more or less the following idea, I need to fill the second file only with ip.

#!/bin/bash   
#Aki pega o que digitar e coloca na variavel sshpass

echo "IP DO ARQUIVO SSHPASS :"
read ip

# Aki ele nao faz nada + do que a saida do comando echo $ip ele coloca no arquivo sshpass.sh

echo $ip >> sshpass.sh
sed "sshpass -p "pdvlinux" "$ip sshpassh.sh

1 answer

1


If I understood what you want to do. That would be, add a command in the IP-based sshpassh.sh file that has been reported. You do not need to add the IP and then give a sed to change the line.

Change the last two lines of your code to:

echo "sshpass -p \"senha\" ssh root@$ip" >> sshpassh.sh

If you always want to replace the command that was already defined in the file, switch from >> to >.

Tip: It wouldn’t be better to ssh with private/foreign key instead of sshpass?

  • in case using ssh with private/foreign key would look like? which your suggestion?

  • @Ricardojmsistemas Before you have to create a public/private key on the client machine with the ssh-keygen command. Ai vc copies the contents of the file . pub created in the ~/. ssh folder for the ~/. ssh/authorized_keys file on your server. With this you should be able to log into the server from your client by only doing a "ssh root@$ip" you do not need to pass the password. This link has a step by step with images to facilitate.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.