Odd script problem (sshpass)



  • Running a bash script (from Linux box) to sed some config files on local linux machines. It fails on every machine that has an 8 or 9 in the IP address. I am using leading zeros in the script (example: ping 10.0.1.077), so 10.0.1.077 will work, but 10.0.1.078 will not.
    The script pulls the IP list from a text file and the reason for the leading zeros is the last octet is a naming/number convention on the backend for something so it is used as a sed variable later in the script. This works without leading zeros, but I need the leading zeros for my variables. Any insight?

    Error message I get when an IP has an 8 or 9: "ssh: Could not resolve hostname 10.0.1.090: Name or service not known"


  • Service Provider

    If you output the resulting variable to the screen, then manually copy and paste to see if SSH works that way, what happens?



  • It is the same thing. I can replicate by running "ping 10.0.1.077" on the same machine hosting the SSHpass script and it works but the "ping 10.0.1.078" Its weird to me. I am logging into another machine on the network to see if it has the same issue.
    Edit: just tried pinging from a different machine with the same issue, 77 is good but anything with an 8 or 9 is bad. What the heck.



  • Hold the phone... machines I have been pinging and sshpass'ing from are on a different network using OpenVPN. I ssh'd into a machine and can ping all the 8's and 9's just fine!
    Weird network issue then...hm...



  • Solution found, human thinking error. Because I was trying to make a bash script take the last octet of an IP address and use it in a config file for naming I was using leading zeros where I shouldn't be. Most modern OS's assume octal is being used when leading zero's are inserted into a number, octal is 0-7 so that is why 8 and 9's weren't working. Also when I did ping 10.0.1.077 the response came back from 10.0.1.63 because 77 in octal equals 63 in decimal. Lesson learned for me trying to overcomplicate things.