Language Selection

English French German Italian Portuguese Spanish

The Bash Fingertips: Making Your Own 'Information Centre'

Filed under
Howtos

Information Centre

FORGET bloated Web browsers. Forget so-called 'social' media (I call it social control media). They're not efficient, they eat up a lot of memory and CPU cycles, and the interfaces are not consistent (across sites). They're sufficiently distracting and they have ads. They erode privacy. They don't scale well; neither for an aging system (my laptop turns 10 in a few months) nor for users. GUIs are good in particular scenarios, but when the same things are repeated over and over again one might as well set up scripts, automating things and tailoring one's own interfaces, which is easy to achieve (relatively fast and simple) in the command line. It's also more accessible, e.g. over SSH. The pertinent tools are already out there (available for download/installation from repositories), they just need to be put together and programming skills aren't required, just batching in a bash file.

Some years ago I 'developed' a little script (I've been scripting since I was about 12). I called it getswap-sorted.sh and it just ran another script that helped me see what applications use the swap (and how much of it). For the sake of speed I like to restart applications that heavily use swap (i.e. depend on magnetic disk operations). I don't have much RAM. I never had more than 2 GB. getswap-sorted.sh just called out ./getswap.sh | sort -n -k 5 and getswap.sh comes from Erik Ljungstrom. Here it is:

#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
let OVERALL=$OVERALL+$SUM
SUM=0

done

The output of getswap-sorted.sh would be something like this:


PID=1559 - Swap used: 16472 - (x-terminal-emul )
PID=21980 - Swap used: 16648 - (kwalletd5 )
PID=25548 - Swap used: 16704 - (konversation )
PID=631 - Swap used: 19336 - (kded5 )
PID=23817 - Swap used: 50048 - (pidgin )
PID=23923 - Swap used: 180312 - (thunderbird )


This helps me see which application/process number uses swap and to what degree. It's sorted by the amount of swap taken and the PID helps when I just want to kill a process from the command line (some are small and obsolete anyway).

My script, however, grew bigger over time. I added more things to it, eventually binding it to a special (fifth) mouse key, using xbindkeys -- an immensely valuable and powerful program I've used since around 2004. Extra mouse buttons always seemed worthless (anything more than three), but that's just because there was no program I needed to open or action I needed to invoke often enough. Over time I found that keeping a new terminal one click away (fourth button) and another special terminal also a click away improved my workflow/productivity. I just needed to invest some time in tailoring it. I ended up opening, temporarily, a terminal window with important information displayed, such as weather, disk space (I'm always near the limits), swap usage (I have only 2GB of RAM), uptime, real-time football scores etc. Change of wallpapers was lumped in too, for good measure...

For football tables/scores use one of the following 1) livescore-cli 2) soccer-cli and 3) football-cli.

Sadly, the above CLI football scores' tools got 'stolen' by Microsoft and need to isolate themselves GitHub, in due cource/time. I use the first of the three as it suits my needs best and does not require an API key.

The output looks like this:

 ... Fetching information from www.livescore.com ... 
Displaying Table for Barclay's Premier League
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                Barclay's Premier League TABLE
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 LP     Team Name               GP      W       D       L       GF      GA      GD      Pts
--------------------------------------------------------------------------------------------------
 1      Liverpool               24      19      4       1       55      14      41      61
 2      Tottenham Hotspur       25      19      0       6       51      24      27      57
 3      Manchester City         24      18      2       4       63      19      44      56
 4      Chelsea                 25      15      5       5       45      23      22      50
 5      Arsenal                 24      14      5       5       50      33      17      47
 6      Manchester United       24      13      6       5       48      35      13      45
 7      Wolverhampton Wanderers 25      11      5       9       33      32      1       38
 8      Watford                 25      9       7       9       33      34      -1      34
 9      Everton                 25      9       6       10      36      36      0       33
 10     AFC Bournemouth         25      10      3       12      37      44      -7      33
 11     Leicester City          24      9       5       10      30      30      0       32
 12     West Ham United         24      9       4       11      30      37      -7      31
 13     Brighton & Hove Albion  25      7       6       12      27      36      -9      27
 14     Crystal Palace          25      7       5       13      26      33      -7      26
 15     Newcastle United        25      6       6       13      21      33      -12     24
 16     Southampton             25      5       9       11      27      42      -15     24
 17     Burnley                 25      6       6       13      26      46      -20     24
 18     Cardiff City            25      6       4       15      22      46      -24     22
 19     Fulham                  25      4       5       16      25      55      -30     17
 20     Huddersfield Town       25      2       5       18      13      46      -33     11
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 LP = League Position   GP = Games Played       W = Wins        D = Draws       L = Lose 
 GF = Goals For         GA = Goal Against       GD = Goal Differences
