Below you will find pages that utilize the taxonomy term “Shell”
Dump all (most?) JMX Beans via Jolokia using just the shell and a bit of json formatting
It seems jolokia doesn’t support dumping everything with just one command.
So here’s a really hacky quick and dirty way to get all information jolokia can access:
for name in $(curl --silent http://dwtest:10002/search/*:* | python -m json.tool | grep '"value":' -A9999 | tail -n +2 | head -n -2 | sed 's/ /%20/g' | cut -d'"' -f2);
do curl --silent "http://dwtest:10002/read/$name" | python -m json.tool;
done
Once you’ve gotten this far, piping the information into a file or another tool is trivial.
Executing shell commands from groovy
pre { border: 1px solid #EEE; }
Sometimes you want to run a shell command generated from groovy or just want to achieve something that’s faster/simpler in the shell in comparison to doing it with groovy. One such case would be to get the number of git commits of a repo. The command for this is fairly simple:
$ git log --oneline | wc -l
179
Running shell commands from groovy is really easy too. Make a list and call ’execute()’ on it - how awesome is that?
Installing/Upgrading flash on Ubuntu behind a proxy
This just refused to work because the flashplugin-installer that actually downloads the packet doesn’t honor the http_proxy environment variable to I had to do a little hack to get this going. It’s actually pretty simple: download the file and serve it from localhost so we don’t need the proxy at all.
First shell:
- mkdir /tmp/flash
- cd /tmp/flash
- wget http://archive.canonical.com/pool/partner/a/adobe-flashplugin/adobe-flashplugin_11.2.202.310.orig.tar.gz
==> or whatever version YOU need - python -m SimpleHTTPServer 80
Second shell:
Always test your Puppet Modules
Always test your puppet modules. Even if it’s just a little smoke test like this:
class { my\_module: }
Now to make this one better, create a job on your continuous integration server and let it run the following script inside the modules directory of your puppet project:
#!/bin/bash
#DEBUG="--verbose --debug"
hash puppet 2>/dev/null || { echo >&2 "Please install puppet"; exit 2; }
[ -z "$(facter | grep fqdn)" ] && { echo >&2 "Your machine has no FQDN (according to facter), some tests may fail or print warnings"; sleep 5; }
for dir in $(find . -type d -name tests); do
for file in $(find ${dir} -name '*.pp'); do
echo ">>> TESTING ${file}"
puppet apply ${DEBUG} --modulepath modules --noop "${file}" || { echo ">>> ERROR" ; HAS_FAILURES="true" ; }
echo "------------------------------------------------------------------------------"
done
done
if [ "${HAS_FAILURES}" = "true" ]; then
exit 1
fi
It looks for all ‘*.pp’ files inside all ’tests’ directories and does a simple ‘puppet apply’ call. It may not be perfect but it’s small, simple, it works and it’ll save you some gray hairs.
Using awk to remove lines from a file
A little goodie I’m writing up here to document for my own future reference.
Objective: Remove all lines matching a certrain pattern from all files in a directory structure. The pattern is in the form of “part1.
First try: grep and sed, unfortunately that leaves me with blank lines where the matching content was and I want that line removed completely. Apparently sed can’t do that.
Second try: use awk with regexes. It took me a while and I wanted to use ’next’ on matching lines but that didn’t seem to work so I ended up printing the entire line if the regex didn’t match. Here goes:
Simple python script to access jmx via jolokia
I’ve never been much of a python guy. Now there’s this production environment where we’ve got a few basic things like bash, ruby (since we’re using puppet) and python. Our Java based software has a nice JMX interface with a bunch of lifesavers in it and each JVM has the jolokia agent running (http/json access to jmx) so we can access this goodness fairly easily from scripts and/or the shell. So far what we’d be doing would be something like this:
Quality loss when saving as JPEG
So recently an article was linked on reddit about a bunch of photography myths. Number 7, called “Saving a JPEG multiple times degrades quality” which was apparently proven to be wrong disturbed me most and so I did a quick test on my own.
Further below are Three images. The Original, the one saved 30 times and an XOR of the first Two showing the differences. If you toggle between the first two you can see quite a difference in the color on the car and several other details. Running any more tests at lower than 100% quality is pretty much a waste of time once you see these results.
Tanuki Software's Java Service Wrapper and your Environment Variables
This post has been updated
Here’s an evil little gotcha I ran into when using the Tanuki Software Java Service Wrapper to run our company bamboo server. But first you need to know a little bit of context:
We had our bamboo agent running as root for a long time and about two months ago I changed that. I created a bamboo user and installed multiple agents. Each of these into its own folder along the lines of /home/bamboo/bamboo/java-agent-1
etc. Now in each of these is a wrapper script under bin/bamboo-agent.sh
. Reading up a bit on the wrapper I found out I can change the script and set the variable RUN_AS_USER=bamboo
and then simply create a symlink from /etc/init.d/java-agent-1
to /home/bamboo/bamboo/java-agent-1/bin/bamboo-agent.sh
and then start/stop the service just like any other normal unix service.
Tanuki Software's Java Service Wrapper and your Environment Variables
This post has been updated
Here’s an evil little gotcha I ran into when using the Tanuki Software Java Service Wrapper to run our company bamboo server. But first you need to know a little bit of context:
We had our bamboo agent running as root for a long time and about two months ago I changed that. I created a bamboo user and installed multiple agents. Each of these into its own folder along the lines of /home/bamboo/bamboo/java-agent-1
etc. Now in each of these is a wrapper script under bin/bamboo-agent.sh
. Reading up a bit on the wrapper I found out I can change the script and set the variable RUN_AS_USER=bamboo
and then simply create a symlink from /etc/init.d/java-agent-1
to /home/bamboo/bamboo/java-agent-1/bin/bamboo-agent.sh
and then start/stop the service just like any other normal unix service.
Automatically switch your mvn settings
I have one primary development notebook and take that with me wherever I go. Now in a company setting you usually have proxies and whatnot. And I think it’s an official best practice to roll your own company or departement maven proxy/cache.
So dependent on where you are, you might need a different maven ~/.m2/settings.xml file. Here’s a very simple shell function you can add to your ~/.bashrc
function mvn {
MVN="$(which mvn)"
if [ -n "$(ifconfig eth0 | grep YOUR-WORK-IP-HERE)" ]; then
echo ">>> Running mvn whith work config"
${MVN} -gs ${HOME}/.m2/settings-work.xml $*
else
echo ">>> Running mvn with vanilla config"
${MVN} $*
fi
}
This just checks for the ip of eth0 and calls mvn with a special settings.xml. In all other cases mvn is run with the vanilla config (or none, since the settings.xml is optional).
Automatically switch your mvn settings
I have one primary development notebook and take that with me wherever I go. Now in a company setting you usually have proxies and whatnot. And I think it’s an official best practice to roll your own company or departement maven proxy/cache.
So dependent on where you are, you might need a different maven ~/.m2/settings.xml file. Here’s a very simple shell function you can add to your ~/.bashrc
function mvn {
MVN="$(which mvn)"
if [ -n "$(ifconfig eth0 | grep YOUR-WORK-IP-HERE)" ]; then
echo ">>> Running mvn whith work config"
${MVN} -gs ${HOME}/.m2/settings-work.xml $*
else
echo ">>> Running mvn with vanilla config"
${MVN} $*
fi
}
This just checks for the ip of eth0 and calls mvn with a special settings.xml. In all other cases mvn is run with the vanilla config (or none, since the settings.xml is optional).
The simplest way to create pdf's from images
There’s probably no simpler way to create a pdf from images. Behold:
convert \*.jpg output.pdf
That’s all folks!
The simplest way to create pdf's from images
There’s probably no simpler way to create a pdf from images. Behold:
convert \*.jpg output.pdf
That’s all folks!
Local postfix as relay to Amazon SES
Introduction
Alright, this is a quick guide for the impatient but otherwise experienced linux admin/hacker/hobbyist. Some past postfix experiences might be advantageous for general understanding and troubleshoooting.
Why would I want a local postfix and relay to another smtp anyway? Simple: When my application code needs to send an e-mail, there is an SMTP server ready to accept the e-mail from me. It will then take care of everything else like re-delivery, dealing with being grey-listed and many other things. Also, if connectivity to the SES SMTP happens to be interrupted it’s no big deal because here too, the local postfix will handle re-sending for me. Nice, huh?
Local postfix as relay to Amazon SES
Introduction
Alright, this is a quick guide for the impatient but otherwise experienced linux admin/hacker/hobbyist. Some past postfix experiences might be advantageous for general understanding and troubleshoooting.
Why would I want a local postfix and relay to another smtp anyway? Simple: When my application code needs to send an e-mail, there is an SMTP server ready to accept the e-mail from me. It will then take care of everything else like re-delivery, dealing with being grey-listed and many other things. Also, if connectivity to the SES SMTP happens to be interrupted it’s no big deal because here too, the local postfix will handle re-sending for me. Nice, huh?