Archive

Tag Archives: Scripting

Often, when using linux, there are times when you need to re-use a long-winded command on a regular basis. Wouldnt it be nice if you could configure your system to carry out that command with just a simple keyword commmand?

Well luckily for us, we can. let me give you an example. The command i use if i want to watch a video within the framebuffer (ouside of X) is as follows:

sudo mplayer -vo fbdev -fs -vf scale=800:-3 /name/of/video.avi

There is no way i’m going to remember that everytime i come to watch a video… Now sure, i could save this into a txt file and grab it when i need it, or even write a script to handle it, but there is a more elegant way. Use an alias.

An alias is just like giving your own unique name to a command for simplicity. I want my alias to be ‘clivid’ so that i can type ‘clivid /path/to/video.avi’ and the computer will do – ‘sudo mplayer -vo fbdev -fs -vf scale=800:-3 /path/to/video.avi’

Heres what you do: open a terminal emu, type

sudo leafpad ~/.bashrc

Or whatever txt editor you use if you dont like leafpad.

You will be confronted with your .bashrc file. Scroll to the very bottom, this is where we will add the alias

First add a comment so you know what the alias does my case its:

#Alias for opening mplayer within framebuffer

Next is the line which actually adds the alias

alias clivid='sudo mplayer -vo fbdev -fs -vf scale=800:-3'

its that simple. You type alias nameOfAlias=’bashCommand’

Save the document, and you’re almost finished. You must recompile .bashrc, type:

source ~/.bashrc

Now test out your new alias on the command line – good luck!

Advertisements

You know what its like, you have an idea for a script or program you want to write, and then sure enough, someone else has already done it better than yours would have been anyway…

This happened to me just now. I wanted to write a program or script that would sign into my xbox live account via www.xbox.com and report back the online status of my friends.

Well, it turns out a very nice python program already exists in the form of XBL Status. Nowl how about the ability to integrate this into conky, and then its perfect.

XBL Status is action - not my screenshot, i grabbed this from the official XBL Status ubuntuforums thread

XBL Status is action - not my screenshot, i grabbed this from the official XBL Status ubuntuforums thread

Windows users can check out this program: XBList

and Mac users can check out: MacLive

I’m running crunchbang linux on my EEEPC 900, and i recently had a sudden urge need to do a couple of calculations.

As far as I am aware, there isn’t a calculator app built into #!

But then i remembered python programming 101 – use the python interpretter as a calculator!

python interpretter used as a calculator

python interpretter used as a calculator

Just open a terminal, type python, hit enter (pre installed on practically every distro i’ve ever encountered), then just type in the sums, you dont even need to know any python, its common sense. extremely handy!

I just threw together a quick shell script to automate the process of unraring multiple rars.

enter a directory containing rars to be extracted, a password if required, and just walk away =)

enter a directory containing rars to be extracted, a password if required, and just walk away =)

The script searches for all .rar files within a user specified directory and then one by one applies an unrar command to each. The script will work for passworded archives too, or if they have different passwords, enter one at a time

Currently split archives are not supported by this script, so be warned.

If you use a lot of rar files, or are a rapidshare user, take a look and try it for your self

echo "Enter path of dir which contains rar files for extraction"
read thedir

echo "The script will now attempt to extract the following files"
ls $thedir
echo "if these files are password protected, enter password now... (if not, type 0)"
read $rarpass

if [ "$rarpass" == 0 ]; then

	for f in "$thedir/*.rar"; do
			
			unrar e -v $f
	done
	

else

	for f in "$thedir/*.rar"; do
	
			unrar -prarpass e -v $f
	done
fi