Friday, October 25, 2013

Spectacle OSX Mavericks fail


Did you upgrade to OSX Mavericks only to find Spectacle failing and no "Enable access for assistive devices" option available?

Me too.

Go to your Systems Preferences, go to Security and Privacy, go to Privacy, then Accessibility, and finally check-mark Spectacle (You may need to click the Lock at the bottom left corner first).



----------

Thursday, October 17, 2013

Batch file: For each live computer in a domain, do something



Need a batch file to perform an action, executable, or script for online domain members only?

Here, for simplicity, our do-something is "echo computer-name is online":

Save the following to a batch file: (two % signs are needed in batch files, one % if at the command-prompt)


@echo off

dsquery * domainroot -filter "(&(objectCategory=Computer))" -limit 0 -attr cn > computers.txt

for /f %%i in (computers.txt) do (
   ping -n 1 -w 500 %%i | find "Lost = 0">NUL && echo %%i is online || echo %%i is offline
)

del computers.txt


This can easily be changed to work on a specific OU and skip sub-OU's (-scope onelevel):

dsquery * "OU=EXAMPLE_OU,DC=EXAMPLE,DC=COM" -filter "(&(objectCategory=Computer))" -limit 0 -attr cn -scope onelevel > computers.txt

So your do-something could be powerful when combined with commands like:
psexec.exe \\%%i some-command
or
START /B some-batch-calling-psexec.bat

You could get fancy and do multiple things by enclosing them in ( ) but separating them with &:
( echo %%i online & script.bat %%i)


So here is an example batch file that runs "gpudate /target:computer /force" on the Computers OU and it's sub OU's (This assumes you are logged in with administrative privileges):

@echo off
setlocal enableextensions enabledelayedexpansion

dsquery * "OU=Computers,DC=EXAMPLE,DC=COM" -filter "(&(objectCategory=Computer))" -limit 0 -attr cn > computers.txt

for /f %%i in (computers.txt) do (
ping -n 1 -w 500 %%i | find "Lost = 0">NUL && ( echo !time! %%i ONline, Launching... & START /B psexec.exe \\%%i -e -d -s -low gpupdate /target:computer /force ) || echo !time! %%i OFFline
)

del computers.txt
echo.

--------------

Saturday, August 24, 2013

Diskfree Watcher script for Linux (Walkthough)

Problem: VMWare does not report Guest OS freespace, and as such there are no alarms triggered and emailed.

Solution: For Linux, script hourly "df" testing within the OS.

We will script the use of “df” to watch disk free space and perform sendmail if the usage is greater-than or equal-to a specified percentage.


Prerequisite: “df”, “sendmail”, “grep”, “awk”, “cut” -- please install them if not installed.
Prerequisite: You will need a valid mail-relay target or mail server target.

Assuming root account.


note: You will alter the script for your specific “df” output.
note: Your drive device will have to be determined manually.
note: “sendmail” my be in some other path than “/usr/sbin”
note: This was all performed on CentOS, a RedHat clone.  Other distributions may be slightly different.


Let’s first run the “df -h” command (diskfree -human_readable)


In my case, this is:
df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_netflow-lv_root
                      90G   64G   22G  75% /
tmpfs                 939M     0  939M   0% /dev/shm
/dev/sda1             485M  115M  346M  25% /boot
/dev/mapper/vg_netflow-lv_home
                     4.9G  160M  4.5G   4% /home


So I have a choice, I can use “df” against any of the listed file-systems. Each one has a Mount point (alias)


I’m interested in my root drive, so I’ll choose “df -h /dev/mapper/vg_netflow-lv_root”.  I could have as easily chose “df -h /” which would be the same in this case.
df -h /dev/mapper/vg_netflow-lv_root
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_netflow-lv_root
                      90G   64G   22G  75% /


Now what I’m interested in is the Use% (75% here).  I can “grep” for “% /” so that only that specific line is printed.
df -h /dev/mapper/vg_netflow-lv_root | grep "\% \/"
produces
                      90G   64G   22G  75% /


Now I’m still only interested in the 75%, which is the 4th item.  Let’s “awk” that.
df -h /dev/mapper/vg_netflow-lv_root | grep "\% \/" | awk '{ print $4 }'
75%


Now I only see 75%.  But I can’t ‘If-Then’ a number containing the %-sign, so I’ll “cut” it.
df -h /dev/mapper/vg_netflow-lv_root | grep "\% \/" | awk '{ print $4 }' | cut -d% -f1
75


