Table of Contents

UNIX/Linux Fundamentals Journal

Week #1

Spells…

The first day of Unix consisted of learning some of the basic spells (commands) that we will use throughout the course. Luckily many of these are familiar to me since I've already taken Joe DeLeone's classes and because I've had to use a handful of similar commands while working with Cisco IOS command line.

Here are the spells I managed to jot down in class:


Spell: Explanation: Example:
ls I call this “list stuff” because it does just that. Smack “-la” on the end and we get a whole bunch of information as well as ALL files in our current directory. n/a
who This tells us who is logged into Lab46 or whatever system you are using. n/a
pwd Tells us the Current Working Directory. n/a
cd Used alone - brings us back to our “home directory”. Used with a path - changes directory to the given path. n/a
man The Holy Grail of Knowledge. I guess. It's the manual. “man ls” will give us the manual info for the “ls” command. Easy Peasy!
whereis Gives us the address to a file/directory. But a directory is technically a file containing files. So, this gives us the address to a file or a file within a file. Or that file within the file of a file. File-ception.
whoami For those days that you really feel like you forget who you are. Who are you?
pom Phase of Moon. I mean, I can't think of any practical use at the moment, but hey… At least we can find out some moon info on the fly? Yep.
cal The calendar! Following up with a year or month, etc. will give more options. “cal 1752” shows us an interesting transition of calendar formats in September of that year.

Week #2

Quotes:

