Getting the name of the previous process

1

0

I'm trying to generate notifications when certain commands finish execution. I'm trying to use xmessage or notify-send to generate this notification.

Right now, I'm trying it this way:

command; notify-send ...;

But I might have multiple such commands running – I want to distinguish between them. So I'm trying to get the PID and name of the process that finished. The problem is, the two processes (<command> and notify-send) aren't related.

Any hints or pointers on what to look for?

Utkarsh Sinha

Posted 2011-10-11T21:03:54.530

Reputation: 1 327

Answers

2

Make a notifier script (~/bin/notifyme)...

#!/bin/bash
(eval "$@")
notify-send "$1 finished" "Command returned $?."

...or a function (~/.bashrc):

notifyme() {
    (eval "$@")
    notify-send "$1 finished" "Command returned $?."
}

This is the easiest way.

user1686

Posted 2011-10-11T21:03:54.530

Reputation: 283 655

That seems to get everything done. – Utkarsh Sinha – 2011-10-11T22:24:08.813

1Is there a way to get auto completion to work? like notify partialcommand <tab> etc? – Utkarsh Sinha – 2011-10-11T22:50:30.850