Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • my guess is that $hostn is define in your first sshpass but the variable leave only during this execution, when you execute sshpass for the second time the variable $hostn doesn't exit anymore Commented Apr 24, 2018 at 9:31
  • A space in your password (or any globbing characters) may confuse your code as $oldpass in never properly quoted. Also, backslashes will not be read correctly as you're not using -r with read. In general, your script is a quoting minefield. Commented Apr 24, 2018 at 9:33
  • Depending on your version of Linux it may serve you better to use hostnamectl to set the host name. Commented Apr 24, 2018 at 9:40
  • Since you're trying to pass multiple commands on the same line (escaping the newlines), each command has to be terminated by ;. Otherwise you'll be trying to execute echo something read newhost sed ... etc. as a single command. Commented Apr 24, 2018 at 9:42
  • Thanks for your help i already put script working Its more simple and work Commented Apr 24, 2018 at 9:48