Network Monitor Applet for Cinnamon with Bars

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
christosangelopoulos
Level 3
Level 3
Posts: 152
Joined: Fri Nov 13, 2020 10:19 pm

Network Monitor Applet for Cinnamon with Bars

Post by christosangelopoulos »

The following script in bash, is a cinnamon panel applet for Linux Mint, that provides network monitoring (upload download speed , and bars).

1.Copy the following code

2.Paste it to an empty file

3.Save it in whichever directory you like as network.sh

4.Make this file executable with the following command in terminal(open the terminal in the same directory):

chmod +x network.sh

5.Then make sure you download the CommandRunner Applet in cinnamon panel:

Right click on the panel you want to present the network monitor
Select Applets
Select Download tab, select CommandRunner and download it
Back on the Manage tab, press the CommandRunner Configure button.
In the Command field, put : /directory/of/network.sh
In the Run Interval field, put: 1 second
Hit Apply
6.You are good to go.

Code: Select all

#! /bin/bash
#  _   _          _                               _    
# | \ | |   ___  | |_  __      __   ___    _ __  | | __
# |  \| |  / _ \ | __| \ \ /\ / /  / _ \  | '__| | |/ /
# | |\  | |  __/ | |_   \ V  V /  | (_) | | |    |   < 
# |_| \_|  \___|  \__|   \_/\_/    \___/  |_|    |_|\_\
#   written by Christos Angelopoulos
NET="$(ifstat -SAnq 0.2 1)"
INTERFACE="$(echo "$NET"|head -1|sed 's/      / /')"
UP="$(echo "$NET" | tail -1|awk '{print $3}'|sed 's/\..*$//')"
DOWN="$(echo "$NET" | tail -1|awk '{print $2}'|sed 's/\..*$//')"
BUP=$(( $UP/12 ))
BDOWN=$(( $DOWN/80 ))
if [ $BDOWN -gt 9 ];then BDOWN=9;fi
if [ $BUP -gt 9 ];then BUP=9;fi
mes1="∇ "$(echo "$DOWN")" kB "
mes3="∆ "$(echo "$UP")" kB "

#loop to decide which download levels are on 
i=0
while [ $i -lt 9 ]
do
 if [ $i -lt $BDOWN ]
 then
 	BAR_0_[$i]="███████_"
 else
 	BAR_0_[$i]="        "	
	fi
	((i++))
done
#loop to decide which upload levels are on 
i=0
while [ $i -lt 9 ]
do
 if [ $i -lt $BUP ]
 then
 	BAR_1_[$i]="_███████"
 else
 	BAR_1_[$i]="        "	
	fi
	((i++))
done


xml=`cat <<EOF
<xml>
<appsettings>
<tooltip>     Interface :$INTERFACE
Download : $DOWN kB/s
Upload :      $UP kB/s</tooltip>
<clickaction>cinnamon-settings network</clickaction>
</appsettings>
<item>
<type>box</type>
<attr>
<vertical>1</vertical>
</attr>

			<item>
			<type>box</type>
			<attr>
			<vertical>0</vertical>
			<xalign>0</xalign>
			</attr>	
			
					<item>
					<type>box</type>
					<attr>
					<vertical>1</vertical>
					<xalign>0</xalign>
					</attr>	
						
								<item>
								<type>text</type>
								<value>$mes1</value> 
								<attr><xalign>0</xalign><style>padding: 0px;font-size: 9pt;font-weight: bold;color:orange</style></attr>
								</item>

								<item>
								<type>text</type>
								<value>$mes3</value> 
								<attr><xalign>0</xalign><style>padding: 0px;font-size: 9pt;font-weight: bold;color:rgb(95,215,175)</style></attr>
								</item>
					</item>
	
						</item>
					<item>
					<type>text</type>
					<value>XXXXXXXXXXXXXXXXΧΧΧXXXXXXXXX</value> 
					<attr><xalign>0</xalign><yalign>2</yalign><style>font-size: 2pt;color:rgb(88,88,88)</style></attr>
					</item>    		  
</item>
					<item>
					<type>box</type>
					<attr>
					<vertical>1</vertical>
					<xalign>0</xalign>
					<yalign>0</yalign>					
					<style>padding: 0px</style>
					</attr>	
					
						<item>
								<type>text</type>
								<value>${BAR_0_[9]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>
						<item>
								<type>text</type>
								<value>${BAR_0_[8]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_0_[7]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_0_[6]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_0_[5]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_0_[4]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_0_[3]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_0_[2]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_0_[1]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>
					<item>
								<type>text</type>
								<value>${BAR_0_[0]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>						
						<item>
								<type>text</type>
								<value>███████_</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:orange;padding: 0px</style></attr>
						</item>						

					</item>
					<item>
					<type>box</type>
					<attr>
					<vertical>1</vertical>
					<xalign>0</xalign>
					<yalign>2</yalign>					
					<style>padding: 0px</style>
					</attr>	
					
						<item>
								<type>text</type>
								<value>${BAR_1_[9]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>
						<item>
								<type>text</type>
								<value>${BAR_1_[8]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_1_[7]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_1_[6]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_1_[5]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_1_[4]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_1_[3]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_1_[2]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>
												<item>
								<type>text</type>
								<value>${BAR_1_[1]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>
						<item>
					<item>
								<type>text</type>
								<value>${BAR_1_[0]}</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>						
								<type>text</type>
								<value>_███████</value> 
								<attr><xalign>0</xalign><style>font-size: 1pt;font-weight: bold;color:rgb(95,215,175);padding: 0px</style></attr>
						</item>						

					</item>

</xml>

EOF
`
echo "$xml"



Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
christosangelopoulos
Level 3
Level 3
Posts: 152
Joined: Fri Nov 13, 2020 10:19 pm

Re: Network Monitor Applet for Cinnamon with Bars

Post by christosangelopoulos »

Here is an updated version of this script, presented with instructions, & screenshots:

https://gitlab.com/christosangel/networ ... -with-bars
Locked

Return to “Scripts & Bash”