I think you want to keep using managed interface (by NetworkManager). nmcli
is a commandâline tool for controlling NetworkManager.
To see list of saved connections, use (<SavedWiFiConn>
)
nmcli c
To see list of available WiFi hotspots (<WiFiSSID>
)
nmcli d wifi list
or:
sudo iwlist <WifiInterface> scanning
To see list of interfaces (<WifiInterface>
)
ifconfig -a
Just change <WifiInterface>
, <WiFiSSID>
, <WiFiPassword>
in the following commands to reflect your setup. If WiFi info already saved, easier way using <SavedWiFiConn>
name of connection as it was saved in NetworkManager.
Ubuntu 16.04
##disconnect
nmcli d disconnect <WifiInterface>
##connect
nmcli d connect <WifiInterface>
Another way:
##disconnect
nmcli c down <SavedWiFiConn>
##connect
nmcli c up <SavedWiFiConn>
Ubuntu 15.10 & previous
##disconnect
nmcli d disconnect iface <WifiInterface>
##connect
nmcli d wifi connect <WiFiSSID> password <WiFiPassword> iface <WifiInterface>
Another way:
##disconnect:
nmcli c down id <SavedWiFiConn>
##connect:
nmcli c up id <SavedWiFiConn>
If your password isn't automatically recognized type this:
nmcli -a c up <SavedWiFiConn>
Reference: man nmcli
Introduction
While it's not possible to log all GUI actions, such things as logging commands that correspond to open windows can be done. Below is the simple python script that does the job. It's still in development, but does 90% of the required task.
Source code
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk,Gtk
import time
import os
import subprocess
def run_cmd(cmdlist):
""" Reusable function for running external commands """
new_env = dict(os.environ)
new_env['LC_ALL'] = 'C'
try:
stdout = subprocess.check_output(cmdlist, env=new_env)
except subprocess.CalledProcessError:
pass
else:
if stdout:
return stdout
def print_info(stack,event):
base_xprop = ['xprop','-notype']
for xid in stack:
pid = None
check_pid = run_cmd(base_xprop + [ '_NET_WM_PID', '-id',str(xid)])
if check_pid:
pid = check_pid.decode().split('=')[1].strip()
with open('/proc/'+pid+'/cmdline') as fd:
command = fd.read()
print(time.strftime("%D %H:%M:%S" + " "*3) + event + pid + " " + command)
def main():
sc = Gdk.Screen.get_default()
old_stack = None
while True:
stack = [ win.get_xid() for win in sc.get_window_stack() ]
if old_stack:
# Difference between current and old stack will show new programs
diff = set(stack) - set(old_stack)
if diff:
print_info(diff," 'New window open' ")
else:
print_info(stack," 'Script Started' ")
old_stack = stack
time.sleep(2)
if __name__ == '__main__': main()
Test run:
$ ./log_open_windows.py
01/25/17 15:33:13 'Script Started' 2915 nautilus-n
01/25/17 15:33:13 'Script Started' 3408 /opt/google/chrome/chrome
01/25/17 15:33:13 'Script Started' 12540 /usr/bin/python/usr/bin/x-terminal-emulator
01/25/17 15:33:13 'Script Started' 2454 compiz
01/25/17 15:33:13 'Script Started' 2454 compiz
01/25/17 15:33:13 'Script Started' 2454 compiz
01/25/17 15:33:13 'Script Started' 2454 compiz
01/25/17 15:33:13 'Script Started' 2454 compiz
01/25/17 15:33:21 'New window open' 15143 /usr/lib/firefox/firefox-new-window
01/25/17 15:33:27 'New window open' 15196 unity-control-center
The script shows timestamp, event type, the window PID, and the corresponding command.
How to use
The standard rules of any script apply. Make sure you store the script in ~/bin
directory. If you don't have ~/bin
directory , then create one. Save script file there and ensure it is executable with chmod +x ~/bin/log_open_windows.py
. After than you can run it from command line at any time you wish by calling ~/log_open_windows.py
in command-line.
Best Answer
A combination of
wmctrl
andxprop
offers many possibilities.Example 1:
The output could look in this case similar like this:
Example 2:
Output example:
You can add the function to your
~/.bashrc
or run it from an script file.