Mine the Harvest

Netstat connection timers

by on Apr.29, 2013, under Linux

Netstat is so dang useful.  I never knew it had the ability to report connection timers. Netstat, I love you.

From:

http://unix.stackexchange.com/questions/10106/orphaned-connections-in-close-wait-state

http://www.sunmanagers.org/pipermail/summaries/2006-January/007068.html

How long have those connection been there anyway?

[root@gibson ~]# netstat -tonp
tcp 0 0 ::ffff:127.0.0.1:8081 ::ffff:127.0.0.1:46181 TIME_WAIT - timewait (0.00/0/0)
tcp 0 0 ::ffff:127.0.0.1:8081 ::ffff:127.0.0.1:47343 TIME_WAIT - timewait (43.72/0/0)

Or hows that keepalive going?

[root@gibson ~]# netstat -tonp | grep ESTABLISHED | grep keepalive
tcp 0 0 127.0.0.1:5432 127.0.0.1:54403 ESTABLISHED 13694/postgres keepalive (5846.25/0/0)
tcp 0 0 127.0.0.1:37929 127.0.0.1:5432 ESTABLISHED 4132/pgagent keepalive (5116.28/0/0)

Yeah, but what about how long they have been in CLOSE_WAIT?

[root@gibson ~]# netstat -tonp | grep CLOSE_WAIT
tcp 1 0 127.0.0.1:38736 127.0.0.1:8083 CLOSE_WAIT 29817/httpd off (0.00/0/0)
tcp 1 0 128.219.164.216:44054 128.219.168.138:8080 CLOSE_WAIT 25264/httpd off (0.00/0/0)

Ahhh . . . there is no time out value for CLOSE_WAIT. Darn.

Your current timeout and keepalive settings in seconds:
cat /proc/sys/net/ipv4/tcp_fin_timeout
cat /proc/sys/net/ipv4/tcp_keepalive_time

Leave a Comment more...

Sublime Text and Floobits

by on Apr.18, 2013, under Linux

I’ve been playing around with some collaborative coding tools recently: Etherpad, c9.io, infinoted / Gobby which is pretty cool with the Gedit plugin, etc. These, especially c9.io with it’s GitHub and Heroku integration, are very cool tools.

However, with the exception of the Gedit Collaboration plugin, many collaborative coding sites expect you to use a web editor. While c9.io’s editor is okay, nothing beats editor like vim, kate, etc.

Floobits is a collaborative editing site, but they are creating plugins for editors. One is available for Sublime Text, and one for Vim is in progress. Floobits lets you create public or private “rooms”, import code from github, and edit the content with a native editor. Using this with Sublime Text is pretty cool. If you need to share code or work with someone who is not set up with an editor and Floobits plugin, no problem – they can fall back to using the Floobits web editor. In minutes you an be coding together.

All the above lead me to check out Sublime Text 2, and I have to say – wow. I’m a long time Vim user, and while I love Vim (especially as my sys admin workhorse editor) for long coding stints, Sublime is looking amazingly good. Just check out the slideshow. But when you match Sublime up with git and floobits plugins, it gets even better.

Sublime has some other brilliant features. The ctrl-p function to search all files, and bring them automatically into focus – and then zero in on the function your looking for instantly is pretty much gold. See the screenshots of this in action, as well as other general tips here. I also really like the preview panel for navigating. And it’s fast – really fast.

Though licensed, it’s extremely forgiving. Download for Linux, Windows and OSX and it is fully functional, no expiration. You don’t need a key, or an account, etc. Download and use. If you like it you can purchase a license for $70.

If you want to test drive Sublime Text and Floobits see my guide, which has some tips as the Package Control installer has a bug that requires manually installing Floobits – which is trivial. And or course see Floobits plugin page.

Leave a Comment more...

f.lux Makes For Sweet Dreams

by on Jan.26, 2013, under Linux

Last year a Hackerspace colleague turned me on to this nifty tool. (Thanks Andy!) It’s just the kind of thing I like: A super-simple, lightweight, “just works” applet that does something exceedingly useful – it red shifts your monitor as you enter evening.

http://stereopsis.com/flux/
It makes the color of your computer’s display adapt to the time of day, warm at night and like sunlight during the day.

It’s even possible that you’re staying up too late because of your computer. You could use f.lux because it makes you sleep better, or you could just use it just because it makes your computer look better.

Now, that that might sound boring or “not very useful” – but I encourage you to test drive it. True, you can manually adjust your monitor, have different color profiles, etc. but the beauty of this is it will color shift automatically – which is exactly what I needed.

I can’t tell you how nice it is  as I’m coding away at night (when I probably shouldn’t be) to have the screen dim to a nice rose tint. I swear I breath a sigh of relief every time. (And it even works with X when I’m playing a game, Diablo 3 looks pretty cool when it happens.)

In the morning, it is equally nice. Rather than be blinded when I turn on the monitor, it is far more soothing and acceptable.

It might indeed even help you sleep better by reducing  stimulation received from blue wavelength light during evening. Check out the research links at the site for further reading.

You can simply download the binary and run it:

wget http://secure.herf.org/flux/xflux.tgz

By providing your zip code (United States only) or lat+long it will be better able to time the transitions. Gnome / Ubuntu users can have a little control panel too – though it does not seem to play well with Unity. No matter though, you don’t really need it. You can add a symlink to the binary from your Desktop Environments startup folder, or be fancy and make a script that starts it every time you boot. A bash script follows which checks for a previously started instance. Sweet dreams.

#!/bin/bash 
#!/bin/bash 
 
# Script to automatically start xflux 
# http://stereopsis.com/flux/
# wget http://secure.herf.org/flux/xflux.tgz
 
