-1

I have a remote server with a couple of cache keys and I am trying to delete them. However, I am getting an error when I am running the script.

This is the script that I am using at the moment. Also, I setup public ssh key so I don't have to type the password:

input="path to file"
while IFS= read -r line; do
    ssh  -tt user@192.168.20.59 "sudo -S rm $line"
done < "$input"

If I try the ssh command outside the loop will work as expected. I can't figure out why the loop affecting the command

The error that I am getting is:

No such file or directory3f971a5e192fb9332c764a636a4205f
connection to 192.168.20.59 closed.

Thank you in advance

NOTE: Fixed the issue by modifying the script which generated the file. For some reason was adding ^M at the end of the line. I used echo & cat to generate the file and avoid alien characters

andregr_jp
  • 13
  • 6
  • 1
    Is there really no space after the word "directory" in the error? – Barmar Aug 12 '19 at 23:45
  • 2
    Not related to the error, but the loop will only process the first line of the file. Use the `-n` option to `ssh`. See https://stackoverflow.com/questions/9393038/ssh-breaks-out-of-while-loop-in-bash – Barmar Aug 12 '19 at 23:46
  • 1
    How are you answering the `sudo` password prompt, since input is redirected from the file? – Barmar Aug 12 '19 at 23:49
  • 1
    @andregr_jp: Picking up the first comment by Barmar: Could it be that `$input` contains carriage returns? – user1934428 Aug 13 '19 at 04:44
  • What if you do `ssh -tt user@192.168.20.59 "sudo -S rm $line"` -> `ssh -tt user@192.168.20.59 "sudo -S rm $line" – anishsane Aug 13 '19 at 08:48
  • @Barmar, the loop process all the lines from the file and I am getting the same error for all the files. However I will try all the suggestions and will update you soon – andregr_jp Aug 13 '19 at 10:14
  • Possible duplicate of [Shell script while read line loop stops after the first line](https://stackoverflow.com/questions/13800225/shell-script-while-read-line-loop-stops-after-the-first-line) – Joao Vitorino Aug 13 '19 at 12:44
  • 1
    @JoaoVitorino That's a fix for a different problem, which the OP claims he's not having (but I don't know why). It's another duplicate of the one I linked to. – Barmar Aug 13 '19 at 15:49
  • @Barmar But the solution must be the same, add `-n` to ssh command. – Joao Vitorino Aug 13 '19 at 16:23
  • @JoaoVitorino How would that fix a "file not found" error? – Barmar Aug 13 '19 at 16:27

1 Answers1

0

Fixed the issue by modifying the script which generated the file. For some reason was adding ^M at the end of the line. I used echo & cat to generate the file and avoid alien characters

andregr_jp
  • 13
  • 6