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).



----------
Please consider crypto tipping:
  

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.

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

Please consider crypto tipping:
  

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!
-----------------
Please consider crypto tipping:
  

July 04, 2013

Duck Duck Go


Please consider crypto tipping:
  

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...
------------------

Please consider crypto tipping:
  

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.
-----------------

Please consider crypto tipping:
  

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

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

Please consider crypto tipping:
  

May 17, 2013

psexec via linux



Best source for Debian derivatives: https://software.opensuse.org/package/winexe
Best source for RH derivatives: https://pkgs.org/search/?q=winexe

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.

~~~
As always, Good Luck!

Please consider crypto tipping:
  

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.

--------
Please consider crypto tipping:
  

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!
------------
Please consider crypto tipping:
  

April 04, 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
----------------
Please consider crypto tipping:
  

March 25, 2013

Useful Text Processing Commands In Linux BASH





I've come back to this time and time again. I hope you find it useful!

#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

# trim leading, middle, and trailing spaces (reconstitutes records )
echo '         text     txt   info     ' | awk '{$1=$1}1'


#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 or
egrep 'string1|string2' input.txt
grep 'string1\|string2' input.txt

#grep non-comment, non-empty-lines -- see 'grep or' above
cat /etc/rsyslog.conf | grep -v '^#\|^$'
cat /etc/php.ini | grep -v '^;\|^$'

#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

#find international characters (possibly limited charset) (e.g. finds íóëã)
grep -P '[^\x00-\x7f]' input.txt

#replace international characters with plain-text (e.g. íóëã to ioea)
perl -C -MText::Unidecode -n -e 'print unidecode( $_)' < input.txt

#replace ` with '
sed "s/\`/'/g" input.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'

#find files that do not contain TEXT from a set of specific files
find ./ -iname "filename" -exec grep -L TEXT {} \;
# e.g. find src/main/target/ -iname "target.h" -exec grep -L USE_.*_EXTI {} \;

#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

~~~
As Always, Good Luck! You can thank me with bitcoin.   

March 15, 2013

Windows Commandline Super Tools

Make your win-management job easier with these command-line super tools:

Swiss Knife Tool
Kixtart
SysInternals Suite
Win Server 2003 resource Kit Tools
CygWin
GnuWin
--------------
Please consider crypto tipping: