-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday, 2018-02-10 at 22:45 +0100, Carlos E. R. wrote:
On 2018-02-10 22:36, Bernhard Voelker wrote:
On 02/10/2018 10:29 PM, Carlos E. R. wrote:
Is it possible to get the PID of the previous command launched and finished?
Example:
fetchmail .... echo "Posible PID of fetchmail was: $!"
Well, the value I get I know it was not the PID. The documentation says that "$!" gets the PID of the previously backgrounded process, so it is not what I want.
The crucial term for "$!" is: "background process".
Yes.
You send a process to background if you start it with "&" a the end.
Yes, I know.
$ sleep 60 &
$ echo $! 14100
So if you need the PID of the previously launched and finished process (whatever this may be good for),
To be able to read all it did in its log entries, differentiating from other instances that had a different PID (and some running at the same time, concurrently, so I can not simply "tail -f" the log).
then you could e.g. do:
sleep 10 & # send process to background pid=$! # get its PID wait $pid # wait for the process to terminate rc=$? # get the exit status of the process echo "PID: $pid, exit status: $rc"
Ah, interesting, thanks.
It is working perfectly! :-) I'm using this code (simplified): fetchmail -v ... & local PID=$! echo "Posible PID of fetchmail $CUAL was: $PID" wait grep fetchmail /var/log/mail | grep $PID | grep "message.*for .* at .*" | cut -d" " -f6- And I get at the end of each run output like this: Posible PID of fetchmail was: 27355 27355 - - 5 messages for my.idename at imap.server.net (folder Inbox). The real code is more complex, because I launch concurrently two fetchmail processes, and there is more debug output. As there are two fetchmail processes, I need to know the PID in order to identify the log entries pertaining to each process. What I get is not the number of fetched emails, but how many are in the folder. There is no single line in fetchmail output that says how many were actually fetched, I would have to parse the output and sum many lines. - -- Cheers, Carlos E. R. (from openSUSE 42.3 x86_64 "Malachite" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlp/lXUACgkQtTMYHG2NR9VYtQCeP33pxamfsEry3HnOOoi3Wov0 E6MAn2sQSRZ8pHyHlVbdN9EVdwVqrwzF =vwMM -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org