Rocu.de

Love, caffeine and omlette

Tag: tapas

The awesomeness tool-chain

I have an awesomeness tool-chain — command line tools, that increase my productivity dramatically. In this blog post I want to introduce you to these powerful tools.

Cowsay

$>  echo "I love strawberries" | cowsay
  _____________________
 < I love strawberries >
  ---------------------
             ^__^
             (oo)_______
              (__)       )/
                  ||----w |
                  ||     ||

Ponysay

If you like ponies and colors more - I understand. Depends on the use case really. I found ponies way more effective if you want to communicate something that could trigger bad feelings.

sl - The ls for pros

I often mistype ls. Gone are the days were this was boring. I just lean back and enjoy the show. Steam Locomotives are a big part of being awesome.

Fortune

If you are as new to programming as me you need help, when someone asks you for you're opinion.

Fortune produces profound answers to all kind of questions you did not even ask.

$ fortune
I am the mother of all things, and all things should wear a sweater.

$ fortune
Any sufficiently advanced technology is indistinguishable from a rigged demo.
    -- Andy Finkel, computer guy

Conclusion

Being awesome requires a special tool-chain. Having ponies and quotes at your disposal is essential. I think you should give this a try.

Backup a local directory to a FTP server

I had to backup a local directory to a FTP server.

My first impulse was to use Rsync but I was out of luck. Rsync doesn't work over FTP since it is a protocol of it's own.

That's when I stumbled over lftp:

LFTP is a sophisticated ftp/http client, and a file transfer program supporting a number of network protocols. Like BASH, it has job control and uses the readline library for input. It has bookmarks, a built-in mirror command, and can transfer several files in parallel.

In order to use lftp you have to install it using the package manager of your choice.

brew install lftp

Now you create a simple script. We use the mirror command here in order to sync a local directory onto the server.

SERVER="your.ftp.server"
USERNAME="user"
PASSWORD="pass123"

LOCAL_DIR="/source/dir"
REMOTE_DIR="/target/dir"

lftp -c "set ftp:list-options -a;
open ftp://$USERNAME:$PASSWORD@$SERVER;
lcd $LOCAL_DIR;
cd $REMOTE_DIR;
mirror --reverse"

The script uses your credentials to log in to the ftp server. The it starts to mirror your local directory to the directory on the server. The flag "reverse" is appended to the mirror command because per default lftp mirrors the content from the server into your local directory.

The mysterious line

lftp -c "set ftp:list-options -a;

is necessary if you want to transfer hidden files as well and your FTP server does not list them per default.

Conclusion

Often FTP backup space is one of the cheapest ways to back up a server, that's when lftp comes really handy. It is way slower then Rsync - but works fine in most situations.

I am glad I have lftp in my toolchain now.

How to prevent a cron job from running multiple times

Sometimes a cron job might run slower, than you anticipated and many instances of it stack up.

You can increase the time interval during starts of the cron job - this can lead to problems in the future however.

Fortunately there's a easy and clean fix.

Just replace your cronjob with this:

/usr/bin/flock -n /var/lock/<foobar> <long-running-task>

Whenever your cron job is started a lock file will be created and no other instance can start.

Conclusion

This a simple remedy for colliding cron job's. I use it frequently.

Create lorem ipsum text with TextExpander and lorem

Often I need dummy text to fill out a form.

I use a combination of TextExpander and the Lorem Gem that makes this
super simple.

Step 1: Install the "lorem" gem

Install the gem lorem using

sudo gem install lorem

It's simple to use:

# For 1 paragraph dummy text
lorem 1 paragraph

# For 140 chars dummy text
lorem 140 chars

Lorem is a Unix tool - you can combine it with other commands:

lorem 140 chars | pbcopy

Copies 140 chars into your clipboard.

Textexpander + Lorem

I dont want to go into my Terminal, whenever I fill out a
form in Chrome, so I created a TextExpander snippet, that executes lorem
for me and fills in the dummy text.

#!/bin/bash
lorem %filltext:name=paragraphs:default=1%

A nice additional feature is that it asks you how many paragraphs of dummy text you want.

Conclusion

Sometimes simple hacks like this save you a lot of time. I hope you find it as useful as me!

Command line tapas: Feel like a hacker with cluster ssh

A few months ago I paired on a chef recipe with a colleague. After we
uploaded the cookbook we wanted to try this stuff out on a few nodes.

Until then I would have kind of done it completely manually. But he
entered a command and the following happend:

ClusterSSH in action

Wow. He just ssh'ed into all of these servers. The next part looked even
cooler. He started typing and magically the text appeared in all the
terminals. He pressed enter and the chef run started. It looked awesome. Chef runs produce quite a lot of text 😉

I was hooked and asked him what he just did. "That's just ClusterSSH", he
replied, "I use it all the time".

ClusterSSH is a tool for making the same change on multiple servers at
the same time. The 'cssh' command opens an administration console and
an xterm to all specified hosts. Any text typed into the
administration console is replicated to all windows. All windows may
also be typed into directly.

For the Mac there is a similar tool called csshx thats what I ended
up using.

It works like a charm. You just specify your clusters in a clusterfile.

cluster1 host1 host2
cluster2 host3 host4

Now you just enter:

csshx cluster1

That's it.

I use csshx during every maintainance window. I love
pair programming. Makes you realize that things that are obvious to
yourself are not obvious to your colleagues.

© 2017 Rocu.de

Theme by Anders NorenUp ↑