0

Running bash file download.sh, scp shows "no such file" error. So I try to run the command ps -efj | grep scp, and console outputs:

love@192.168.1.105:/home/storage/static/test/res/house/res.zip_b077f446? ../logs/static/test/res/house/

A redundant question mark occurs in the file name and I think that causes the error info of "no such file". But echo $SOURCE output is static/test/res/house/res_update.zip_61b25e4b, no question mark.

download.sh

#!/bin/bash

FILE=love@192.168.1.105:/home/storage/
while read p; do
    PART_DIR=$(echo $p | awk 'BEGIN{FS=OFS="/"}{NF--; print}')
    DEST_DIR="../logs/${PART_DIR}" # directory for saving files 
    mkdir -p "${DEST_DIR}"
    SOURCE="${FILE}${p}" 
    echo $SOURCE # debug, output: static/test/res/house/res_update.zip_61b25e4b 
    scp -P 19061 $SOURCE "${DEST_DIR}/"
done <../logs/file.txt

file.txt

static/test/res/house/res.zip_b077f446
static/test/res/house/res_update.zip_61b25e4b
DevSolar
  • 67,862
  • 21
  • 134
  • 209
user7328234
  • 393
  • 7
  • 23
  • 1
    First glance guess, `\r\n` line ends or somesuch... – DevSolar Dec 12 '17 at 08:17
  • @DevSolar I tried `set list` in vim, and it shows: $ in every line. – user7328234 Dec 12 '17 at 08:18
  • In other words, I can't reproduce the problem ATM, and I'd much prefer if you could edit the script (and the description) to *just* reproduce the error, ideally without creating directories or requiring a specific setup of subdirectories / remote connections I do not have and do not want. Create a [mcve]. – DevSolar Dec 12 '17 at 08:22
  • @DevSolar For `scp source dest`, I output the source value in two ways:1. `echo $SOURCE`. 2. `ps -efj | grep scp`. But for `ps` command, a redundant "?" occurs. So I try command `set list` in vim to check whether `\r\n` exists in file `file.txt`, but it seems not(only `$` occurs at the end of every line in `file.txt`). – user7328234 Dec 12 '17 at 08:25
  • 1
    Run `file file.txt`. Does it say "ASCII text", or does it say "ASCII text, with CRLF line terminators"? – DevSolar Dec 12 '17 at 08:34
  • @DevSolar It says:"ASCII text, with CRLF line terminators". Thanks. – user7328234 Dec 12 '17 at 08:36
  • 1
    You're welcome. Use `dos2unix` to convert the line endings in `file.txt`. (Vim's `set list` is depending on the `listchars` set and can be deceiving.) Also, [`man dirname`](https://linux.die.net/man/1/dirname) if you want to drop that `awk` bit in there. – DevSolar Dec 12 '17 at 08:37

0 Answers0