-
-
Save rbottomley/61983d08d674f903b45126df1bec8a28 to your computer and use it in GitHub Desktop.
Simplify nmcli usage to control wifi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Control wifi. Since I can never remember the arguments to nmcli, I made | |
# this command to simplify usage. | |
# | |
# Written by Robert Bottomley | |
# | |
# $Id: wifi,v 1.4 2021/05/20 18:05:55 bob Exp $ | |
# | |
# $Log: wifi,v $ | |
# Revision 1.4 2021/05/20 18:05:55 bob | |
# Display help on invalid option. | |
# | |
# Revision 1.3 2021/05/20 18:01:24 bob | |
# Add more options beyond just on and off. | |
# | |
# Revision 1.2 2020/05/21 15:22:10 bob | |
# *** empty log message *** | |
# | |
# | |
NMCLI=/usr/bin/nmcli | |
HELPMSG="USAGE: wifi on | off | status | list | rescan | connect <SSID>" | |
if [ $# -lt 1 ] ; then | |
echo $HELPMSG | |
exit 1 | |
fi | |
case $1 in | |
on | off) | |
$NMCLI radio wifi $1 | |
if [ $? = 1 ] ; then | |
echo "Error: Unable to control radio." | |
exit 1 | |
fi | |
;; | |
status) | |
echo "Wifi radio `$NMCLI radio wifi`" | |
$NMCLI connection show --active | |
;; | |
list | rescan) | |
$NMCLI device wifi $1 | |
;; | |
connect) | |
if [ $# -lt 2 ] ; then | |
echo "Missing SSID" | |
exit 1 | |
fi | |
$NMCLI device wifi connect $2 --ask | |
;; | |
*) | |
echo "Invalid option '$1'" | |
echo $HELPMSG | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment