Set a Wallpaper That Survives Reboots in Slackware Linux

If you’re using KDE, GNOME, XFCE or any other full desktop environment you probably have a right-click “set as background” option that handles this for you. However if you’re on Fluxbox,  DWM, AwesomeWM, TWM or another lightweight window manager this tip might be helpful for you.

The command we’ll use is the fluxbox wallpaper command fbsetbg, it should work across almost all other window managers however.

Usage is simple:

fbsetbg mywallpapername.jpg

However that wallpaper won’t survive a reboot and you’ll be back with a blank screen the next time you need to power down. To make it permanent we can use fbsetbg -l (which automatically sets the last wallpaper set with the command) in our ~/.xinitrc.

So for example a minimal .xinitrc to launch fluxbox with our wallpaper could look like:

exec fbsetbg -l &

exec fluxbox

It’s simple but elegant. Since the last wallpaper set will always be restored on the start of X you’re free to change it as much as you want without updating anything.

There are several other cool things you can do with fbsetbg covered in it’s help output and man pages. Go forth and experiment!

How Strong is your tcpdump Fu?

Tonight I just wanted to point out a great little article that ran on Linux Journal a few days ago by author Henry Van Styn titled tcpdump fu.

It goes into a few of the more useful things you can do with the tcpdump command and does a good job of it. If you’re looking for a good five minute primer on using tcpdump for packet analysis I’d recommend checking it out.

Seeing it pop up in my feed reminded me I need to actually read the copy of Network Flow Analysis by Micheal Lucas that I bought a few months ago. Look for an in depth series on packet an flow analysis in the future.

View Your IP Geolocation in Google Maps – One Liner

This little one-liner will automatically find the coordinates of your public IP address and display them in google chrome in web app mode.