Symbol: Explanation:
the half quote, allows variable expansion
' the full quote, literal quote - no expansion
` the back quote/tick, allows command expansion
\ the “whack” - toggle special meaning of the following

Examples of Quotes:

echo “$PATH” ls [this will list stuff as usual] PATH= [this sets your PATH to null] ls [this is now broken] PATH=/bin [this sets PATH back to /bin where ls is located]

echo “There are `/usr/bin/who|wc -l` users on the system.” -the above command echoes “There are”, runs the command inside the backticks, echoes it's output within the original echo, and then echoes “users on the system.” to finish the command.

echo “\$PATH”

Wildcards:

Symbol: Explanation:
* is 0 or more of anything
? is 1 of any character
[ ] is a character class, 1 of any within brackets
[^ ] is an inverted character class, do not match anything within

Examples of Wildcards:

-from within /bin

ls ???? | wc -w

The above command will do a normal ls including only 4 character results, then it is piped into the wordcount program and returns the numerical amount of entries (because of the ”-w“) that contain 4 characters.

ls ?[aeiouy]??

The above command will show us all 4 character results from /bin that have a vowel in the second character field.

Fun with stuff...

r=[^aeiouy]

That will make the $r variable equal to ”[^aeiouy]“ so you can do this…

ls $r$r

And that will list every 2 character result that DOESN'T have a vowel in either of the two characters (because of the ^ inside the brackets).

Week #3

So, today I managed to goof up the ability to edit my opus from the website. I was pretty stumped until I took the time to look into what happened…

A little background, first. I was given the ability to access src/opus so that I could edit my journal entries from right inside the prompt (I've been getting comfortable with VI lately). This was a random idea I had during class last week and Matt thought it was good enough of an idea to give me this ability. Why do I need this? Why not just edit right from the webpage? Well, say I'm on my phone and I want to SSH into Lab46 or my terminal at home and add to my journal. Nifty! Why not just use the web browser on my phone? Because it's not always about HOW something is accessed, but the fact that it CAN be accessed from anything capable of establishing an SSH session and providing me a method of I/O.

Alright. So, I made sure src/opus was added to hg (Mercurial Repository) so that I could push and pull my commits to my journal from home and Lab46. The other day I decided to catch up on my opus by adding to my journal via the included (GUI-based) text editor in CentOS (what I run at home as a Unix “play-box”). When I finished, I gave “hg commit -m “Added to journal”” and “hg push” and provided my credentials. I SSH'd into Lab46, said “hg pull” and “hg update” and then went to check my journal through the website. It worked! Sort of. I mean, at this point I was happy I was able to make all of this work. But when I clicked “Edit” on the website (after logging in), it brought me to a Read-Only version of my journal. When I said “ls -la” from within src/opus I see intro.txt, start.txt, and title.txt and they all have the permissions of 660 and the group “www-data” while my recently edited journal.txt has the permissions of 644 and the group “lab46”.

So, obviously it's a permission issue. I did a little research and tried to “chgrp www-data journal.txt” but permission was denied. I changed the permissions to 660 (like the other files that are still working correctly) and now clicking the “Edit” button on the site brings me to a blank box. Derek Parsons told me a conflict between UID's may have caused this. The only other conclusion I can come to is the Text Editor in CentOS messed up the group and permissions which I then pulled back to Lab46 to overwrite the previously functional journal.txt file.

I'm going to tinker around a little more and perhaps try duplicating the text inside journal.txt into a new file, renaming the old journal.txt to journal.txt.bak, and set the proper group and permissions on the “new” journal.txt file. Also, I was able to make everything work by setting the permissions on the existing journal.txt to 666… But that's not very ideal. I doubt it'd be a good idea to leave it like that so it's now back to 644 until I figure this out.

Anyways, on to the Archive and Compression activity!

I copied the files for the Lab over from the given directory by typing the following commands…

cp /var/public/unix/archives/* ~

(The above command copies all files in that directory to my home directory.)

To extract the files from archive1.tar.gz I typed the following:

tar -xf archive1.tar.gz

To extract the files from archive2.zip I typed the following:

Week #4

Using some of the commands and tricks I've learned in class, I set up an environment variable that tells me how many processes I currently have running! I achieved this by typing the following…

procnum=$(ps aux | grep $USER | grep -v grep | wc -l)

echo $procnum

That will give me a number (wc -l) equal to the number of processes currently running (ps aux) that are my own (grep $USER) but not including this command (grep -v).

Actually, since “echo” is a process, I added echo to the grep -v pipe. Now it shows a more accurate count of running processes.

Regular Expressions:
Symbol: Explanation:
. match any single symbol
* 0 or more of the previous
\< match start of word
\> match end of word
^ match start of line
$ match end of line
[ ] match one of the enclosed
[^ ] do not match any enclosed
( ) grouping
| logical OR

Remember… if you use the regular expression .* you will get 0 OR MORE of any symbol.

So, messing with the dictionary, we can do some insane searches with grep. grep loves regular expressions!

cd /usr/share/dict/

cat words | grep '^[Ss].*[Mm].*[Ee]$' | wc -l

This will give us the number of words of any length that start with a upper or lower case s, have a lower or upper case m somewhere in the word, and ends with a lower or upper case e. Sweeeeeeet.

Week #5

for

The “for loop”

for1);do

Double parenthesis contain arithmetic!

i=0 is the “starting place”

i<10 is the “loop as long as”

i++ is the “step”

This says that i is equal to 0 at first and so long as i is less than 10, add 1 to i until it finishes.

Unix Case Studies


HPC Experience I Journal

Week #1/2/3

My first ambition in this class will be getting Debian on an old HP iPAQ HX4700 that currently runs Windows Mobile 6.5! Windows Mobile is slow and somewhat “clunky” and I think I could actually make some use out of that little PDA if it had a Linux distro on there.

Maybe after I get that up and running, I could find some interesting uses for it… I've been anxious to learn about SNMP traps/etc lately. I'm thinking a live “feed” of SNMP messages from my network and server equipment in my house would be awesome. First thing's first though… Getting Debian onto it.

OH! And I intend to grab a RaspberryPi Mobel B off of Amazon some time very soon. I'd love to see what I could do with one of those.

Week #4

I have been pushing myself to transition a lot of my stuff at home into the Linux world. Aside from my primary server and my gaming PC's, I've been installing Ubuntu/Debian/etc on my Virtual Servers as well as my laptops. I have another little project or two I have been starting at home as well…

- DIY Home Security System -

I have some old Android Smartphones sitting around that are nearly useless to me. I found an app called IP Webcam which broadcasts (from your preferred IP and Port) a live stream of video on your network. I would like to get a new Virtual Server up and running on my secondary home server that will monitor this stream and record a clip whenever it senses movement. The camera sits in my kitchen watching the only door in the house that is occasionally left unlocked while nobody is home. I've been getting paranoid lately with the recent discovery of a drug dealer down the road. HURRAY. I've been snooping around for applications that fit the bill for what I want and found plenty of Windows apps (of course) and a handful of Linux apps that can do this. Most notably, ZoneMinder, allows me to run a service on a Linux system that hosts a web page that gives me oodles and oodles of options for IP cam monitoring. More on this next week!

- Lightweight Linux DNS Server -

This one should be a boatload easier than the above project. I'm tired of typing IPs every time I want to use vSphere Client to connect into my VMware ESXi Servers. Or when I just want to ping something on my network, etc… So I'll be running a small, standalone virtual DNS server on my network on one of my VMware servers. I love VMware. I mean, seriously. I've never had so much fun with virtualization in my life. Using Hyper-V sucks. Why in the world would I want to run critical virtual machines inside an unreliable, resource hogging, clunky OS (Windows Server)? I tried this for awhile and I hated it. Every time Windows Server needed to reboot to apply updates, I'd have to take down mulitple virtual machines as well. Now I use VMware ESXi 5.1 in conjuction with vSphere Client which allows me to manage my servers from my laptop or gaming pc or whatever I have the client installed on. Holy crap that was a tangent. DNS. Right. So I looked at Bind9 and wanted to curl up in a corner and die so maybe I'll find something a little more user-friendly.

- HP iPAQ hx4700 Project -

I've been a little overwhelmed with the amount of nonsense it takes to get Debian onto this little guy. The whopping 59MB of RAM on this PDA will make things difficult. And the ~2MB/s transfer speed limitation on the SD and CF card bus is downright painful. I've read that some people have had much better luck using lightweight distros like Angstrom on this PDA. Maybe something even lighter such as DSL (Damn Small Linux) will be an even better choice! I'm still in the “planning” stage on this one. I've been having more fun with the other things above…

Week #5

PROGRESS. I love progress. And French Toast Crunch. But that's not sold in the US anymore and I'm not willing to pay ~$20 to have a box shipped down from Canada so I'll just stick with progress for now.

- DIY Home Security System -

I found an extremely convenient VMware Virtual Appliance of ZoneMinder that some wonderful soul built and shared with the world. It's Ubuntu Server 12.04 LTS at the base with a lot of extras stripped out and ZoneMinder pre-installed and ready to run. Within the vSphere Client, I connected to my secondary server, installed the .OVA file (“something” Virtual Appliance - I assume) and I had a nice little VM all ready to boot. I allocated 3GB of RAM (the guy who built the template used x86 Ubuntu Server… blegh) and 2 processor cores as well as ~40GB disk space for recordings and whatnot. Upon booting the system, I changed the default login and updated everything using apt-get. I named the server HomeSecurity1, also. So, with the ZoneMinder process running, I can navigate to (from within my network) http://HomeSecurity1/zm and access all of the settings and config stuff for ZoneMinder! Nifty. I haven't gotten around to adding the camera yet, but I will soon. I haven't really had the time to dabble through all of the super-granular settings within the ZoneMinder web interface.

The camera is a Samsung Intercept with Android 2.3 running on it. I debated rooting this phone and putting Cyanogenmod or something else on it but decided I would stick with Stock Android with the hope of better stability. The app IP Webcam is streaming to the static IP that I set in the Android Settings and the port that I chose for IP Webcam. All I need to do is point ZoneMinder to that IP and port and configure the motion detection stuff. SOON.

- Lightweight Linux DNS Server -

So I found something called dnsmasq which is an extremely lightweight DNS and DHCP server for Linux. I won't be using DHCP since my home router is currently handling this (for the sake of simplicity and compatibility) and I don't plan on using it down the road either. I created a file in /etc called dnsmasq.conf that will be referred to when dnsmasq is run. It tells dnsmasq to look at a file called hosts.dns in /etc that lists all of the DNS entries. I pointed a few systems to 192.168.1.25 (the address of this new DNS server) and tried some pings. No luck. I'll troubleshoot a bit and see what I can come up with.

Wedge to the rescue! The config file I created for dnsmasq isn't picking up the custom hosts.dns file that contains all of the DNS entries for my network. That's what SHOULD happen but instead the file has to be called on in an argument when running the dnsmasq process. So, now everything works! I pointed all of my systems to 192.168.1.25 for their DNS nameserver and I can successfully ping all of the systems on my network that are listed in the hosts.dns file! The only problem is on my Windows machines. Whenever I ping or attempt to contact a system in the hosts.dns list, I have to include a period after the name for the DNS name to happily resolve to the IP address. Some research on this suggests it is in regards to the domain name or the lack of a FQDN. I can tolerate this for now but maybe I'll look into that later.

- HP iPAQ hx4700 Project -

Meh. Not this week. I'm more concerned about the stuff above. Maybe next week…

Week #6

- DIY Home Security System -

After hosting the IP Webcam from the Android phone, I added it into Zoneminder

Week #7

Week #8

Week #9

Week #10

Week #11

Week #12

Week #13

I dedicated a majority of my LAIR time to cleaning and organizing with Pressly during this week.

Week #14

EoCE

1)
i=0;i<10;i++