--------------------------------------------------------------------------------------------------
 Champions League       Champions League qualification  Europa League
 Europa League qualification    Relegation
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Real-time scores (when matches are on):

 ... Fetching information from www.livescore.com ... 
Displaying Scores for Barclay's Premier League
----------------------------------------------------------------------------
                 Barclay's Premier League SCORES 
----------------------------------------------------------------------------
 January 29  FT     Arsenal                  2 - 1  Cardiff City           
 January 29  FT     Fulham                   4 - 2  Brighton & Hove Albion 
 January 29  FT     Huddersfield Town        0 - 1  Everton                
 January 29  FT     Wolverhampton Wanderers  3 - 0  West Ham United        
 January 29  FT     Manchester United        2 - 2  Burnley                
 January 29  FT     Newcastle United         2 - 1  Manchester City        
 January 30  FT     AFC Bournemouth          4 - 0  Chelsea                
 January 30  FT     Southampton              1 - 1  Crystal Palace         
 January 30  FT     Liverpool                1 - 1  Leicester City         
 January 30  FT     Tottenham Hotspur        2 - 1  Watford                
 February 2  FT     Tottenham Hotspur        1 - 0  Newcastle United       
 February 2  FT     Brighton & Hove Albion   0 - 0  Watford                
 February 2  FT     Burnley                  1 - 1  Southampton            
 February 2  FT     Chelsea                  5 - 0  Huddersfield Town      
 February 2  FT     Crystal Palace           2 - 0  Fulham                 
 February 2  FT     Everton                  1 - 3  Wolverhampton Wanderers
 February 2  FT     Cardiff City             2 - 0  AFC Bournemouth        
 February 3  15:05  Leicester City           ? - ?  Manchester United      
 February 3  17:30  Manchester City          ? - ?  Arsenal                
 February 4  21:00  West Ham United          ? - ?  Liverpool              
----------------------------------------------------------------------------
---------------------------------------

Now putting it all together:


