Posted: . At: 9:31 PM. This was 2 years ago. Post ID: 12666
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Get weather information from the command line in Linux.


Printing information about the weather on the command line is quite easy on Linux. One way is using the finger(1) command to retrieve a forecast for a certain city.

┌──(john㉿DESKTOP-PF01IEE)-[~]
└─$ finger sydney@graph.no
             -= Meteogram for Sydney, New South Wales, Australia =-             
 'C                                                                   Rain (mm) 
 25                                                                   
 24                                                                   
 23            ^^^                                                    
 22   ===^^^^^^   ===^^^                                              
 21===                  ^^^=--=--=--=--=--                            
 20                                       =--^^^                      
 19                                             ^^^^^^^^^^^^^^^^^^^^^ 
 18                                                                   
 17                                                                   
 16  |  |           |  |  |                             |  |  |  |  | 1 mm 
   _10_11_12_13_14_15_16_17_18_19_20 21 22 23 22/01 02 03 04 05 06_07 Hour
 
    SE SE SE SE SE SE SE SE SE SE SE SE SE SE SE SE SE SE SE SE SE SE Wind dir.
     5  6  6  6  6  6  6  5  5  4  4  4  3  3  2  2  2  2  1  1  2  2 Wind(m/s)
 
Legend left axis:   - Sunny   ^ Scattered   = Clouded   =V= Thunder   # Fog
Legend right axis:  | Rain    ! Sleet       * Snow
[Weather forecast from yr.no, delivered by the Norwegian Meteorological Institute and the NRK.]

This prints a very nice 24-hour forecast of the weather.

Another way is to use the airport information to get a weather report. Type sudo apt install metar and then find the airport code for your city. They may be found here: https://www.world-airport-codes.com/. Then you are ready to check the weather with the metar utility.

┌──(john㉿DESKTOP-PF01IEE)-[~]
└─$ metar -d yswg
YSWG 202300Z AUTO 08015KT 9999 // NCD 23/11 Q1028
Station       : YSWG
Day           : 20
Time          : 23:00 UTC
Wind direction: 80 (E)
Wind speed    : 15 KT
Wind gust     : 15 KT
Visibility    : 9999 M
Temperature   : 23 C
Dewpoint      : 11 C
Pressure      : 1028 hPa
Clouds        : 
Phenomena     :

Another way is to use the weather utility.

sudo apt install weather-util

Then run it like this to get weather information.

jason@kaio:~$ weather yswg
Searching via station...
[caching result Wagga Airport, Australia]
Current conditions at Wagga Airport, Australia (YSWG) 35-09S 147-27E 213M
Last updated Nov 05, 2018 - 05:00 PM EST / 2018.11.05 2200 UTC
   Temperature: 66 F (19 C)
   Relative Humidity: 100%
   Wind: from the NE (040 degrees) at 7 MPH (6 KT)
   Weather: rain
   Sky conditions: overcast

use the -v parameter for more verbose output.

jason@kaio:~$ weather -v yswg
Wagga Airport, Australia (YSWG) 35-09S 147-27E 213M
Nov 05, 2018 - 05:00 PM EST / 2018.11.05 2200 UTC
Wind: from the NE (040 degrees) at 7 MPH (6 KT):0
Visibility: 3 mile(s):0
Sky conditions: overcast
Weather: rain
Temperature: 66 F (19 C)
Dew Point: 66 F (19 C)
Relative Humidity: 100%
Pressure (altimeter): 29.77 in. Hg (1008 hPa)
ob: YSWG 052200Z 04006KT 6000 RA FEW010 SCT036 OVC064 19/19 Q1008
cycle: 22

The ansiweather utility is another way to get a weather forecast from the command line.

Install it like this.

sudo apt-get install ansiweather

Then run it to get the weather forecast for your city.

