0

I tried to write a bash script for process some files inside a ssh server. I can login but I can't navigate through folders. I know I'm missing something important but I don't know what.

#!/bin/bash

input="/home/homename/password.txt"
while IFS= read -r line
do
  sshpass -p "$line" ssh -tt user@server
done < "$input" 

cd ..
cd ..
cd /folder/folder

Thank you all.

12
  • Um. You're logging in a separate time per line in password.txt? Why have a loop at all? Commented Jan 29, 2020 at 2:53
  • 1
    Beyond that, you need to pass commands to run on the remote system as stdin or command line arguments to SSH; it won't just send the rest of the script as input to a single command that script contains automatically. Commented Jan 29, 2020 at 2:53
  • Possible duplicate of What is the cleanest way to ssh and run multiple commands in Bash? Warning: if cd fails, your script can execute commands in the wrong place, with potentially weird and/or disastrous results. Commented Jan 29, 2020 at 3:00
  • @CharlesDuffy no this is a piece of code to read the only line (my password) file.txt that contain my password. I can delete the loop. Commented Jan 29, 2020 at 3:19
  • 1
    also this is not very secure. see the 'Security Considerations' section of linux.die.net/man/1/sshpass Commented Jan 29, 2020 at 3:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.