for years have i been using a self-made backup script [...]
I won't get into that -- I can't even fathom why you'd need coproc
for a backup script. I tend to keep things simple -- they tend to
thank me in failing less often and in more understandable ways.
I didn't try your script, but may be there is a "\n" missing down^^
there?
^^^printf "%s\n" "sleep 3;exit" >&6
On 1 Jun 2024 10:11 +0200, from [email protected]:
for years have i been using a self-made backup script [...]
I won't get into that -- I can't even fathom why you'd need coproc
for a backup script. I tend to keep things simple -- they tend to
thank me in failing less often and in more understandable ways.
I agree. There are plenty enough of ready-made backup solutions to
cater to different needs that making one's own shouldn't be needed.
I didn't try your script, but may be there is a "\n" missing down
there?
^^^^^printf "%s\n" "sleep 3;exit" >&6
Hello,
for years have i been using a self-made backup script [...]
^^^printf "%s\n" "sleep 3;exit" >&6
Am 01.06.2024 um 09:20 schrieb DdB:
Hello,
I get it: you wouldnt trust my scripts.
Thats fine with me. But my
experience is quite different: Software, i prefer using is such, that i
keep control.
#!/bin/bash -e
coproc { bash; }
exec 5<&${COPROC[0]} 6>&${COPROC[1]}
fd=5
echo "ls" >&6
while IFS= read -ru $fd line
do
printf '%s\n' "$line"
done
printf "%s\n" "sleep 3;exit" >&6
while IFS= read -ru $fd line
do
printf '%s\n' "$line"
done
exec 5<&- 6>&-
wait
echo waited, done
i get the output from ls, but then the thing is hanging indefinitely, apparently not reaching the exit line. :(
Hello,
for years have i been using a self-made backup script, that did mount a
drive via USB, performed all kinds of plausibility checks, before
actually backing up incrementally. Finally verifying success and logging
the activities while kicking the ISB drive out.
Since a few months, i do have a real backup server instead, connecting
to it via ssh i was able to have 2 terminals open and back up manually.
Last time, i introduced a mistake by accident and since, i am trying to automate the whole thing once again, but that is difficult, as the load
on the net is huge, mbuffer is useful in that regard. So i was intending
to have just one script for all the operations using coproc to
coordinate the 2 servers.
But weird things are going on, i cant reliably communicate between host
and backup server, at least not automatically.
Searching the web, i found: https://github.com/reconquest/coproc.bash/blob/master/REFERENCE.md
But i was unable to get this to work, which seems to indicate, that i am misunderstanding something.
The only success i had was to "talk" to a chess engine in a coprocess,
which did go well. But neither bash nor ssh are cooperating, i may have timing issues with the pipes or some other side effects.
How can i describe? For example if i start this:
#!/bin/bash -e
coproc { bash; }
exec 5<&${COPROC[0]} 6>&${COPROC[1]}
fd=5
echo "ls" >&6
while IFS= read -ru $fd line
do
printf '%s\n' "$line"
done
printf "%s\n" "sleep 3;exit" >&6
while IFS= read -ru $fd line
do
printf '%s\n' "$line"
done
exec 5<&- 6>&-
wait
echo waited, done
i get the output from ls, but then the thing is hanging indefinitely, apparently not reaching the exit line. :(
Anyone who can share his experience to advance my experimenting?
DdB
for years have i been using a self-made backup script, that did mount a
drive via USB, performed all kinds of plausibility checks, before
actually backing up incrementally. Finally verifying success and logging
the activities while kicking the ISB drive out.
Am 02.06.2024 um 02:41 schrieb DdB:
Will share my findings, once i made more progress...
Here is what i've got before utilizing it:
datakanja@PBuster-NFox:/mnt/tmp$ cat test
#!/bin/bash -e
# testing usefulness of coprocess to control host and backup machine from a single script.
# beware: do not use subprocesses or pipes, as that will confuse the pipes setup by coproc!
# At this point, this interface may not be very flexible
# but trying to follow best practices for using coproc in bash scripts
# todo (deferred): how to handle stderr inside coproc?
# todo (deferred): what, if coproc dies unexpectedly?
# setting up the coprocess:
stdout_to_ssh_stdin=5 # arbitrary choice outside the range of used file desciptors
stdin_from_ssh_stdout=6
coproc SSH { bash; } # for testing purposes, i refrain from really involving ssh just yet and replace it with bash:
# save filedescriptors by duplicating them:
eval "exec ${stdin_from_ssh_stdout}<&${SSH[0]} ${stdout_to_ssh_stdin}>&${SSH[1]}"
echo The PID of the coproc is: $SSH_PID # possibly useful for inspection
unique_eof_delimirer="<EOF>"
line=""
# collect the output available and print it locally (synchonous):
function print-immediate-output () {
while IFS= read -r -u "${stdin_from_ssh_stdout}" line
do
if [[ "${line:0-5:5}" == "$unique_eof_delimirer" ]] # currently, the length is fixed
then
line="${line%<EOF>}"
if [[ ! -z $line ]]
then
printf '%s\n' "$line"
fi
break
fi
printf '%s\n' "$line"
done
}
# send a single command via ssh and print output locally
function send-single-ssh-command () {
printf '%s\n' "$@" >&"${stdout_to_ssh_stdin}"
printf '%s\n' "echo '"$unique_eof_delimirer"'" >&"${stdout_to_ssh_stdin}"
print-immediate-output
}
send-single-ssh-command "find . -maxdepth 1 -name [a-z]\*" # more or less a standard command, that succeeds
send-single-ssh-command "ls nothin" # more or less a standard command, that fails
# tearing down the coprocess:
printf "%s\n" "exit" >&"${stdout_to_ssh_stdin}" # not interested in any more output (probably none)
wait
# Descriptors must be closed to prevent leaking.
eval "exec ${stdin_from_ssh_stdout}<&- ${stdout_to_ssh_stdin}>-"
echo "waited for the coproc to end gracefully, done"
datakanja@PBuster-NFox:/mnt/tmp$ ./test
The PID of the coproc is: 28154
./test
./out
ls: Zugriff auf 'nothin' nicht möglich: Datei oder Verzeichnis nicht gefunden
waited for the coproc to end gracefully, done
datakanja@PBuster-NFox:/mnt/tmp$
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 146:11:55 |
| Calls: | 12,089 |
| Calls today: | 2 |
| Files: | 15,000 |
| Messages: | 6,517,501 |