scp仅复制前两个文件求助:尝试复制4个文件却仅成功2个
Let's figure out why only your first two log files are making it across, and fix the issue so all four copy successfully. Here are the most likely causes and actionable fixes:
Check if the missing files actually exist
Start with the basics: verify thatdbg_c.date +"%Y-%m-%d-%H"_EST.loganddbg_d.date +"%Y-%m-%d-%H"_EST.logare present in/home/car02fv/. Run this command to list them:ls -l /home/car02fv/dbg_*.`date +"%Y-%m-%d-%H"`_EST.logIf only the first two files show up, the problem is that the latter logs haven't been generated yet—maybe the process creating them failed, or they're still being written to disk.
Fix timestamp inconsistency across filenames
Your current command runsdatefour separate times. If the command executes right at the top of an hour, the first two files might use hourX, while the last two use hourX+1—and those newer timestamped files won't exist yet. To fix this, store the timestamp in a variable first so all files use the exact same value:LOG_TIMESTAMP=$(date +"%Y-%m-%d-%H") scp /home/car02fv/dbg_a.${LOG_TIMESTAMP}_EST.log \ /home/car02fv/dbg_b.${LOG_TIMESTAMP}_EST.log \ /home/car02fv/dbg_c.${LOG_TIMESTAMP}_EST.log \ /home/car02fv/dbg_d.${LOG_TIMESTAMP}_EST.log \ user@host:/home/car02fv/The backslashes just make the command easier to read—they don't change its functionality.
Verify permissions for the missing files
If the files exist but won't copy, check if you have read access to them. Run:ls -l /home/car02fv/dbg_c.`date +"%Y-%m-%d-%H"`_EST.log /home/car02fv/dbg_d.`date +"%Y-%m-%d-%H"`_EST.logLook for the
r(read) permission in the first column for your user. If it's missing, adjust permissions withchmod +r <filename>or usesudoto run the scp command if you have elevated access.Enable verbose mode to catch hidden errors
SCP might be failing silently for the later files. Add the-vflag to get detailed output about each file's copy process:scp -v /home/car02fv/dbg_a.`date +"%Y-%m-%d-%H"`_EST.log dbg_b.`date +"%Y-%m-%d-%H"`_EST.log dbg_c.`date +"%Y-%m-%d-%H"`_EST.log dbg_d.`date +"%Y-%m-%d-%H"`_EST.log user@host:/home/car02fv/This will show you exactly where the process breaks—whether it's a network blip, a target directory permission issue, or something else.
Check target directory disk space
It's possible the first two files filled up the target/home/car02fv/directory. Log into the remote host and run:df -h /home/car02fv/If the
Use%is 100%, you'll need to free up space before copying the remaining files.
内容的提问来源于stack exchange,提问作者Camilo Riviere

