terça-feira, maio 10, 2016

How To : Use wpa_cli To Connect To A Wireless Network using terminal manually

How To : Use wpa_cli To Connect To A Wireless Network – The Rantings and Ravings of a Madman





debian wpa_cli how-to



To connect manually, you need to first start up wpa_cli. This assumes that wpa_supplicant is already running, which it should be in most cases. If it’s not, you will see an error when you start wpa_cli.
Otherwise, once you’re in wpa_cli, it will show a prompt similar to this

Selected interface 'wlan0'
Interactive mode
>
Using the scan and scan_results command, you can scan for the networks and see some basic information

> scan
OK
<2>CTRL-EVENT-SCAN-RESULTS
> scan_results
bssid / frequency / signal level / flags / ssid
00:55:ab:25:ac:5a 2462 -71 [WPA2-PSK-CCMP][ESS] WLAN-Network
00:11:99:51:ba:f0 2437 -64 [WPA2-PSK-CCMP][ESS] WLAN-Network2
>
In the above scan results, you can see the 2 networks that the computer can pick up, the frequencies / channel that they are broadcasting on, the signal strength, the security type, and network name. Both of these networks are using WPA2 with a Pre-Shared Key.
To connect to one of them, we need to first create a network.

> add_network

This will output a number, which is the network ID.

> add_network
0
This will create an empty network ready for us to configure it.
Next up, we need to set the SSID and PSK for the network.

> set_network 0 ssid "WLAN-Network"
> set_network 0 psk "SupahSecretPassphrase"
> enable_network 0

sábado, maio 07, 2016

Guide: Removing desktop of raspbian to run headless

Guide: Removing desktop to run headless (Raspbian Jessie 2015-09-24): raspberry_pi



raspbian remove gui



Guide: Removing desktop to run headless (Raspbian Jessie 2015-09-24) (self.raspberry_pi)



  1. Start out with entering: sudo raspi-config into the terminal. Once you get into the menu select boot options and make the pi boot to console. Optionally you can overclock Then: sudo reboot now
  2. When it's back up run: sudo apt-get remove --auto-remove --purge libx11-.* this will remove all the packages that start with lx.
  3. Remove some rather large packages with: sudo apt-get remove --purge wolfram-engine libreoffice libreoffice was added to the Jessie release, since we're running headless we don't need this.
  4. Run: sudo apt-get autoremove to clear out the rest of the packages we no longer require.
  5. Run: sudo apt-get update && sudo apt-get upgrade
  6. Reboot and finish setting up your headless pi
    Note: I wrote this guide not 5 minutes after I did this to my pi. So I am open to criticism and optimizations. If anyone would like an image I could pull one off of the SD card on request. I did this on the original raspberry pi B with 256mb of ram. Someone correct me if I'm wrong but this should work across all versions.

quarta-feira, maio 04, 2016

How to view the output of a running process in another bash session

How to view the output of a running process in another bash session? - Unix & Linux Stack Exchange



How to view the output of a running process in another bash session?


capture pts output


ps -ef |grep sshd
grep whatever process you want to attach








strace -e write=1,2 -e trace=write -p xxxx


Here is more complete example:
strace -e trace=write -s1000 -fp 18386 2>&1 \
| grep --line-buffered -o '".\+[^"]"' \
| grep --line-buffered -o '[^"]\+[^"]' \
| while read -r line; do
  printf "%b" $line;
done

To avoid that, lets simplify the whole process, so lets define the following formatter alias:
alias format-strace='grep --line-buffered -o '\''".\+[^"]"'\'' | grep --line-buffered -o '\''[^"]*[^"]'\'' | while read -r line; do printf "%b" $line; done | tr "\r\n" "\275\276" | tr -d "[:cntrl:]" | tr "\275\276" "\r\n"'
where:
  • grep -o '".\+[^"]"' - select double-quoted string with quotes
  • grep -o '[^"]*[^"]' - select text within the double quotes
  • while read -r line - store each line into $line and do some action (help read)
  • printf "%b" $line - print line by expanding backslash escape sequences
  • tr "\r\n" "\275\276" - temporarily replace \r\n into \200\201
  • tr -d "[:cntrl:]" - remove all control characters
  • tr "\275\276" "\r\n" - restore new line endings
then the complete example to trace some command (e.g. php) can look like:
strace -e trace=read,write,recvfrom,sendto -s 1000 -fp $(pgrep -n php) 2>&1 | format-strace