I have this script:


    #This works:
    #dd if=$file bs=1 skip=$skippedBytes | ssh sshConnection 'cat - >> /remote/dir/myTarget.txt.output' > export.output 2>&1

    #This does not work:
    dd if=$file bs=1 skip=$skippedBytes | $($exportCommandString $file) > export.output 2>&1

    cat export.output

    echo 'ssh '$userAtServer' '\''cat - >> '$targetDir'/'$filename'.output'\'
    #Same result with this:
    #echo "ssh $userAtServer 'cat - >> $targetDir/$filename.output'" 

exportFile mySource.txt 9 "sshExportCommand sshConnection /remote/dir myTarget.txt"

When invoking it, I obtain the following output:

85+0 records in
85+0 records out
85 bytes (85 B) copied, 0.00080048 s, 106 kB/s
Read bytes: 85
ovh_ssh: cat - >> /remote/dir/myTarget.txt.output: No such file or directory

What does prevent this from working ? Is this command substitution ? Anything else I missed ?

  • Can you maybe strip your script down to the bare essentials for what your question is? It will greatly increase the chance for a useful answer – Bernhard Mar 10 '13 at 19:43

As you written in the comment code line, the following is working:

byteCount=$( exec 3>&1 ; dd if=$file bs=1 skip=$skippedBytes | tee -a >(wc -c >&3) -a $file.output | ssh sshConnection 'cat - >> /remote/dir/myTarget.txt.output' > export.output 2>&1 ; 3>&1 )

So adapt this knowledge and use this refactoring:

   rm export.output

   byteCount=$( exec 3>&1 ; dd if=$file bs=1 skip=$skippedBytes | tee -a >(wc -c >&3) -a $file.output | ssh ${userAtServer} "cat - >>$targetDir/${targetFile}" > export.output 2>&1 ; 3>&1 )

   echo "Read bytes: $byteCount"
   cat export.output
 exportFile mySource.txt 9 sshConnection /remote/dir myTarget.txt
  • It would work, but I need export command string to be configurable and multiple. Something like this: exportFile mySource.txt 9 "sshExportCommand sshConnection /remote/dir myTarget.txt" "sshExportCommand otherSshConnection /otherRemote/dir myTarget2.txt" – lauhub Mar 10 '13 at 21:09
  • @lauhub Sorry - that use case is not described in your question. I'm sure that you not really need it this way. Change your point of view. Duplicate transmissions can be initiated by duplicate exportFile calls. If you realy need it with one function, you may use a wrapper function dividing the arguments to a sequence of exportFile invocations. – H.-Dirk Schmitt Mar 10 '13 at 21:17
  • Ok, thanks, I am gonna try this. Actually I found some workaround but was curious why this way did not work – lauhub Mar 10 '13 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.