Linux - General This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
08-30-2016, 09:18 PM
|
#1
|
Member
Registered: Aug 2016
Posts: 52
Rep:
|
Send Results of Curl Command to Notify-Send?
This is a weather script I successfully use in conky. It produces a simple weather read-out (e.g. "84F Sunny").
#!/bin/sh
#AccuWeather (r) RSS weather tool for conky
#
#USAGE: weather.sh <locationcode>
#
#(c) Michael Seiler 2007
METRIC=0 #Should be 0 or 1; 0 for F, 1 for C
if [ -z $1 ]; then
echo
echo "USAGE: weather 20902"
echo
exit 0;
fi
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'
Is it possible to use this output with notify-send? A keystroke producing a notify-send balloon with the weather read-out?
Thanks,
Jake
|
|
|
08-31-2016, 10:29 AM
|
#2
|
Senior Member
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Rep:
|
Seems like...
Code:
#!/bin/bash
while [ 1 ]; do
notify-send "Current Temp" \
"`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'`" \
sleep 5m
done
would work
Last edited by dijetlo; 08-31-2016 at 10:31 AM.
|
|
1 members found this post helpful.
|
08-31-2016, 11:10 AM
|
#3
|
Member
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634
|
I just wrapped the curl in a command substitution
Code:
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'
)"
Code:
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.
Last edited by Sefyir; 08-31-2016 at 11:12 AM.
|
|
1 members found this post helpful.
|
08-31-2016, 12:09 PM
|
#4
|
Member
Registered: Aug 2016
Posts: 52
Original Poster
Rep:
|
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
Jake
Last edited by jakfish; 08-31-2016 at 12:21 PM.
|
|
|
08-31-2016, 01:13 PM
|
#5
|
Member
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634
|
Quote:
I tried Sefyir's in terminal:
|
Which wasn't the original presentation. It was originally in a script, relying on a variable passed to it
Code:
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')"
If you want to use it as a standard command, you'll need to switch that.
Code:
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')"
Quote:
As an aside, I'm using Ubuntu Hardy 8.04 on an ancient HTC Shift X9500.
|
Using Bash version 4.3.42(1)-release, you may need to do some debugging (or upgrade)
|
|
1 members found this post helpful.
|
08-31-2016, 03:32 PM
|
#6
|
Member
Registered: Aug 2016
Posts: 52
Original Poster
Rep:
|
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.
Jake
|
|
|
08-31-2016, 07:03 PM
|
#7
|
Member
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634
|
Quote:
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
Code:
$ curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=20902 | grep 'Currently: '
<title>Currently: Partly Cloudy: 83F</title>
Feel free to look at additional weather cli commands here
https://www.commandlinefu.com/comman.../sort-by-votes
Quote:
this old hardware couldn't take on a newer OS.
|
Check out linux-mint mate or xfce? They may work on older / lower end hardware
https://linuxmint.com/download.php
|
|
|
09-01-2016, 08:55 AM
|
#8
|
Member
Registered: Aug 2016
Posts: 52
Original Poster
Rep:
|
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?
Jake
|
|
|
All times are GMT -5. The time now is 03:46 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|