feh --bg-fill --randomize /media/roy/c3fd5b6e-794f-4f24-b3e7-b4ead3722f11/home/roy/Main/Graphics/Wallpapers/Single\ Head/natgeo/* &

livescore -t bpl 

./getswap.sh | sort -n -k 5
 curl -4 http://wttr.in/Manchester
 swapon --summary | grep sda2
 df | grep sda1
uptime

sleep 10

livescore -s bpl 

sleep 40

The first line is feh choosing a wallpaper at random from a collection of award-winning National Geographic photographs. The options and the underlying parameters are self-explanatory.

The football league's table is then shown.

Next, after about 10 seconds of processing, a list of processes will show up based on swap usage (as described above)

The weather at home (Manchester) will then be shown, with colour. Right now I get:

Weather report: Manchester

     \   /     Sunny
      .-.      -5--2 °C       
   ― (   ) ―   ↑ 9 km/h       
      `-’      10 km          
     /   \     0.0 mm         
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Sun 03 Feb ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│    \  /       Partly cloudy  │      .-.      Light drizzle  │  _`/"".-.     Light rain sho…│               Mist           │
│  _ /"".-.     -4-0 °C        │     (   ).    -2-3 °C        │   ,\_(   ).   1-3 °C         │  _ - _ - _ -  0-3 °C         │
│    \_(   ).   ↑ 12-20 km/h   │    (___(__)   ↑ 17-26 km/h   │    /(___(__)  ↗ 7-14 km/h    │   _ - _ - _   ↑ 9-17 km/h    │
│    /(___(__)  20 km          │     ‘ ‘ ‘ ‘   20 km          │      ‘ ‘ ‘ ‘  16 km          │  _ - _ - _ -  13 km          │
│               0.0 mm | 0%    │    ‘ ‘ ‘ ‘    0.4 mm | 83%   │     ‘ ‘ ‘ ‘   0.4 mm | 65%   │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Mon 04 Feb ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│      .-.      Light drizzle  │  _`/"".-.     Patchy rain po…│               Cloudy         │               Cloudy         │
│     (   ).    2-6 °C         │   ,\_(   ).   3-7 °C         │      .--.     1-4 °C         │      .--.     -2 °C          │
│    (___(__)   → 16-26 km/h   │    /(___(__)  → 20-27 km/h   │   .-(    ).   → 13-23 km/h   │   .-(    ).   ↗ 9-16 km/h    │
│     ‘ ‘ ‘ ‘   14 km          │      ‘ ‘ ‘ ‘  18 km          │  (___.__)__)  20 km          │  (___.__)__)  20 km          │
│    ‘ ‘ ‘ ‘    0.3 mm | 88%   │     ‘ ‘ ‘ ‘   0.3 mm | 88%   │               0.0 mm | 0%    │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Tue 05 Feb ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│    \  /       Partly cloudy  │               Overcast       │               Overcast       │      .-.      Light drizzle  │
│  _ /"".-.     -1-3 °C        │      .--.     2-6 °C         │      .--.     6 °C           │     (   ).    1 °C           │
│    \_(   ).   ↖ 19-31 km/h   │   .-(    ).   ↑ 23-33 km/h   │   .-(    ).   ↑ 24-40 km/h   │    (___(__)   ↑ 24-40 km/h   │
│    /(___(__)  20 km          │  (___.__)__)  19 km          │  (___.__)__)  8 km           │     ‘ ‘ ‘ ‘   9 km           │
│               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │    ‘ ‘ ‘ ‘    0.3 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘


After this I am shown general memory usage and disk usage (for a particular partition) along with uptime thusly:

/dev/sda2                               partition       2097148 381128  -1
/dev/sda1        84035088   77299588   2443660  97% /
 08:03:28 up 116 days, 12:36,  7 users,  load average: 1.70, 1.40, 1.26

It will close on its own after I see what needs seeing, owing to the sleep command. It saves me the clicking (required to then close the window); it just fades away or 'expires', so to speak (until the next time the mouse button gets pressed).

More in Tux Machines

Graphics: AMDGPU and X.Org Elections

  • amdgpu drm-next-5.2
  • AMDGPU Has Another Round Of Updates Ahead Of Linux 5.2
    Feature work on DRM-Next for the Linux 5.2 kernel cycle is winding down while today AMD has sent in what could be their last round of AMDGPU feature updates for this next kernel release. Building off their earlier Linux 5.2 feature work are more updates. That earlier round brought new SMU11 enablement code for Vega 20, various other Vega 20 features, HMM preparations, and other code changes.
  • 2019 Election Round 2 voting OPEN
    To all X.Org Foundation Members: The round 2 of X.Org Foundation's annual election is now open and will remain open until 23:59 UTC on 2 May 2019. Four of the eight director seats are open during this election, with the four nominees receiving the highest vote totals serving as directors for two year terms. There were six candidates nominated. For a complete list of the candidates and their personal statements, please visit the 2019 X.Org Elections page at https://www.x.org/wiki/BoardOfDirectors/Elections/2019/ The new bylaw changes were approved in the first round of voting. Here are some instructions on how to cast your vote: Login to the membership system at: https://members.x.org/ If you do not remember your password, you can click on the "lost password" button and enter your user name. An e-mail will be sent to you with your password. If you have problems with the membership system, please e-mail membership at x.org. When you login you will see an "Active Ballots" section with the "X.Org 2019 Elections Round 2" ballot. When you click on that you will be presented with a page describing the ballot. At the bottom you will find a number of dropdowns that let you rank your candidates by order of preference. For the election: There is a pull-down selection box for 1st choice, 2nd, choice, and so on. Pick your candidates top to bottom in order of preference, avoiding duplicates. After you have completed your ballot, click the "Cast vote" button. Note that once you click this button, your votes will be cast and you will not be able to make further changes, so please make sure you are satisfied with your votes before clicking the "Cast vote" button. After you click the "Vote" button, the system will verify that you have completed a valid ballot. If your ballot is invalid (e.g., you duplicated a selection or did not answer the By-laws approval question), it will return you to the previous voting page. If your ballot is valid, your votes will be recorded and the system will show you a notice that your votes were cast. Note that the election will close at 23:59 UTC on 2 May 2019. At that time, the election committee will count the votes and present the results to the current board for validation. After the current board validates the results, the election committee will present the results to the Members. Harry, on behalf of the X.Org elections committee
  • It's Time To Re-Vote Following The Botched 2019 X.Org Elections
    While there were the recent X.Org Foundation board elections, a do-over was needed as their new custom-written voting software wasn't properly recording votes... So here's now your reminder to re-vote in these X.Org elections. At least with the initial round of voting they reached a super majority and the ballot question of whether the X.Org Foundation should formally fold FreeDesktop.org into its umbrella worked and that X.Org + FreeDesktop.org hook-up passed so all is well on that front. But for the Board of Directors elections, that's where re-voting is needed with the voting software that now correctly records the votes.

today's howtos

Games: Lutris and More

  • Epic Games Store Now On Linux Thanks To Lutris
    While the Epic Games Store itself is not officially supported by the open source Linux operating system, a third-party gaming client has now made sure that you can access the store and launcher on your own distro. The Epic Games Store is now accessible on Linux via the Lutris Gaming client. The client is available to all Linux users, who in the past has provided the same users a way to play PC games without the need to have Windows installed in their machines. Although Linux is not necessarily the go-to platform when it comes to PC gaming, there is a very niche audience dedicated to making the platform work in favor of open-source and to counteract what could be perceived as a heavily Windows-biased PC gaming community. Linux gaming is somewhat tedious to the relatively casual or normal user, although there are some within the Linux community that advertise and try to foster its growth in terms of gaming, as there are some games that can run better on the operating system. That is to say, if you have a lot of patience to try and make it work.
  • You Died but a Necromancer revived you is good fun in a small package
    Sometimes, simplicity is what makes a game and in the case of You Died BaNRY that's very true. The game has little depth to it but makes up for that in just how frantic and fun it can be. The entire gameplay is just you (or you and friends) attempting to cross a small level filled with platforms, spikes and all sorts of crazy traps. It's ridiculously easy to get into as well, since the controls are so basic all you need to worry about is your movement.
  • Forager is a weirdly addictive casual grinding game that has mined into my heart
    I'm not usually one for games that have you endlessly wander around, collect resources, build a little and repeat but Forager is so ridiculously charming it's lovely.
  • DragonRuby Game Toolkit, a cross-platform way to make games with Ruby
    Now for something a little different! Ryan "Icculus" Gordon, a name known for many Linux ports and SDL2 teamed up with indie developer Amir Rajan to create a new cross-platform toolkit. Why was it created? Well, in a nutshell they both "hate the complexity of today's engines" and this toolkit was actually made to help ship A Dark Room for the Nintendo Switch, which shows how versatile it is.

10+ Open Source Software Writing Tools That Every Writer Should Know

Being a professional writer requires two key things to help ensure success: commitment and support. The former comes from the writer, and the latter comes from the tools he (or she) uses to get the job done. Below is a list of 11 great and lesser-known writing tools or apps, many of which are free and open-source, that can help improve the quality of your writing and make you a more productive and successful writer. Read more