Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an error EOF : Command no found when using ssh

Tags:

bash

unix

sh

scp

ssh

I am trying to rename the filenames in remote server like filename-dirname.suffix and copy the files to my server . I had written code like ....

  #!/usr/bin/bash
  TRANSFERSERVERXMLS="/emp/transfer/XMLS"
  REMOTESERVERXMLS="remoteemp/empdir/XMLS"

  # renaming the filenames in remote server like filename-dirname.suffix  
  ssh abc@xyz REMOTESERVERXMLS=$REMOTESERVERXMLS 'bash -s'<< 'EOF'

  for i in $REMOTESERVERXMLS/* ; do 
     if [[ -d $i ]]; then
            dirname=$(basename $i)
                     for j in $REMOTESERVERXMLS/$dirname/* ; do

                               fname="$(basename "$j")"

                               prefix=$(echo $fname | awk -F "." 'NF{NF-=1};1')
                               suffix=$(echo $fname | awk -F "." '{print $NF}')

                               target=$prefix-$dirname.$suffix

                                mv $REMOTESERVERXMLS/$dirname/"$fname" $REMOTESERVERXMLS/$dirname/"${target// /_}"
                          done
    fi
  done
  EOF
 scp abc@xyz:${REMOTESERVERXMLS}/*/* ${TRANSFERSERVERXMLS}

Getting an error : EOF:Command not found and scp is not working ( not able to copy into calling server)

like image 954
Prasu Avatar asked Mar 23 '26 13:03

Prasu


1 Answers

You have a space before the delimiter EOF. Do not indent EOF at the end of your "here document". The delimiter (EOF) must be the only thing on the line, with no leading or trailing whitespace.

Alternatively use <<- 'EOF' and indent with a tab.

like image 185
cdarke Avatar answered Mar 26 '26 05:03

cdarke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!