This is the result I want to perform an action on -- so now a script can be written.  Here is mine:
cat /root/scripts/diskwatch.sh
#!/bin/sh
used=`df -h /dev/mapper/vg_netflow-lv_root | grep "\% \/" | awk '{ print $4 }' | cut -d% -f1`
echo "diskspace used: $used%";
if [ $used -ge 93 ] ;
then
/usr/sbin/sendmail "myaccount@mydomain.com" << EOF
From: root@netflow.mydomain.com
To: me@mydomain.com
Subject: Alert: netflow diskspace $used% used.
netflow diskspace $used% used.
EOF
fi


This script prints the usage to screen and also sends mail if the usage if greater-than_or_equal-to 93%.


Note the “used”-variable assignment -- The command is single-back-quoted.  The ` character on the ~ (tilde) key.
Change the trigger-limit (93 here) as you see fit. And also, all your email information as it pertains to you and your server.  Make sure to mark your script executable, in my case
chmod +x /root/scripts/diskwatch.sh


You will need to configure your OS for sendmail.  As, stated above, you will need a valid email server or relay target.  This write-up does not go into such.


Now configure sendmail, In my case, I used postfix sendmail, so I added
relayhost = mail.mydomain.com
to the file “/etc/postfix/main.cf” then restarted the postfix service
service postfix restart


You should test sendmail by typing the part of the script between “then” and “fi” directly in the command-line.


If it works, you are ready to cron-job the script.
crontab -e
add
0 * * * * /root/scripts/diskwatch.sh
for hourly execution.

Good Luck!
-----------------

Thursday, July 4, 2013

Duck Duck Go

uninstall a surprise gnome install from your debian testing xfce desktop.


2013-07-04

I boot up my Debian Testing XFCE machine, login to a slow startup and surprise it's F'ing gnome 3 shell.

WTF?!?!?!  This is not what I had in mind for 4th of July fireworks.  I hate this bullshit!  Seriously, Debian testing just installed gnome without my authority!??!?! (Granted, yes i know nothing happens without authority -- updates suck sometimes)

sudo aptitude purge gnome-applets gnome-session-fallback gnome-control-center-data gnome-control-center gnome-media gnome-online-accounts gnome-bluetooth gnome-panel-data gnome-panel mousetweaks gnome-panel gnome-session gnome-shell  ; sudo reboot


ahhhh much better!!!!


but now i'm aggravated...

sudo shutdown -h now

walking away...
------------------




Wednesday, June 19, 2013

run commands against AD domain members via flexcommand.hta


Execute commands against AD Domain Members via web-interface.

Thanks to the article How to Force Remote Group Policy Processing, I found "flexcommand.hta" compliments of Mr. Jakob H. Heidelberg of Copenhagen, Denmark.

First, I've repaired the original for use on Windows7 and 2008 as per Mr. Eirik Andreassen's comment.

I've also edited the original to allow for larger fields including the OU dropdown box and enabled the "sub-OU's" and "alive-only" options by default. 

Download the full flexcommand.hta here or the diff patch to compare.  It has to be run with domain admin privileges and without UAC.


Here are some useful example psexec commands:

psexec.exe \\{C} -e -h -d gpupdate.exe /force

psexec.exe \\{C} -e -h -d wuauclt.exe /reportnow

psexec.exe \\{C} -e -h -d \\example.com\netlogon\WUInstall.exe /install /criteria "IsHidden=0 and IsInstalled=0 and IsAssigned=1"
(depends on WUInstall on accessible share)

Enjoy.
-----------------

Thursday, May 30, 2013

Install nfsight plugin for nfsen on CentOS 6


Install nfsight plugin for nfsen netflow/sflow collector/analyser on CentOS 6 (and probably RedHat 6)

This was done with nfsen 1.3.6p1 and nfdump 1.6.6 -- i have not yet upgraded to any newer versions which may may be different.

This was one of the most difficult installations I've done to date.  I had attempted to do so at least twice if not thrice without success.  The key was to know about the chgrp command which I had not used before.  Also mysql was not something I was overly familiar with.  I attempted this task knowing I had failed in the past, but I also knew I had gained more Linux experience since those attempts.  I was very excited to succeed this time.

Here are my notes, because quite frankly I have not found any hints online other than the official installation guide which is bare minimum.

Please comment, especially if you find errors or know better solutions.  Enjoy.

Edit: newer nfsight version available: nfsight-beta-20140905.tgz ; just replace references.

######################################################
### Install nfsight plugin for nfsen on CentOS 6.4 ###
### http://sourceforge.net/p/nfsight/home/Nfsight/ ###
### Prerequisite: nfsen/nfdump already operational ###
######################################################

#################################################################
### Your nfsen and webserver directories may indeed be different.
### Apply settings as they pertain to your directory structure.
###
### My server's configuration:
### nfsen installed to /usr/local/nfsen
### nfsen website installed to /var/www/html/nfsen
### website owner=root, group=apache
###
### All commands performed as root.
#################################################################

### install prerequisites
yum install mysql mysql-server perl-DBI perl-DBD-MySQL php-mysql

### download and untar nfsight v.20130323
cd ~
wget http://sourceforge.net/projects/nfsight/files/nfsight-beta-20130323.tgz/download
tar xvfz nfsight-beta-20130323.tgz
cd ~/nfsight-beta-20130323

### following http://sourceforge.net/p/nfsight/wiki/Installation/

### copy nfsight.pm to plugins directory
cp ~/nfsight-beta-20130323/backend/nfsight.pm /usr/local/nfsen/plugins/

### make nfsight data directory and set rights
mkdir /var/www/html/nfsen/plugins/nfsight
chgrp -R apache /var/www/html/nfsen/plugins/nfsight

### make nfsight website directory
mkdir /var/www/html/nfsen/nfsight

### copy frontend to nfsight website directory
cp -R ~/nfsight-beta-20130323/frontend/* /var/www/html/nfsen/nfsight/

### set rights to nfsight website
chgrp -R apache /var/www/html/nfsen/nfsight/

### unsure if necessary - set write permissions for apache
chmod g+w /var/www/html/nfsen/nfsight/
chmod g+w /var/www/html/nfsen/plugins/nfsight
### if nothing else apache must write config.php
### touch /var/www/html/nfsen/nfsight/config.php
### chmod g+w /var/www/html/nfsen/nfsight/config.php

### install mysql service and start it 
yum install chkconfig 
chkconfig mysqld on
service mysqld start

### first time setup of mysql
/usr/bin/mysql_secure_installation


#################################################################
### create nfsight database -- probably overkill but this worked
#################################################################
mysql -u root -p 
Enter password: 

mysql> CREATE DATABASE nfsight

mysql> GRANT ALL PRIVILEGES ON nfsight.* TO root@'%' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on nfsight.* TO root@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON nfsight.* TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

#################################################################
### launch http://yourserver/nfsight/installer.php
### 
### setup as you desire including proper paths:
### URL = /nfsight/
### Path to data files = /var/www/html/nfsen/plugins/nfsight
#################################################################

#################################################################
### settings can be edited later without installer.php: 
### nano /var/www/html/nfsen/nfsight/config.php
### nano /var/www/html/nfsen/nfsight/detail.php
#################################################################

#################################################################
### edit detail.php to include proper paths:
### /bin/grep
### /bin/cat
### /usr/bin/pcv
#################################################################
nano /var/www/html/nfsen/nfsight/detail.php


#################################################################
### edit /usr/local/nfsen/etc/nfsen.conf
### add settings as output by installer.php
### 
### your setting may vary:
#################################################################
@plugins = (
[ '*', 'nfsight' ],
);

%PluginConf = (\
nfsight => {
            path => "/var/www/html/nfsen/plugins/nfsight",
                expiration => "180",
                processing_timer => "",
                network => {
                        "10.0.0.0" => "8",
                },
                scanner_limit => "5",
                bidirectional_via_nfdump => "",
                print_int_scanner => "1",
                print_ext_scanner => "1",
                print_int_client => "0",
                print_ext_client => "0",
                print_int_server => "1",
                print_ext_server => "0",
                print_int_invalid => "0",
                print_ext_invalid => "0",
                sql_host => "localhost",
                sql_port => "3306",
                sql_user => "root",
                sql_pass => "password",
                sql_db => "nfsight",
        },

);
#################################################################

### restart nfsen
/usr/local/nfsen/bin/nfsen stop
/usr/local/nfsen/bin/nfsen start
/usr/local/nfsen/bin/nfsen status

### edit cron jobs as decribed from installer.php
crontab -e
06 * * * *  /usr/bin/wget --no-check-certificate -q -O - http://management:aggregate@127.0.0.1/nfsight/aggregate.php


#################################################################
### optional: install picviz
#################################################################
### picviz 0.6-8 has only one dependency issue in CentOS 6.4
### picviz 0.6-8 requires libev available in the EPEL repository
### What is EPEL?: https://fedoraproject.org/wiki/EPEL
#################################################################

### Install the EPEL repository 
### This is the 64-bit version, you may need to locate the 32-bit version
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

### install picviz prerequisite libev from EPEL
yum install libev

### install picviz 0.6-8 64-bit
wget https://depots.global-sp.net/CentOS/6/x86_64/picviz-0.6-8.el6.x86_64.rpm
rpm -i picviz-0.6-8.el6.x86_64.rpm 
wget https://depots.global-sp.net/CentOS/6/x86_64/picviz-plugin-pngcairo-0.6-8.el6.x86_64.rpm
rpm -i picviz-plugin-pngcairo-0.6-8.el6.x86_64.rpm 

### fix errors decribed by nfsight regarding picviz
chmod g+w /var/www/html/nfsen/nfsight/cache
chmod g+x /var/www/html/nfsen/nfsight/bin/biflow2picviz.pl

---------------

Monday, May 27, 2013

Wifey does it best

NOT COMPUTING, NOT LINUX, NOT TECHNOLOGY, BUT DAMNED DELICIOUS!

This is what "Wifey" does.... She's not a technology geek; she's a scientist in the kitchen; she's a cupcake geek.... enjoy!

Friday, May 17, 2013

psexec via linux

I often use sysinternals'  psexec during my windows management routines; however, i'd often wish i could do such from my linux desktop rather than my windows vm.  Thanks to an updated "winexe" hosted at http://sourceforge.net/p/winexe/wiki/Home/ "psexec in linux" is possible.

In your debian, or ubuntu based distro add the following repository to /etc/apt/sources.list :
deb http://repo.openpcf.org/repository/ext/openpcf/ubuntu/ precise main

Then add the repo's public key and update/install: (As of this writing, it is version 1.00 and they are developing v1.1)
wget http://repo.openpcf.org/repository/ext/openpcf/openpcf.org-repo-public-key-C6E91526.asc
sudo apt-key add ./openpcf.org-repo-public-key-C6E91526.asc
sudo apt-get update
sudo apt-get install winexe

As with the windows utility psexec.exe, the target must be configured appropriately.  Specifically read the following if necessary:
1) http://forum.sysinternals.com/psexec-could-not-start_topic3698_post11962.html#11962
2) http://jamesrayanderson.blogspot.com/2010/04/psexec-and-ports.html

Lets test it by listing processes on the target:
winexe -U USERNAME //HOSTNAMEorIP "tasklist"

The utility should ask for the password and display results:
Password for [WORKGROUP\USERNAME]:

Image Name                   PID Session Name     Session#    Mem Usage
========================= ====== ================ ======== ============
System Idle Process            0 Console                 0         28 K
System                         4 Console                 0         72 K
smss.exe                     712 Console                 0        268 K
csrss.exe                    800 Console                 0      1,488 K
winlogon.exe                 824 Console                 0      4,892 K
services.exe                 868 Console                 0      2,228 K
lsass.exe                    880 Console                 0      1,876 K
vmacthlp.exe                1084 Console                 0        152 K
svchost.exe                 1100 Console                 0      2,328 K
PresentationFontCache.exe   1168 Console                 0      1,024 K
svchost.exe                 1196 Console                 0      1,676 K
svchost.exe                 1320 Console                 0     32,768 K
svchost.exe                 1412 Console                 0      2,576 K
svchost.exe                 1436 Console                 0        368 K
svchost.exe                 1508 Console                 0      1,440 K
svchost.exe                 1568 Console                 0      1,368 K
svchost.exe                 1912 Console                 0        272 K
alg.exe                     1956 Console                 0        280 K
svchost.exe                  584 Console                 0        384 K
ramaint.exe                 1296 Console                 0        424 K
SntpClient.exe              2796 Console                 0      1,416 K
dllhost.exe                 2892 Console                 0        360 K
vmtoolsd.exe                3260 Console                 0      2,708 K
vmware-usbarbitrator.exe    3368 Console                 0        388 K
vssvc.exe                   3436 Console                 0        188 K
SDUpdSvc.exe                3488 Console                 0        800 K
dllhost.exe                 2472 Console                 0      1,040 K
logon.scr                   4080 Console                 0        252 K
csrss.exe                   4024                         1      2,340 K
winlogon.exe                 404                         1      5,684 K
[etc]

When running programs that take parameters, remember to use quotes.
Lets test this by running a ping-to-self on the target.  Execute the utility including quotation marks:
winexe -U USERNAME //HOSTNAMEorIP "ping -n 1 127.0.0.1"

The above produces:
Password for [WORKGROUP\USERNAME]:

Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms ttl=128
Ping statistics for 127.0.0.1:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

For domain accounts, i've found that you need to escape your domain username in this fashion: (notice the double-slashed username )
winexe -U DOMAIN\\username //HOSTNAMEorIP "commandline"

Be warned though, as also true with psexec, your password may be passed as plain text over the network.
-----------

Thursday, May 16, 2013

setting xdg-mime defaults

Often in Linux a mime-type has the wrong application associated with it. Here i will share a short script I found hiding online (thanks to "aleb") that will assist in both finding your options and setting your defaults.

Please read http://budts.be/weblog/2011/07/xdf-open-vs-exo-open first.

If you've read the link you understand xdg-open should work on any Desktop Environment. You may however wish to alter this article for your specific D.E.

First is a script that will display every app option for every mime-type on your system.
#!/bin/sh
for dd in /usr/share/applications ~/.local/share/applications; do
 for d in $(ls $dd 2>/dev/null | grep "\\.desktop$" 2>/dev/null); do
  for m in $(grep MimeType $dd/$d | cut -d= -f2 | tr ";" " "); do
   echo xdg-mime default $d $m;
  done;
 done;
done;

To use this copy paste into a file named mimetypes.sh, then make it executable with chmod +x mimetypes.sh

Now run it: ./mimetypes.sh

You will of course see all options.

Suppose you only want to see video mime-types. Try: ./mimetypes | grep video

(Just ignore any output that begins with "grep:", the usefull ones are only the ones that begin with "xdg-mime".)

Now suppose you have vlc installed and it is the only video player you want as a default. Highlight all the lines that contain vlc (the whole code block) from your results and paste them into the bash prompt. Voila, vlc is now your default player for all video mime-types.

Suppose you have firefox and you like it best. But for whatever reason chromium is still the default when launching links or html files.

Try: ./mimetypes.sh | grep html | grep firefox

you should see something like:
xdg-mime default firefox.desktop text/html
xdg-mime default firefox.desktop application/xhtml+xml


Copy those two lines and paste into your bash shell. Now Firefox should be your default.

--------

Sunday, April 14, 2013

Holy X11 Batman (RDP via ssh X11Forwarding from an OSX host over VPN -- it's true!)

Can it be true??? YES it IS... with a caveat I hope you solve for me...
The caveat is with a Linux client; I've verified OSX to OSX has no issue.

Scenario: I wanted to ssh into my Mac Pro at work from my Linux box at home and launch RDP via X11Forwarding.  Of course, from-Linux to-Linux is a non-issue, but in this case my host is OSX.  I got to playing, and the surprise was joyous.


Setup/Prerequisites:
 Client: Linux or OSX
 Host: OSX 10.8
 VPN: Hamachi (Hamachi for Linux in Labs)
 RDP Client: FreeRDP via OSX HomeBrew
 X11: XQuartz will be required for both OSX Hosts and OSX Clients.  Of course X11 is already part of any Linux Desktop Environment.
 Host firewall's ssh port 22 open for NIC "ham0"


Assumptions/Prerequisites:
 Let's assume you've installed XQuarts on the OSX host already.
 Let's assume you have Hamachi fully operational on both machines. (i.e. hamachi logged in, VPN created, joined on both machines, firewall open for ham0) -- ("hamachi list" to see your IP's, "hamachi -h" for other options).
 Let's assume you've installed Homebrew on the host already. (or you can do it while ssh'd in).

We will do this remotely through the hamachi VPN.

From your linux client, ssh into your OSX host: (If on an OSX client, XQuartz's xterm is necessary)
 ssh -XC user@hostIP #(-X is for X11 forwarding, -C is for compression)

Edit the ssh server config:
 sudo nano /etc/sshd_config
Adding the following 3 lines to the end of the config file:
 AddressFamily inet #(required when IPv6 is disabled on any client or host)
 X11Forwarding yes
 X11DisplayOffset 10

Restart the sshd service:
 ps -ef | grep sshd | awk {'print $2'} | sudo xargs kill -HUP
 
This will have disconnected you, so ssh in again:
 ssh -XC user@hostIP

Let's install FreeRDP:
 brew install freerdp

Setup the display for the X11Forward:
 export DISPLAY=localhost:10.0

Now run xfreerdp:
 xfreerdp serverIP #(where serverIP is a legitimate internal network IP)
 #OR
 xfreerdp -u username -d domain serverIP  #(where -d domain is only needed for Active Directory members)

Proof:

Caveat:
  I've found a significant issue strictly when on Linux client-side --  When i type into the RDP session I get completely different characters making the session unusable.

Here I type "Administrator":

I'm sure it's a keyboard or character set issue.  I'm looking into the xfreerdp -k option, but have not solved it yet.  If you solve my problem, PLEASE post it in a comment.  Thank you, and good luck!
------------

Thursday, April 4, 2013

Check GMail via Linux Commandline

one line:
curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if //; print "$2\n" if /<(title|name)>(.*)<\/\1>/;'


originally from: http://www.commandlinefu.com/commands/view/3386/check-your-unread-gmail-from-the-command-line
----------------

Monday, March 25, 2013

Useful Text Processing Commands In Linux BASH



#replace inline-file
sed -i 's/old/new/g' file.txt

#de-duplicate
awk '!x[$0]++' input.txt > output.txt
#OR
perl -ne 'print unless $dup{$_}++;' input.txt > output.txt
#OR
awk '{if (++dup[$0] == 1) print $0;}' input.txt > output.txt

#save only line containing TXT
sed '/TXT/!d' input.txt > output.txt
#OR

grep -F "TXT" input.txt > output.txt
#delete line matching TXT
sed '/TXT/d' input.txt > output.txt
#OR
grep -v -F "TXT" input.txt > output.txt

#trim trailing spaces inline
sed -i 's/[[:space:]]*$//' filename.txt

#delete blank lines
sed '/^[[:space:]]*$/d' input.txt > output.txt

#delete blank lines inline-file
sed -i '/^[[:space:]]*$/d' input.txt

#del blank lines - does not work in ALL cases
sed '/^$/d' input.txt > output.txt

#del blank lines - does not work in ALL cases
awk NF input.txt > output.txt

#append text to lines
sed 's/$/APPEND/' input.txt
#OR
cat input.txt | awk '{ print $0 "APPEND" }' > output.txt
#OR
awk '{ print $0 "APPEND" }' < input.txt > output.txt

#output IP's only
grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' input.txt > output.txt

#output numbered quartet (IP-like)
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' input.txt

#count occurences
sort input.txt | uniq -c > output.txt

#top 10 stats of unique text, where $1 means 1st column, $2 second column, etc
grep sometext input.txt | grep someothertext | awk '{ print $1 }' | sort -n | uniq -c | sort -rn | head > output.txt

#top 20 stats of IP's performing nslookup to ".ru" sites, where input.txt is from a Windows Server DNS log.
grep -F '(2)ru(0)' input.txt | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | sort -n | uniq -c | sort -rn | head -n 20 > output.txt

#grep with or
egrep 'string1|string2' input.txt
grep 'string1\|string2' input.txt

#inverse head
#if "head" is first 10, then
tail -n +11 input.txt

#inverse tail
#if "tail" is last 10, then
head -n -11 input.txt

#remove lines in file2.txt from file1.txt
awk 'NR==FNR{a[$0]++;next} !a[$0]' file2.txt file1.txt > filtered.txt

#de-timestamping (zero time from datestamp)
echo "2015-06-26 07:33:55" | awk '{$0=substr($0,1,11)"00:00:00"; print $0}'
#OR
echo "2015-06-26 07:33:55" | sed 's/[0-1][0-9]:[0-5][0-9]:[0-5][0-9]/00:00:00/g'

#take a .yml file that has some lines with "income:" <value> and replace the value with 10% of the value
#ex.
#      WATER_WORKER:
#        income: 30.0
#        experience: 100.0
perl -pe 's/(income:) (\d+.*)/($1)." ".($2*0.10)/ge' jobConfig.yml > jobConfig.yml.new



Grep AND, OR, NOT

sed one-liners

PERL Regular Expressions

--------------

Monday, February 11, 2013

Exposé in Debian Linux XFCE


enter image description here

Updated 2016 Nov 4.

Compiz is fantastic, but i don’t want it. I only want an Exposé like feature. Thanks to Skippy-XD I can have it.

Firstly, you will need some dependencies:

sudo aptitude install libimlib2-dev libfontconfig1-dev libfreetype6-dev libx11-dev \
libxext-dev libxft-dev libxrender-dev zlib1g-dev libxinerama-dev libxcomposite-dev \
libxdamage-dev libxfixes-dev libxmu-dev

Now, install the currently maintained code from github:

cd ~/Downloads
git clone https://github.com/antonio-malcolm/skippy-xd.git
cd skippy-xd
make
sudo make install

Based on previous versions, I found it to crash occasionally, so I created a wrapper script to maintain it in a running state. Save the following script to ~/scripts/expose.sh or whatever your preference may be and mark it executable with chmod +x ~/scripts/expose.sh.

#!/bin/sh
while true
do
  echo [re]start
  killall skippy-xd
  rm /tmp/skippy-xd-fifo
  /usr/bin/skippy-xd --start-daemon
  echo "Died"
  echo
done

You can run it in the background with ~/scripts/expose.sh& or set it to autostart with login: In XFCE go to Applications->Settings->Session and Startup->Application Autostart tab: Add a new item named “Skippy-XD” with the command pointing to your new script.

Test it by running sleep 0.5 && /usr/bin/skippy-xd --activate-window-picker. If it works, proceed.

Now you need to set a keyboard shortcut: Go to Applications->Settings->Keyboard->Application Shortcuts: Add a new command containing /usr/bin/skippy-xd --activate-window-picker and set the key to your preferred keystroke (I chose F9).

If it ever seems to hang, you may wish to see if it is running with ps aux | grep [s]kippy and kill any processes before launching it again.

enter image description here

Good Luck!

Written with StackEdit.

Cisco VPN via Network-Manager applet in XFCE4 Debian

Fighting VPN configuration in Debian Wheezy lead me to post these notes.

Even after installing network-manager, network-manager-gnome, network-manager-vpnc, and adding a VPN, actually launching it failed -- no authentication dialog would show.

It was definitely a GUI issue as running vpnc from commandline succeeded.

As a test, run sudo vpnc --gateway <gateway-IP> --id <cisco-group-id> --username <username>
To disconnect use: sudo vpnc-disconnect
If you can connect, you know your vpn subsystem is operational.

So first install the necessary components: sudo aptitude install vpnc vpnc-scripts network-manager network-manager-gnome network-manager-vpnc network-manager-vpnc-gnome

To permanently add the nm-applet to your panel, in XFCE, go to Applications(Menu)>Settings>Session and Startup>Application Autostart tab and enable "Network". This will add the applet upon next session start. You MUST have the "Notification Area" applet added to the panel.

To temporarily show the applet without logout or restarting, run nm-applet & ; exit
Now initially, Network-Manager will not be managing your connection, so edit the config to enable management of your existing wired connection. For me this was named "ifupdown (eth0)": (reference) sudo nano /etc/NetworkManager/NetworkManager.conf and set in the config file managed=true
Then restart the network-manager: sudo /etc/init.d/network-manager restart
Now add your VPN settings and everything should work as expected.
---------

Sunday, February 10, 2013

Uninstall Squeeze Archive Manager

I love XFCE4. I dislike Squeeze Archive Manager.  It fails to unzip certain files.

When I tried to sudo aptitude purge squeeze, it always told me it would also remove xfce4-goodies. I didn't want all the goodies un-installed. But finally I typed "Y" ... go ahead, i'll add them myself if I have to -- i want squeeze OFF!

Well it seemed to hold all the goodies, and just removed the xfce4-goodies name....  But when I installed a new package it indeed started to remove all the goodies.

so I copied and pasted the "removing XXXXXX" lines and then reinstalled them:
sudo aptitude install hddtemp xfburn libburn4 libthunar-vfs-1-2 libhal-storage1 libhal1 libisofs6 libjte1 libthunar-vfs-1-common xfce4-verve-plugin xfce4-timer-plugin xfce4-smartbookmark-plugin xfce4-quicklauncher-plugin xfce4-notes-plugin xfce4-notes xfce4-mailwatch-plugin xfce4-dict xfce4-datetime-plugin xfce4-cpufreq-plugin xfprint4 libxfcegui4-4 mousepad ristretto xfce4-artwork xfce4-battery-plugin xfce4-clipman-plugin xfce4-clipman xfce4-cpugraph-plugin xfce4-diskperf-plugin xfce4-fsguard-plugin xfce4-genmon-plugin xfce4-mount-plugin xfce4-netload-plugin xfce4-places-plugin xfce4-sensors-plugin xfce4-systemload-plugin xfce4-taskmanager xfce4-wavelan-plugin xfce4-weather-plugin xfce4-xkb-plugin
and i need an archive manager so...
sudo aptitude install xarchiver
You may also want some certain utilities:
sudo aptitude install zip unzip rar unrar arj p7zip-full
now relax.
--------

Tuesday, January 15, 2013

Install php-mcrypt in CentOS 6


php-mcrypt is not in CentOS's standard repositories.  However, it is in Fedora's EPEL repository.

Install the EPEL Repo:
for 32 bit:
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
for 64 bit:
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Then you can
yum install php-mcrypt


EPEL also includes php-mbstring if you need that as i did.
-------

Redirect http to https on Apache server (httpd)

After googling http to https redirect, I found several answers that simply did not work (for me).  Finally I came across one that did:

In the directory of your web-content, create the file .htaccess and fill it with these directives:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI}

That's it.

This worked on CentOS 6.3 and Apache 2.2.15

p.s. Don't forget your firewall settings.

Friday, January 11, 2013

Install official VMWare-Tools via yum repository for RedHat and CentOS


Edit: RHEL 7 and CentOS 7 now officially recommends open-vm-tools via their own repository -- i.e. sudo yum -y open-vm-tools , then reboot -- that is all!  If you are still using RHEL/CentOS 5 or 6, then continue below:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(Sources: http://packages.vmware.com/tools/docs/manuals/index.html)

All instructions assuming root or sudo.

Special Note: May have to remove old versions prior to upgrades:
vmware-uninstall-tools.pl  or
rpm -e VmwareTools or
yum remove vmware-tools[-esx] or ..?..


First, add gpg keys for repositories:
wget http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-DSA-KEY.pub
wget http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-RSA-KEY.pub
rpm --import ./VMWARE-PACKAGING-GPG-RSA-KEY.pub
rpm --import ./VMWARE-PACKAGING-GPG-DSA-KEY.pub


Adding the appropriate sources depend on Release-Version and Architecture:

(Tools version can be 4.0latest, 4.1latest, 5.0latest, or 5.1latest)
(Release can be rhel5 or rhel6)
(Architecture can be i386 or x86_64)

***** edit: Thanks to Anonymous (Nov 1 2013), please do not use "*latest" as VMWare now recommends the static url/folder.  Ex: "5.1u3". Find yours by traversing http://packages.vmware.com/tools/esx/ 
***** edit: As of Early 2014, I find "*.latest" is still working with ESXi 5.1 and CentoOS 6.5 -- proceed at your own discretion.

Confirm your distro with cat /etc/redhat-release

Confirm your architecture with uname -m (or -a) (if i686, use i386)

Create the repository file /etc/yum.repos.d/vmware-tools.repo and edit it to contain the following, based on the above confirmations and desired vmware version:
(your baseurl will be http://
packages.vmware.com/tools/esx/<version>/<release>/<architecture>)
(note various examples are commented with #)
----------------------------------------------------------------------------------------------
[vmware-tools]
name=VMware Tools

baseurl=http://packages.vmware.com/tools/esx/5.1latest/rhel6/x86_64
#baseurl=http://packages.vmware.com/tools/esx/5.1latest/rhel6/i386
#baseurl=http://packages.vmware.com/tools/esx/5.1latest/rhel5/i386
#baseurl=http://packages.vmware.com/tools/esx/5.1latest/rhel5/x86_64
#baseurl=http://packages.vmware.com/tools/esx/4.0latest/rhel6/x86_64
#baseurl=http://packages.vmware.com/tools/esx/4.0latest/rhel5/i686
#baseurl=http://packages.vmware.com/tools/esx/4.0latest/rhel6/i686
enabled=1
gpgcheck=1

----------------------------------------------------------------------------------------------
 

Installation for VMWare 4.x tools (option 1 or 2 exclusively):
option 1) 4.x including X11 dependencies:
yum install vmware-tools
option 2) 4.x excluding X11 dependencies (headless):

yum install vmware-tools-nox

Installation for VMWare 5.x tools:
Step 1) Confirm PAE or not (if not PAE, will not see it):
uname -a


Step 2) Install kmods: (option 1 or 2 exclusively)
Option 1) non-pae:
yum install vmware-tools-esx-kmods
Option 2) pae:
yum install vmware-tools-esx-kmods-PAE

Step3) Install tools: (option 1 or 2 exclusively)
Option 1) including X11 dependencies:
yum install vmware-tools-esx
Option 2) excluding X11 dependencies (headless):
yum install vmware-tools-esx-nox

Note, This can be done in one line, but "kmods" must be FIRST
yum install vmware-tools-esx-kmods[-kerneltype] vmware-tools-esx[-nox]
where [-kerneltype] is "-PAE" or nothing and "-nox" or not.

Therefore, this is the no pae, no X (headless) install command:
yum install vmware-tools-esx-kmods vmware-tools-esx-nox


-------------