<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Bandwidth on Natenoms Blog</title><link>https://natenom.de/tags/bandwidth/</link><description>Recent content in Bandwidth on Natenoms Blog</description><generator>Hugo -- gohugo.io</generator><language>de</language><copyright/><lastBuildDate>Mon, 16 May 2016 20:17:00 +0000</lastBuildDate><atom:link href="https://natenom.de/tags/bandwidth/index.xml" rel="self" type="application/rss+xml"/><item><title>Run backup script only if a specific network connection is activated</title><link>https://natenom.de/2016/05/run-backup-script-only-if-a-specific-network-connection-is-activated/</link><pubDate>Mon, 16 May 2016 20:17:00 +0000</pubDate><guid>https://natenom.de/2016/05/run-backup-script-only-if-a-specific-network-connection-is-activated/</guid><description><![CDATA[<p>I use <a  class='urlextern'  href="https://wiki.archlinux.org/index.php/NetworkManager">NetworkManager</a> to handle network connections on my laptop.</p>
<p>Once a day some backup scripts are started automatically. They need a lot of bandwidth and I don’t want them run while I use a low bandwidth mobile connection or when I am not at home.</p>]]></description><content:encoded><![CDATA[<p>I use <a  class='urlextern'  href="https://wiki.archlinux.org/index.php/NetworkManager">NetworkManager</a> to handle network connections on my laptop.</p>
<p>Once a day some backup scripts are started automatically. They need a lot of bandwidth and I don’t want them run while I use a low bandwidth mobile connection or when I am not at home.</p>
<p>To get the status of my connection named „Home (LAN)“ I use the nmcli tool:</p>
<pre>nmcli -t -f 'GENERAL.STATE' connection show "Home (LAN)"</pre>
<p>If the connection is not in use the tool returns nothing and if it is in use it returns „GENERAL.STATE:activated“.</p>
<p>Now I can insert the following line into my backup scripts somewhere before it starts the backup stuff. If my home connection is online the script is continued and if not the script exits with a text message.</p>
<pre>STATE=$(nmcli -t -f GENERAL.STATE connection show "Home (LAN)"); if [ -z $STATE ]; then echo "Not starting the backup because we are not connected to \"Home (LAN)\"."; exit 15; fi</pre>
<p>Thats it :)</p>]]></content:encoded></item></channel></rss>