Frage

In a Bash Script I iterate over a list of IPv6 Addresses. I try to scp a unique file on each unique IPv6 Device. The unique file for every Device has the IPv6 Address in the filename.

Unfortunately SSH/SCP try to resolve something in the Filename and throw this Error:

"ssh: Could not resolve hostname file_2001: Name or service not known"

How can I supress this unexpected resolving? or is there a possibility to escape something in here?

#!/bin/bash

DEVICES="\
2001:db8::3e81:d8ff:feef:4982 \
"

do_copy_xml_file()
{
    if [ -e $XML_FILE ]; then
        for X in ${DEVICES} ; do
            echo "copy file_${X}.xml to ${X}:/data/file.sxml"
            sshpass scp -o stricthostkeychecking=yes file_"${X}".xml root@\[${X}\]:/file.xml
        done
    else
        echo $XML_FILE does not exist
    fi
}

do_copy_xml_file
War es hilfreich?

Lösung

Try using

file_"${X//:/_}".xml

in order to replace all : with _.

If your files are already named this way and this shouldn't change,

file_"${X//:/\\:}".xml

can be used as well. But I'm not sure if scp does recognize this appropriately.

Besides that, the scp manpage contains

File names may contain a user and host specification to indicate that the file is to be copied to/from that host. Local file names can be made explicit using absolute or relative pathnames to avoid scp treating file names containing ':' as host specifiers. Copies between two remote hosts are also permitted.

So just using ./file_"${X}".xml should work as well.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top