Which exact one-line conditional construct activates an existing Internet connection if it's off and deactivate it if it's on?
I looked some on-line pages to understand the use of
- the "nmcli" command
- the "if then else fi" construct
- command substition, i.e. the use of "$(command_name)" function to get the output of a command
- the "grep" command to manage the nmcli command output
The final construct should be of this kind:
if ( nmcli MyConnection status = down ); then nmcli c up id "MyConnection"; else nmcli c down id "MyConnection"; fi
Note: the if condition is not real code and should be elaborated.
But I didn't find an option for the nmcli command to test if a connection is up or down. I thought of using the "status" option, i.e.: "nmcli c status id "MyConnection"", but while nmcli gives a grep-parsable output message when "MyConnection" is up, it returns an error and doesn't exit to the command line when "MyConnection" is down (the cursor in the terminal window stays there and a CTRL+C is needed to get the shell prompt back).
I need some help to arrange these things into a complete one-line script usable in the
System Settings > Keyboard > Shortcuts > Custom Shortcuts
Thank you very much.
P.S.: This question follows what learned here some time ago: How to set a keyboard shortcut to activate an existing Internet connection?
SO is Ubuntu 13.04, Internet connection type is Mobile broadband