curl -s http://geoiplookup.wikimedia.org/|awk -F, ‘{print $3,$4}’|awk -F’”‘
‘{print “http://mm/maps?q=”$4 “,” $8}’ > .t && google-chrome –app=`cat .t` ; rm .t

Shown across two lines to not mangle, run as one.

It’s a little inelegant with the writing to a file but I found that if you try to pipe the data straight to chrome the response is not fast enough and the url is not inserted correctly.

Thanks to j_melis over on commandlinefu for the initial code that I simply added on to.

Find Your Public IP from the Linux Command Line

Here’s another short ass-kicking tip.

Whenever you’re wondering what the public IP of the box your working on is, whether it’s to perform a scan, correctly point DNS, forward ports or any of the other many reasons one needs to find a public IP try this:

curl icanhazip.com

That’s it. If you go to http://www.icanhazip.com in a browser you’ll see it just spits out your IP in plaintext.

It’s no beautiful 10000 character one liner but it’s amazingly helpful to remember when you need it ( and you will, trust me ).

Completely Kick a User on Linux

This is so quick it probably doesn’t even warrant a post. However it’s Sunday, i’m lazy, and I don’t intend on breaking my perfect one post per day streak.

The killall command is really useful in several different circumstances but for our purposes right now we’re interested in the -u switch. This tells killall to kill every process running as a user, that covers ssh sessions, screen, any GUI, everything. If you need someone off of your system immediately for whatever reason just use:

killall -u someusername

There you have it, nothing fancy but it does the job fast. Use it to strike fear into the hearts of your mere user enemies.

Allow MySQL Users to Create Databases Safely

If you’ve used a shared hosting platform before and wondered why your databases were always $username_database or even a random string of characters, it’s a pretty simple concept. When you have multiple users sharing the same RDBMS ( in this case MySQL ) you can’t have them all trying to create databases with the same name, you need some way of keeping every DB name unique.

This handy little trick for MySQL allows a user to create any database he wants as long as it starts with $username_. So I could create masen_wordpress but not wordpress, and so on and so forth.

GRANT ALL PRIVILEGES on `monty\_%` .  * TO ‘monty’@'localhost’;

Obviously this can be tweaked to shave down the permissions given and any arbitrary string can be used in place of monty, the basic concept remains the same however. After entering this in the mysql command line our user monty can create databases to his hearts content.

Quickly Find Thinkpad CPU Temp Linux

This one is a little specific but I needed it this morning so I made a quick one liner for it that I thought I would share.

tc=`tc=`cat /proc/acpi/ibm/thermal | awk ‘{ print $2 }’`;tf=$(echo “scale=2;((9/5) * $tc) + 32″ |bc) echo “CPU TEMP => $tf F”

Pretty simple but I’ll break it out for you anyway.

cat /proc/acpi/ibm/thermal

This proc file contains quick readings for each thermal sensor, you can check out the listings for them over on thinkwiki: http://www.thinkwiki.org/wiki/Thermal_Sensors. A reading of -128 means a disconnected sensor.

awk ‘{ print $2 }’`

Print the second collumn, I happen to know this is the CPU Temp colloum.

tf=$(echo “scale=2;((9/5) * $tc) + 32″ |bc) echo “CPU TEMP => $tf F”

Use bc to convert the C reading to F which makes more sense to me, then output a pretty reading.

As you can see it’s a pretty simple little one liner. This is obviously specific to a Thinpad T400 but it would work the same with any other machine, just sub the correct /proc file for your model.

Disk usage from du/df with colored graph output

Here’s a nifty little command that I picked up off my commandlinefu.com RSS feed a couple weeks back for colored graph of du

t=$(df|awk ‘NR!=1{sum+=$2}END{print sum}’);du / –exclude /proc –exclude /sys –max-depth=1|sed ‘$d’|sort -rn -k1 | awk -v t=$t ‘OFMT=”%d” {M=64; for (a=0;a<$1;a++){if (a>c){c=a}}br=a/c;b=M*br;for(x=0;x<b;x++) {printf “\033[1;31m” “|” “\033[0m”}print ” “$2″ “(a/t*100)”% total”}’

Run As Root! This is meant to be used as a one-liner, it’s broken up here to make it readable on the page

Yea it’s a long one. Basically it takes the output from df and du / ( I’ve added some exclusions for /proc and /sys to quiet down the errors ) sorts it, and outputs a rudimentary ASCII graph showing the percentage of disk usage for / level directories ( home, etc, opt, tmp ).

You can change the directories it scans by tweaking the du c0mmand at the start, and you can also tweak the colors the graph outputs by tinkering with these:  printf “\033[1;31m” “|” “\033[0m”}.

Here’s a quick list of ANSI/bash color codes to use:

Black 0;30

Dark Gray 1;30

Blue 0;34

Light Blue 1;34

Green 0;32

Light Green 1;

32 Cyan 0;36

Light Cyan 1;

36 Red 0;31

Light Red 1;31

Purple 0;35

Light Purple 1;35

Brown 0;33

Yellow 1;33

Light Gray 0;37

White 1;37

Test it out in a terminal, if you don’t find it useful I guarantee you’ll find it at least mildly entertaining.

RHCE Objectives Series: Book Recommendation

 

I spoke earlier about the huge help having a book can be in studying for your Red Hat exams. I’m using the RHCSA/RHCE Red Hat Linux Certtfication Study Guide ( Amazon.com link, definitely the cheapest option ) by Micheal H Jang.

Some things I appreciate about it are the very detailed labs it provides at the end of each chapter, a great table at the beginning showing where specific information for each certification objective are located in the text ( easy to read along with this series ), and overall clear and sometimes even amusing writing.

I would post a more detailed review on it but I don’t believe it’s needed. It’s a great buy for the price, it helped me pass my RHCSA and I’m already glad to have it while I study for my RHCE. Just like the actual tests it puts alot of emphasis practical exorcise and includes theory as more of a footnote.

Whether you’ll be following along with my series or not, if you’re working towards your RHCSA or RHCE I would wholeheartedly recommend you pick up a copy of this book.

 

RHCE Objectives Series: Introduction

Studying for a Red Hat exam can be a daunting task and self studying for one is even worse. Books bent towards the specific certification are a huge help for those of us who prefer to learn at our own pace, providing detailed labs and code/output examples to get you through each study objective.

However when I was studying for my RHCSA what I really wanted was something concise and clean. Something that would go objective by objective with no fluff or digressions into something that wasn’t directly exam relevant. I thought this would be the ultimate study tool to keep handy along side my massive tome of a book, and that is what I hope to provide for RHCE seekers with my Objectives series . It will be written as I study for the exam myself and feature only the fastest methods (99% CLI) and most relevant information for each individual exam objective.

Red Hat is kind enough to provide the RHCE objectives that I will be following on their site over here: http://www.redhat.com/certification/rhce/objectives/. These objectives are exactly what you’ll need to know to take and pass the RHCE, nothing more and nothing less.

For all of my examples I’ll be using CentOS 6, which you can freely obtain on their website ( http://www.centos.org ). There are other rebuild distributions but I recommend Cent, it has a long history and in very proven track record in the wild.

Thanks for reading this brief introduction and I hope you enjoy the series.