Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was playing around with Pushover, and had the thought that it would be cool if I could use it as an argument on any random command, so that it would run a pushover script at the end of the task, regardless of what that task was.

I have no idea if it's possible, or how I would go about it, but I'd like to learn.

This question on the RasPi Stack Exchange site is what got me thinking about it. But I think there are many things it would be useful for, like letting you know when that compile job is finally finished, and maybe if it was successful.

I had the thought that it could look something like:

     $ apt-get -b source packagename -pushover "Compile job complete."

The thought being that the argument '-pushover [enter message text here]' after any command would execute the pushover script, and use their API to notify you via their app.

So I guess the question is, is it possible to do in this fashion? If so, where do I start? If not, are there better ways to accomplish the same thing, without being limited by what command you are running?

I'm not locked on the idea of using it as a command argument, but I do want a way to run it with any command, without writing a separate script for each one.

I am new to Linux, so if it is a non-starter idea, I'll take that answer, too, provided there are logical explanations of why it won't work to go with it.

share|improve this question

2 Answers 2

You do it the other way around:

$ pushover-notify "This is my message" command arg1 arg2

Your script pushover-notify could be something like this:

#!/bin/sh
TOKEN=your_token
USER=your_user
MSG="$1"
COMMAND="$2"
shift 2
if "$COMMAND" "$@" ; then
   # here run your send-message script, with message "$MSG". for example:
   curl -s \
        -F "token=$TOKEN" \
        -F "user=$USER" \
        -F "message=$MSG" \
        https://api.pushover.net/1/messages
else
   # here send some message indicating failure, or don't do anything. for example:
   curl -s \
        -F "token=$TOKEN" \
        -F "user=$USER" \
        -F "message=command failed: $COMMAND $@" \
        https://api.pushover.net/1/messages
fi
share|improve this answer
    
Can you break down the script you've laid out a bit for me? Is '# here run your send-message script, with message "$MSG"' intended as a placeholder for the pushover script, i.e. (curl -s \ --data-urlencode "token=$TOKEN" \ --data-urlencode "user=$USER" \ --data-urlencode "$COMMAND($DIST) HAS COMPLETED." \ api.pushover.net/1/messages ;;). Or is that a functional part of the script? I assume the former, but you know what they say about assumptions... –  zenbike Aug 10 '12 at 13:23
    
Yes, you got it right. The hash character # means the rest of the line is a comment. Between the if line and the else line you have to put the commands that will send the message when the command was successful. Between the else and fi lines, the commands to send the message if the command was unsuccessful. I'll just fill the spaces with the examples from the Pushover page. –  angus Aug 10 '12 at 13:34
    
Ok. I'll see what I can make work. –  zenbike Aug 10 '12 at 14:53

I have my programs send me emails, or beep the console when they are finished. I use the && character which tells console to wait for the previous command to finish and I end the whole thing with another & to get control of the console back.

So your example would look like this:

apt-get -b source packagename && sleep 10 && pushover "Compile job complete." &

I add sleep 10 for good measure. Note I don't know the pushover syntax.

Also, without using pushover, you might like using mailx to send you emails or txt messages, or echo -a "\a" to beep the console instead.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.