1

For years I've been using the following sequence (via ssh from my Linux Mint PC) on several different "headless" Raspberry Pi's to copy large folders over the Internet to my friend's PC (also Mint, and we're both on the same Zerotier network).

sudo rsync --bwlimit=300 -avP --append-verify "src_folder" "[email protected]:/dst_folder"
(Ctrl/Z)
bg
disown
exit

...after which I can just leave the Pi to chug away for hours, if necessary. But it was always difficult for my non-technically-minded friend to establish whether and when any given copy had successfully completed, so with some help from chatgpt, I ended up with this bash script (parameters 1=source, 2=dest)...

#!/bin/bash
folder_path="$1"
size_file="${folder_path%/}.size"
dest="$2"
find "$folder_path" -type f -exec du -b {} + | sort -n | tail -n1 | awk '{print $1}' > "$size_file"
sudo rsync --bwlimit=300 -avP --append-verify "$size_file" "$dest"
sudo rsync --bwlimit=300 -avP --append-verify "$folder_path" "$dest"

The basic idea is I create a text file1 with the same name as the source folder plus extension .size, which I send before the main folder. The .size file simply contains the exact size in bytes of the largest file in the source folder. I wrote a little utility program for my friend (user2) to use via Open with... in Nemo File Manager - all that does is compare the size of the largest received file with the value in the .size file, and display an appropriate status window using Zenity (size still increasing, copy complete, or copy stalled).

My problem is that although everything runs fine so long as I keep the ssh link open between Pi and PC, when I do Ctrl/Z ... bg [... disown ... exit] with the script (rather than the original single rsync command), sometimes rsync continues, other times it stops (stalled or terminated, I don't know).

I've tried various ways of detaching from the Pi (repeating the bg command, including fg, running the script thru sudo, simply closing the ssn connection window without running disown or exit,...). But nothing seems to work consistently, the way it did before I started trying to use a script.


1 I couldn't possibly have written that find ... awk... command myself (it was entirely chatgpt), so don't assume I have significant command-line skills. But I don't think that's relevant to my problem.

4
  • 2
    Why not just use screen or tmux?
    – Daniel B
    Jun 15, 2023 at 13:01
  • Because I don't know how (but I expect chatgpt could help on that front). Are you suggesting that the problem would go away if I used one of them? Which is easiest? Jun 15, 2023 at 13:04
  • Found this which may be relevant: Using TMUX on PI : I don't know that screen runs on the RaspberryPI, but I assume it does.... screen -S letrun then usually it's CTL+A, D to disconnect and screen -X letrun to reconnect/reattach. Let me know if that works.
    – Xinthral
    Jun 15, 2023 at 13:48
  • @Xinthral: Thanks. I'll give that a go. I never really need to "reattach" to the copy process (which I assume disappears elegantly, safely, and completely if & when it finishes copying the entire source folder). But being able to do that might be useful in some other contexts. Jun 15, 2023 at 14:00

1 Answer 1

0

I'd still like to understand why my bash script doesn't always work the same as just entering the three relevant commands consecutively on the command line, but following @Xinthral's suggestion, I installed tmux and ran...

tmux new -s my_rsync_session
rsync_size.sh "src_folder" "[email protected]:/dst_folder"
Ctrl + b
d

(Detaches from tmux job, after which I just exit from the Pi command line ssh connection.)

So far, so good.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .