Mostly about my amusement

Tag: note to self (page 1 of 1)

sed to the rescue again

Some days you just want to quickly edit a bunch of config files in one go.

One of the reasons I use Ubuntu LTS is that it’s got long term support (<light sarcasm>is that why it’s got LTS in the name?</light sarcasm>) and I make configuration templates that I just reuse in all the places. Poodle was announced and the short of it is that you need to disable the SSLv3 protocol on your web server.

No big deal. Visit your sites-available directory and change “SSLProtocol All -SSLv2” to add “-SSLv3” at the end. 17 times.

*Drinks more coffee and makes that face*

Or you know, run this command after checking you have “SSLProtocol All -SSLv2” in those mod_ssl config files.

sed -i.bak -e 's/SSLProtocol All -SSLv2$/SSLProtocol All -SSLv2 -SSLv3/g' *.conf

The -i.bak is to create unedited copies because bad things do happen to nice people.

Once I made sure that the files were edited I ran these commands to restart the web server and test.

service apache2 restart
openssl s_client -connect blog.dembowski.net:443 -ssl3

I promptly saw this line.

140496364975776:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:s3_pkt.c:596:

And all was right in the world. I deleted the .bak files and finished my coffee.

Namecheap dynamic DNS setup with ddclient

I recently received an e-mail from my free dynamic DNS provider that said I can upgrade for a fee or I can every month login and re-validate that I’m still using their service.

As I’ve been mooching off of them for over 8 years I really can’t blame them and I fully understand this change.

When I moved my domains to Namecheap one of the options they provide is dynamic DNS so that’s the solution for me. But my FIOS router doesn’t support Namecheap so I setup ddclient on my basement Linux server.

Using Namecheap’s support forum I found what I needed. This post is really my note to myself for when I wipe out my Linux server again and I wonder “How did I do that again?”

Enable Dynamic DNS for your domain

Login to your Namecheap control panel and enable dynamic DNS for your domain. You’ll get a really long password string to use. Save that for now as you’ll need it later on.

Create the DNS entry you want for your host as an A record

I created it with an entry of 127.0.0.1 just as place holder. I’m not sure if this step is really necessary as dynamic DNS should let you create new entries on the fly. But Namecheap’s page says to do it and there’s no harm in prepping for that A record.

Install the ddclient package on your Linux server

I’m using Ubuntu 12.04.2 LTS and the command is simply

sudo apt-get install ddclient

The debconf setup will ask you some questions, just put in what you like. You’ll need to change those values in /etc/ddclient.conf anyway.

Modify the ddclient.conf file

My /etc/ddclient.conf looks like this.

################
# ddclient.conf
# namecheap
################
use=web, web=checkip.dyndns.com/, web-skip='IP Address'
protocol=namecheap
server=dynamicdns.park-your-domain.com
login=my-domain.com
password='ReallYLongStringLooksLikeMD5orso'
my-server

Details have been changed to protect the innocent.

Don’t mess with the server= line, they’re not being cute that really is the name of the dynamic DNS client end point.

The debconf settings that were put in previously won’t work so I deleted /var/cache/ddclient/ddclient.cache and re-ran ddclient manually.

$ sudo rm /var/cache/ddclient/ddclient.cache
$ sudo ddclient
SUCCESS:  updating my-server: good: IP address set to 111.222.12.13

Cool. My server in on my private network so I’m using what my IP address looks like to the outside world.

The ddclient is running as a daemon and when my DHCP assigned IP changes (FIOS does that frequently, no idea why) my basement server will still be resolvable as my-server.my-domain.com. The client will run as long as my server is booted. I use that for testing dumb and harmful ideas and it’s always on.

DNS tranquility has been restored to my world.

Force logout Mac users

Yet another one of those write this down Jan, it will come up again posts. There’s almost certainly a better way to force log out absent users on a Mac but heck, this works for me.

To kill off all the processes of a user named joe who’s left logged in but used the user switcher, open up the Terminal app and run these commands.

sudo su -
ps aux | grep ^joe | awk '{ print $2; }' | xargs -I{} kill -9 {}

In my kitchen is the community iMac and I have set up accounts for my whole family. Sometimes people come over and forget to log out but used fast user switching to go to the login screen or a different user.

That’s not too bad, but some software combinations I’m running often take up lots of CPU needlessly. Yes, Firefox and Adobe Flash I mean you. The whole iMac becomes slow and unresponsive.

That makes for a sad Mac. More importantly at 5:30 AM it makes for a sad me. As long as you know Joe’s user id then this will zap all of his processes and log him out as a result.

If some of those processes are stubbornly cling to life then rinse and repeat.

Tabs and spaces

Self? Remember this:

tr 't' ' ' | sed -e 's/  */ /gp'

You’ll need it later.

At work I use bash, sed, [e]grep, cut, tr, and occasionally awk if I can’t get out what I need from the others. These aren’t used as scripts per se, just some tools I use to massage data.

Need that formatted, irregular, multi-line text file broken up and ripped into another format for processing? Sure, not a problem. Most people would (correctly) use PERL but I never got into it that much. I hardly ever get the same situation twice and deal with new data all the time.

But I do need to remove tabs and multiple spaces almost every time. While I always remember the tr part, I always need to rethink the sed regular expression. So here I am, writing a post to myself to keep it in my mind.