Sunday, December 29, 2013

Useful commands and scripts (Linux, Windows, bash, etc...)

Linux

Automatically call 'ls' when the directory is changed:
sudo echo export 'PROMPT_COMMAND='\''[[ $my_currdir != $PWD ]] && ls; my_currdir=$PWD'\''' > ~/.bash_aliases


Reinstall all installed packages with a specific word: (in this case, this line reinstalls all installed packages with the word perl in it)
sudo apt-get --reinstall install $(dpkg --get-selections | grep perl | awk '{print $1}')

(this case, this line reinstalls all installed packages with the word perl in it and not perl-base)
sudo apt-get --reinstall install $(dpkg --get-selections | grep perl | grep -v perl-base | awk '{print $1}')

Update all opkg packages
for pkg in `opkg list-upgradable | cut -d' ' -f1 | grep -v Multiple`; do opkg upgrade $pkg; done


Find all files in home directory larger than a defined size
find ~ -size 20MB

Find occurences of ip address by count:
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' NCL-G2-LOG-1.txt | sort -r | uniq -c | sort -rn | head


Encrypted netcat group chat:
server: 
while true; do read -n30 ui; echo $ui |openssl enc -aes-256-cbc -a -k PaSSw; done | nc -l -p 8877 | while read so; do decoded_so=`echo "$so"| openssl enc -d -a -aes-256-cbc -k PaSSw`; echo -e "Incoming: $decoded_so"; done
client: 
while true; do read -n30 ui; echo $ui |openssl enc -aes-256-cbc -a -k PaSSw; done | nc $ipaddress 8877 | while read so; do decoded_so=`echo "$so"| openssl enc -d -a -aes-256-cbc -k PaSSw`; echo -e "Incoming: $decoded_so"; done

Centos issues:
when attempting to do an ssh-keygen as a user that is not in the sudoers file you will get a "permission denied" error because SELinux is blocking ssh-keygen. To get SELinux to accept the command without blockage, run the following:
chcon -R -t ssh_home_t ~/.ssh


Docker pull all and update all images from repositories:
docker images | awk 'NR > 1 && $1 !~ /<none>/ {print $1}' | uniq | xargs -n 1 docker pull


Mac

dd with a progress bar (requires brew and install pv):
pv -tpreb ~/Desktop/openSuse.img | sudo dd of=/dev/disk2 bs=1m


mount smb share:

mount_smbfs
or
mount -t smbfs

Windows

Flush Windows Updates cache:
net stop wuauserv
cd /d %windir%
rd /s SoftwareDistribution
net start wuauserv


Bash scripts

Auto extract compressed file (place the following in your bash_profile or bashrc file):
extract() { 
    if [ -f $1 ] ; then 
      case $1 in 
        *.tar.bz2)   tar xjf $1     ;; 
        *.tar.gz)    tar xzf $1     ;; 
        *.bz2)       bunzip2 $1     ;; 
        *.rar)       unrar e $1     ;; 
        *.gz)        gunzip $1      ;; 
        *.tar)       tar xf $1      ;; 
        *.tbz2)      tar xjf $1     ;; 
        *.tgz)       tar xzf $1     ;; 
        *.zip)       unzip $1       ;; 
        *.Z)         uncompress $1  ;; 
        *.7z)        7z x $1        ;; 
        *)     echo "'$1' cannot be extracted via extract()" ;; 
         esac 
     else 
         echo "'$1' is not a valid file" 
     fi 
}

Thursday, December 5, 2013

Windows XP Mode Crash After Domain Controller Migration

It appears that windows xp virtual pc retains some settings that cannot be removed after installation of the virtual machine itself.  When the integration features are turned on in the settings of the virtual pc (mainly network drives), the virtual machine tries to link it's previous route to the old domain controller with the new network drives which will cause the virtual pc to crash.  If you turn integration features off, the virtual will run odd with strange graphic artifacts and other nuances that shouldn't be there, but the point is that it will run.  To fix this, disable the network drives and keep the integration features turned on.  A "gpupdate /force" on the virtual pc may fix this drive issue but I have not tested it.

Tuesday, December 3, 2013

Headless Raspberry Pi media server

I had installed a raspberry pi in my old car and just played around with it.  Didn't really use it for anything spectacular except to say that i have a usb powered computer in my car.

Now I am exploring the possibility of making the pi a media server.  I have read a lot about media servers and have yet to find a decent method for multi-source music.  I am mainly talking about wifi, usb, bluetooth audio.  Mainly bluetooth streaming with MPRIS2 support for wireless phone control, stick it in a glove box or center console and forget about it.  Strange how nearly every car radio you can buy either has, or makes available to option as, a bluetooth receiver for phone calls and bluetooth streaming.  I have yet to find a linux application that combines these two elements together, as well as utilizing it as a media player.  In a nutshell, I would like to implement the ford sync system in the raspberry pi.  It doesn't have to look pretty or function the same, but it's just shocking how car audio systems are the best at being media players.

Current media players:
XBMC
Amarok
Clementine
Banshee
Volumio(Raspyfi(raspberry pi distro) replacement)
Pimusicbox (another raspberry pi distro that is actually really good)

Media/music servers/mixers:
XBMC
MPD
ALSA
pulseaudio
Mopidy (preferred)

Proposed implementation:
XBMC with a Mopidy backend for music playback with support for bluetooth, wifi, and usb audio reception.


http://www.ccoffey.ie/?p=53