# To have it start automatically on user login:
# KDE: Place binary or this script in /home/$USER/.kde4/Autostart
# Gnome / Ubuntu: Run gnome-session-properties in terminal and add xflux (or this script) to the startup program list
# See: http://askubuntu.com/questions/48321/how-to-start-applications-at-startup-automatically
# Other: Create a symlink to the binary, or place it in your environments startup folder, etc. 
 
# Usage: /usr/local/bin/xflux [-z zipcode | -l latitude] [-g longitude] [-k colortemp (default 3400)] [-nofork]
# protip: Say where you are (use -z or -l).
 
instance=`pidof xflux`
if [ -z $instance ]
then
/usr/local/bin/xflux -z yourZipCode
else
echo "xflux is already running with pid $instance."
echo "You may kill it with: kill $instance or pkill xflux"
fi
Leave a Comment more...

lslt Bash Function

by on Jan.26, 2013, under Linux

I’m always typing: ls -lhatr | tail

I decided this was getting old. ‘Alias’ was not going to really do what I wanted, so I made a little bash function instead, which can be put in your .bashrc, etc. Simple – but handy. And (of course) maintains colors.

The full script version :

?Download lslt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
# List the last N items in specified directory in
# reverse time order (newest on bottom).
#
# Note however, the 'alias' commanad alone will not correctly handle args.
 
if [ $# -lt 1 ]
then
        echo "Usage: $0 /foo N (optional)"
        echo "Will perform ls -lhatr | tail -N"
        exit 1  
fi
 
dir=$1
echo "Listing $dir . . . "
ls -lhatr --color=always $dir | tail -$2

But you can achieve the same thing with a bash function, perhaps in your ~/.bashrc e.g.:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# lslt () { command ls -lhatr --color=always "$1" | tail -"$2"; }
#
# Or even fancier . . .
 
lslt () {
if [ $# -lt 1 ]
then
        #type lslt //Works, but a nicer way is . . .
        echo "Usage: lslt /foo N (optional)"
        echo "Will perform ls -lhatr | tail -N"
else
        command ls -lhatr --color=always "$1" | tail -"$2";
fi
}
Leave a Comment more...

Google Drive for Linux – grive

by on Jun.01, 2012, under Linux

Google has yet to release a Linux client for its new Google Drive service, but thanks to some enterprising individuals an Open Source client called grive is available at this github repo. Some additional info is available through the grive Google+ site and here.

Google Drive, similar to Dropbox and other file sharing services, allows you to store documents online, share them with others, etc. with a 5GB allocation to start with.

Getting grive for Linux

For Ubuntu 11.10 or later grive should be in your repos.
For other distros, building from source is fairly trivial, but the follow notes might be of assistance.

Building from source

Install the needed libs listed in the README, and cmake then build as below, which uses the typical cmake build process that create a Makefile, etc. (For Suse 12.2: zypper install cmake libgcrypt-devel libjson-devel curl-devel libexpat-devel boost-devel)

git clone git://github.com/Grive/grive.git
cd grive
mkdir build
cd build/
cmake ..
cd grive
make

You can run the binary from here, without running make install.

Running make install did not install the libgrive.so library correctly for me. You can verify if yours did with ldd `which grive` and see. If needed, you can install the library separately:

Installing the library

From the libgrive directory:
grive/build/libgrive$ sudo make install
#ldconfig (as root)

This should install to /usr/local/lib/libgrive.so

Rebuilding

As a note, if you relocate your git repo cmake will freak out as the paths will be wrong. Another lovely benefit of cmake. To clean up and rebuild if needed:

In your build directory:
mv grive/ grive.old
mv CMakeCache.txt CMakeCache.txt.old
cmake ..

Okay, okay – let’s use it already!

Run the resultant binary and connect it to your Google Drive via the nifty Google API. (Create a sync folder first, in which to they sync contents):

mkdir ~/Grive
cd ~/Grive
grive -a

Go to the Google link provided and then enter the API key so grive can talk to your Google Drive. Grive then downloads your drive contents to the local folder.

Now, push stuff up!

echo “Pushing this to my Google Drive.” > grive.push.test.txt
grive

View your drive contents at https://drive.google.com/#my-drive and verify your file has been pushed.

That’s all there is to syncing folders – pretty easy. You can add the -V option for more verbose log messages.

Security via Encfs

For the security conscious, encfs can transparently encrypt files stored in an encfs mounted directory. I use this to mount a encrypted folder in Dropbox to an unencrypted mount point in my home directory. Anything dropped in the mount point dir is AES encrypted and stored in the folder in Dropbox. I find this extremely useful and it integrates with Dropbox well. More information on encfs and integrating it Dropbox is here. Though I’ve not tried it yet, I see no reason it could not also be used with Google Drive folders as well.

Conclusion

Google, despite being a bit late to this game, is sure to win over many people with Google Drive especially heavy Google Docs users or who may be otherwise new to this type service. There is a lot of competition with Dropbox, Spideroak, S3, and Sky Drive – but Google has not exactly been first to market in other areas, which they then dominated. For myself, Google Drive is somewhat handy but I’ve been using Dropbox for a good while now, and Google Drive really offers me nothing more compelling feature wise than I enjoy with Dropbox.  I also like Dropbox’s file recovery options (the pack rat option makes available all previous versions of an object, nothing is ever really deleted) and I like how all clients are automatically synced – no action is required. Still, options are good!

If you would like to try Dropbox, see this previous post which also links to a referral that will give you (and me) an additional 250MB of storage.

Another interesting option is SparkleShare which allows you to store your files in a git repo – be it github, gitorious or a bare repo on your own server. Very cool. The open source client is available for Linux, OSX and Windows. This is also an interesting and compelling new way to centrally save, distribute and share files.

 

 

4 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!