jason@kaio:~$ ansiweather -l Sydney,AU -f 3
 Sydney forecast => Tue Nov 06: 29/25 °C ☔ - Wed Nov 07: 25/14 °C ☔ - Thu Nov 08: 17/12 °C ☔

If the inxi utility is installed, this can also give you a nice weather forecast.

jason@kaio:~$ inxi -wxxx
Weather:   Conditions: 75 F (24 C) - light rain Wind: From the West at 7 MPH Humidity: 65%
           Pressure: 29.77 in (1008 mb) Location: Rhodes 02 (AUS) Altitude: 14 m
           Time: November 6, 9:24 AM AEDT (Australia/Sydney) Observation Time: November 6, 9:00 AM AEDT

These simple commands are very good for retrieving a weather forecast on the command line. Very useful to have in your .bashrc file to open a forecast when the terminal is opened.

The prettiest way to get a weather report on Linux is to use the wttr.in website. Access is via the curl utility.

┌──(john㉿DESKTOP-PF01IEE)-[~]
└─$ curl -s http://wttr.in/sydney
Weather report: sydney
 
                Shower in vicinity
       .--.     +23(25) °C     
    .-(    ).   ↖ 20 km/h      
   (___.__)__)  10 km          
                0.0 mm         
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Fri 21 Jan ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│  _`/"".-.     Patchy rain po…│    \  /       Partly cloudy  │    \  /       Partly cloudy  │  _`/"".-.     Patchy rain po…│
│   ,\_(   ).   22 °C          │  _ /"".-.     +22(25) °C     │  _ /"".-.     21 °C          │   ,\_(   ).   21 °C          │
│    /(___(__)21-27 km/h   │    \_(   ).   ← 22-26 km/h   │    \_(   ).   ← 18-24 km/h   │    /(___(__)20-29 km/h   │
│      ‘ ‘ ‘ ‘  10 km          │    /(___(__)  10 km          │    /(___(__)  10 km          │      ‘ ‘ ‘ ‘  10 km          │
│     ‘ ‘ ‘ ‘   0.1 mm | 96%0.0 mm | 0%0.0 mm | 0%    │     ‘ ‘ ‘ ‘   0.1 mm | 75%   │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Sat 22 Jan ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│  _`/"".-.     Patchy rain po…│               Cloudy         │    \  /       Partly cloudy  │    \  /       Partly cloudy  │
│   ,\_(   ).   22 °C          │      .--.     +22(25) °C     │  _ /"".-.     21 °C          │  _ /"".-.     20 °C          │
│    /(___(__)19-22 km/h   │   .-(    ).   ↖ 20-23 km/h   │    \_(   ).   ↖ 17-22 km/h   │    \_(   ).   ↖ 13-20 km/h   │
│      ‘ ‘ ‘ ‘  10 km          │  (___.__)__)  10 km          │    /(___(__)  10 km          │    /(___(__)  10 km          │
│     ‘ ‘ ‘ ‘   0.1 mm | 72%0.0 mm | 0%0.0 mm | 0%0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Sun 23 Jan ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│  _`/"".-.     Patchy rain po…│    \  /       Partly cloudy  │     \   /     Sunny          │     \   /     Clear          │
│   ,\_(   ).   22 °C          │  _ /"".-.     +23(25) °C     │      .-.      21 °C          │      .-.      21 °C          │
│    /(___(__)17-22 km/h   │    \_(   ).   ↖ 18-21 km/h   │   ― (   ) ―   ↖ 12-18 km/h   │   ― (   ) ―   ↖ 9-15 km/h    │
│      ‘ ‘ ‘ ‘  10 km          │    /(___(__)  10 km          │      `-’      10 km          │      `-’      10 km          │
│     ‘ ‘ ‘ ‘   0.1 mm | 76%0.0 mm | 0%/   \     0.0 mm | 0%/   \     0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
Location: Sydney, NSW, Australia [-33.8548156,151.2164539]

This shows a 3-day forecast of the weather in your town.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.