Linux Customization With .bashrc

This post will explain what a .bashrc file is and how it can be used to customize your usage in a Linux environment. It will explain what alias and export are used for. Also it will explain how easy it is to create functions. Finally, to tie it all together, it will explain how to set up a colored system-status display that will be shown when you first log into your machine via the command line.

What is a .bashrc file?

A .bashrc file is a startup configuration file used with the Bourne-Again SHell (Bash). Bash is the most common shell on Linux systems, as far as I know at least; I would also assume it is on OS’s like Solaris and Mac OSX too, though I .

What is a .bashrc file used for?

The .bashrc file is used for personal aliases of commands, think shortcuts, and user-functions.

Some quick example .bashrc files

This Novell CoolSolutions page on configuring the .bashrc file is what prompted me to write this entry. This is a fairly lengthy .bashrc file example. You may also just want to google for more examples.

Aliases, Export, Functions, etc.

Alias

You can think of an alias just like you think of a shortcut on your GUI desktop. Effectively they are no different. Isn’t it easier to type something like web instead of cd /opt/lampp/htdocs. If I wanted to, I could have even shortened the alias to just w. Aliases allow you to quickly move around your system as well as execute complex commands with ease.

Export

The export system command can be used in a similar manner as alias. The main difference is that when using export, you create a system variable. An example of this usage is updating the default PATH system variable. For example: export PATH=$PATH:/sbin:/opt/lampp/bin/. This updates the PATH variable to include, what else, other paths. Programs, really the whole system, can access the value of this system variable by referring to $PATH. I mentioned that exporting variables can be used in a similar manner as an alias. An example of this would be creating a system variable called WEB, i.e. export WEB=/opt/lampp/htdocs. On the command line simply execute cd $WEB. This has the exact same effect as having the web alias mentioned above.

Functions

Understanding functions is really quite simple. A function simply wraps around a code block of system commands. An example will probably do the explaining for me:
netinfo () {
echo "---------------- Network Information ----------------"
/sbin/ifconfig | awk /'inet addr/ {print $2}
echo ""
/sbin/ifconfig | awk /'inet addr/ {print $3}
echo ""
/sbin/ifconfig | awk /'inet addr/ {print $4}
echo "------------------------------------------------"
echo ""
}

This block of code, this netinfo function, simply outputs my network information with some nice formatting. From the command line, all I’d have to do is type netinfo.

An example to put it all together

I will put the code here that will allow you to set up your own ‘Welcome / System Status’ display upon logging into your computer via command line. My comments and explanation of what is going on will be shown as comments in the actual code. At the very bottom will be a link to my actual .bashrc file which will include everything I’ve mentioned here.

# WELCOME SCREEN
#######################################################
clear; #remove anything above this welcome screen
for i in `seq 1 15` ; do spin; done ;echo -ne "${WHITE} Welcome to Apache01 ${NC}"; for i in `seq 1 15` ; do spin; done ;echo ""; # this will display a header
echo -e ${LIGHTBLUE}`cat /etc/SuSE-release` ; # this shows some information about my machine itself
echo -e "Kernel Information: " `uname -smr`;
echo "";
echo -ne "Hello $USER today is "; date
echo -e "${WHITE}"; cal ; echo ""; # some date / calendar info
echo -ne "${CYAN}";netinfo; # network info
mountedinfo; echo ""; # filesystem info
raidinfo; echo ""; # RAID info
echo -ne "${LIGHTPURPLE}";fortune; echo ""; # and for a little fun, a fortune
echo -ne "${LIGHTBLUE}Uptime for this computer is ";uptime | awk /'up/ {print $3,$4}' # machine uptime
for i in `seq 1 15` ; do spin; done ;echo -ne "${WHITE} Welcome to Apache01 ${NC}"; for i in `seq 1 15` ; do spin; done ;echo ""; #ending header
echo ""; echo ""

My .bashrc file

A note about the code snippets you see here: I do not claim to be the originator of all this code you see here. Though, much of the code can be found in various places around in the intarweb. Also, if you happen to see anything incorrect, please let me know!

And a question for my those who read this: What interesting things do you have in your .bashrc file?

WordPress Plugin: Page Access

[UPDATE #2]
Updated to version 1.2
[END UPDATE #2]

[UPDATE]
Updated to version 1.1
[END UPDATE]

I now present my second WordPress plugin – Page Access.

This plugin allows the creation of page groups and then allows users to be associated with the groups. If the page is in a group that is associated with the user, then the user is allowed to access the page. Otherwise, they are redirected to another page which is specified on the Page Access admin panel. Personally, I just created another page explaining what is going on – saying that they don’t have access to this page and to contact the admin. If you do it this way, be sure not to restrict that page!

Also, this plugin is used in conjunction with my Page Restriction plugin. That plugin restricts certain pages to logged in users.

This is my biggest plugin to date, so let me know what you think!

WordPress Plugin: Page Restriction

[UPDATE #3]
Updated to version 1.4
– There should be no more errors on install or activation/deactivation.
[END UPDATE #3]

[UPDATE #2]
Updated to version 1.3
[END UPDATE #2]

[UPDATE]
I’ve updated the plugin. I’m now at version 1.2.

Here is the changelog:
v1.2:
– added code check for the Page Access plugin, only used if installed

v1.1:
– used built in WordPress function dbDelta() to update database structure
– changed name of options subpanel

The link is the same, but the .phps file has been updated

Enjoy!
[END UPDATE]

I know I haven’t posted in a long time and I’m sorry. I’ve been… lazy? busy? Sure, those will work. I would also like to sincerely appologize for the complete and utter disarray that this site is in – don’t worry, I’m working fixing all that.

But on to the point of this post…

Because I’m using WordPress as a Content Management System for our up-coming intranet/web-app at work, I needed a way of keeping the regular folks out of our private section of the site.

So, I wrote this plugin – Page Restriction – and it does just what it says, pretty much. It will add an Administration panel under the Options section, entitled Page Restriction – Clever huh? There you can pick and choose whatever pages you want restricted to logged-in users.

You may download the source here: https://17thdegree.com/wp/page-restriction.phps

Any questions, comment here.

FBI Scraping Half Billion Dollar Program

For reference, you should probably read this Yahoo article first.

Now my commentary…

Gotta love our government. Half a billion dollars down the tubes. I love how they’re still working on this program yet they’ve started soliciting offers for a new program to replace it at the same time.

And you know what the program does:

The prototype’s main feature allows users to prepare documents and forward them in a usable form.

and

Eventually, the FBI expects to have software with added features for managing records, evidence and other documents, along with the ability for users to collaborate on documents and share information online.

Jesus! What about this project can’t be done via the internet? Seriously. Prepare documents and forward them in usable form? What the hell is that? Sounds like email to me. Collaborate on documents and share information online? That just sounds like something you could just put on an encrypted network and then have like a Wiki or something along those lines, combine that in with the emailing of documents (mind you it could be heavy SSL or an equivalent).

I dunno, I just don’t get our government some times. This is my rant for the day.