Lyte's Blog

Bad code, bad humour and bad hair.

Remembering Long Running Commands

At least once a day I’ll start a command that runs for a few hours.

Usually I attach a sendmail command to the end of it so that I’ll know when it completes like so:

1
2
3
$ some really slow command; \
echo "Subject: some really slow command has completed" \
| sendmail me@exmaple.com

… but sometimes I just forget.

On Solaris I previously fired up a second screen session at this point and wrote something like:

1
2
3
$ pwait <pid of some really slow command>; \
echo "Subject: some really slow command has completed" \
| sendmail me@exmaple.com

but in Linux I haven’t been able to achieve the same thing:

1
2
$ wait 1234
bash: wait: pid 1234 is not a child of this shell

so I’ve been looking for an alternative solution.

I finally figured it out.

Press ctrl+z to pause the process:

1
2
$ some really slow command
[1]+  Stopped                 some really slow command

then simply fore-ground the process with the usual email alert appended on the end:

1
2
3
$ fg; \
echo "Subject: some really slow command has completed" \
| sendmail me@exmaple.com

Comments