[SOLVED] Send Results of Curl Command to Notify-Send?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Command Substitution
Command substitution allows the output of a command to replace the com‐
mand name. There are two forms:
$(command)
or
`command`
Bash performs the expansion by executing command and replacing the com‐
mand substitution with the standard output of the command, with any
trailing newlines deleted. Embedded newlines are not deleted, but they
may be removed during word splitting. The command substitution $(cat
file) can be replaced by the equivalent but faster $(< file).
When the old-style backquote form of substitution is used, backslash
retains its literal meaning except when followed by $, `, or \. The
first backquote not preceded by a backslash terminates the command sub‐
stitution. When using the $(command) form, all characters between the
parentheses make up the command; none are treated specially.
Command substitutions may be nested. To nest when using the backquoted
form, escape the inner backquotes with backslashes.
If the substitution appears within double quotes, word splitting and
pathname expansion are not performed on the results.
Many thanks for both of your quick responses. Before I start playing with dijetlo's suggestion, I tried Sefyir's in terminal:
notify-send "$(
curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 \
| sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p'
)"
I've also tried notify-send "$(curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 \ | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p')"
as one command but no balloon comes up and I have to kill the curl process.
As an aside, I'm using Ubuntu Hardy 8.04 on an ancient HTC Shift X9500. That alone may make you lose all interest
The standard command worked! Bash version 3.2.39 still does the job. Many thanks to both of you. Ubuntu's weather indicator has recently stopped working for most legacy versions (NOAH has ceased support), and this old hardware couldn't take on a newer OS.
I could've run it in a conky but would've had to go back to desktop to see it. Plus, I learned much from your suggestions. The syntax remains a large mystery--I don't know how you guys do it.
Thanks for sticking with the thread and advising on antiques.
The syntax remains a large mystery--I don't know how you guys do it.
I presume you mean the sed syntax?
Best way to do that is to break up the command. Run the curl command by itself to see the output. Then, look for the output you want. In this case, it starts with a "Currently: "
I'm not great for regular expressions (which allows for refined control) but you can do a rudimentary start with grep
This is very helpful. I understand how the curl command calls the weather, but I'm still not certain why the grep command knows to put "Currently: " in front of the weather output.
For instance, what if you wanted to put a text output after the curl weather call, something like "So bundle up"
And is it possible to code a hard return in the notify-send balloon? Right now, my keystroke produces this output:
notify-send "$(curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=20902 \ | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3 \1/p') uptime:`uptime | sed -re 's/^.+\up//' | sed -re 's/min.*//g'`" "`acpi 1`"
It's two lines of output and I simply put hard spaces between the weather forecast and uptime. But what if I wanted to put the forecast on one line, uptime on the second, and the battery info on a third?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.