Tuesday, December 28, 2010

Pandora via Command Line

I came upon a rather interesting article pointing out a command line interface for the pandora.com radio service.  I believe on lifehacker, but it didn't quite work for me, so I thought I would throw together something to remind me, and to perhaps help out others, on how to do it later.

The program is called pianobar, and seems like a rather cool program. 

So, first thing you'll need is the compilers and make.  This is usually apart of Ubuntu, but incase it's not, try:

sudo apt-get install build-essential


And that should get the basic programs installed. 

Next, we need the libraries that piano bar depends upon.  To get these: 

sudo apt-get install libao-dev libfaad-dev libmad0-dev

Lastly, we'll need the program source itself.  To get this, I went to the git-hub, and downloaded the archive.  It has several versions of the pianobar, and in either .zip or tar.gz:

https://github.com/PromyLOPh/pianobar

So, then extract the archive, shell to that directory, and run "make".

You can either leave the pianobar executable that is made there, or do:

sudo cp pianobar /usr/local/sbin

To put it in a place where the shell can find it no matter where your current working directory is.

And then it's just a matter of running it, entering your pandora username and password, and rocking out. 

Friday, November 19, 2010

Check that off my to do list.

So, it just goes to show that a simple google search could turn up an answer to most things.  In this case, a shell function I felt was missing.

That is, I wanted to be able to cd into a directory, and then have the files listed automatically. I had attempted to try this myself.  First thinking of trying an alias, then trying to write a shell script for it.

As I found out , and a forum poster pointed out, a shell script would print out the ls of the target directory, but the cd function would actually change the current working directory of the shell script, not the terminal that ran it.  It might be possible to write a script to change the calling terminal's current working directory, but it is beyond my scripting skills.

So, after googling here is what I found.

Add to your ~/.bashrc ( or if you have one,  ~/.bash_aliases ) file the line:

lcd() { cd ${1} ; ls ; }

To get a basic ls after a cd. Then restart your terminal, if you had one running, and give it a try.

Or if you are like me, you might want a more detailed ls after cd, so I implemented:
lcd() { cd ${1} ; ls -hl; }


 Which has it list details about the directory with filesize listed in k, M or G sizes. 



So, the googled idea is very elegant, and works well.  

Good night, and good luck.

Tuesday, November 16, 2010

Interesting wireless tidbits ( Ubuntu )

On HP laptops, the module hp_wmi is used for processing hotkeys related to the wireless.

I was running into an issue where after shutting down my laptop's wireless with the button, it refused to start back up again, with the same button.

So after a bit of research, I found these things to be useful .

Command 1: rfkill
Very Important tool for wireless. 
     - rfkill list - Lists the states of the various wireless devices.
     - rfkill (un)block <index> - blocks or unblocks the wireless device listed at the index.

Command 2: lsmod | grep <snipit of module name >
Looks through the modules installed in the kernal for the name. Useful in this case to see if hp_wmi is installed.

Command 3: sudo modprobe <module>
Activates module in the kernel.

Command 4: sudo modprobe -r <module>
Removes module in the kernel.

So, as soon as I added hp_wmi using modprobe, it started working again.

Also, to make sure it is run at boot, add hp_wmi to a new line of /etc/modules using your favourite super user powered text editor.

Monday, November 15, 2010

Firewall script snippets

#This is going to drop packets that claim to be from the loopback interface but
#are coming in on a physical network interface. These packets are clearly
#spoofed and should be dropped.
#$IPTABLES -A INPUT --in-interface ! lo --source 127.0.0.0/8 -j DROP
#above is the version that yields an error, use the one below instead
$IPTABLES -A INPUT --in-interface $EXTIF --source 127.0.0.0/8 -j DROP

#This line prevents the smurf attack, which depends on flooding a
#network with ping requests. We can prevent this attack by only allowing
#one ping request per second.
$IPTABLES -A INPUT -p icmp -m icmp -m limit --limit 1/second -j ACCEPT


#We also want to drop any packets that have TCP flags that don't make
#any sense. To really understand these lines, you are going to need to
#understand the TCP protocol and that is beyond the scope of this video.
#All you really need to know is that the TCP protocol allows different
#flags to be set, and we are going to drop packets where the flags
#contradict each other or otherwise don't make logical sense.

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags FIN,ACK FIN -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags ACK,URG URG -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP

Sunday, November 14, 2010

Adding Scripts to run at Boot ( Linux )

Running a script at boot is sometimes very important.  You, the user, can decide which programs run on log in to your account via the "start up applications" system menu. 

However this doesn't do system wide scripts.  A good example of one that would be an important system wide script is a firewall script.

To get this to run as linux boots up, copy the script to /etc/init.d/.

Then, run the command
update-rc.d <script file > defaults

Saturday, August 21, 2010

Productivity in Linux

In the spirit of the coming school year, I thought I would share something linux can do for productivity.

Calender on your Desktop:

Recently I happened upon a tutorial on how to embedd google calender on to your linux desktop. The full tutorial is on Make Tech Easier, and involves several linux applications, but they all come together to be quite cool. 
Conky on my computer, with system stats and calender.

The first required application is called Conky, and is a framework that allows for many combinations of system monitoring.  It can be displayed either on the desktop, or in it's own window.  

To get conky, if you have some form of Ubuntu, the simplest way is to run in a terminal: 

sudo aptitude install conky

The main file for configuring the display is .conkyrc,  and it needs to be created in the home folder.  There are many example .conkyrc files out there, and I will post the contents of mine at the end of this article, for those interested.  

The next main part for this to work is the google calender command line interface, which can also be found in aptitude.  

sudo aptitude install gcalcli 

The important file here is .gcalclirc, also found/created in your home directory.  

Inside .gcalcli there needs to be three lines:
[gcalcli]
user: <google user>
pw: <google password>

After this file is configured, you can run several commands from the bash terminal  without entering your calender username and password.  

Some example commands are: 
 
gcalcli calm   (displays the month)
gcalcli agenda (displays the dates and times of the next 3 events)
gcalcli calw 2 (displays the next 2 weeks)

To display it in a conky file, the line is

${execi 300 gcalcli --nc --cals=owner calw 4}

Which runs the gcalcli command once every few minutes.  And thats all you should need.  As promised, my .conkrc file follows this paragraph.  I like the way it ended up because it should be able to move between installs of Ubuntu without modification because it doesn't call on hardware specific status indications. 


.conkyrc:
 
alignment top_right
background no
border_width 0
cpu_avg_samples 2
default_color white
default_outline_color white
default_shade_color white
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
use_xft yes
xftfont DejaVu Sans Mono:size=10
gap_x 5
gap_y 60
minimum_size 5 5
net_avg_samples 2
double_buffer yes
out_to_console no
out_to_stderr no
extra_newline no
own_window yes
own_window_class Conky
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
stippled_borders 0
update_interval 1.0
uppercase no
use_spacer none
show_graph_scale no
show_graph_range no
text_buffer_size 8096
   
TEXT
${color #00ff00}$alignc$sysname $kernel on $machine --- ${color #00ff00}$alignc${exec whoami} @ $nodename
${color #ff0000}$stippled_hr
${color #ff0000}Date: ${color #00ff00}${time %A,%d %B} ${color #ff0000}Time: ${color #00ff00}${time %k:%M:%S}${alignr}${color #ff0000}Uptime: ${color #00ff00}$uptime
${color #ff0000}$stippled_hr
${color #ff0000}CPU: ${color white} ${cpu cpu1}% ${cpubar cpu1}
${color #ff0000}RAM: ${color white} $memperc%  $mem/$memmax $membar
${color #ff0000}Swap: ${color white}$swapperc% $swap/$swapmax ${swapbar}
${execi 300 gcalcli --nc --cals=owner calw 4}

 

Saturday, August 7, 2010

LSOF

lsof -P -i -n | cut -f 1 -d " " | uniq | tail -n +2

Narcoleptic9 stumbled into a linux command that allowed him to view what applications were using internet connections. Open up a terminal and paste the command. For more information, you can check out the man page. You may want to verify with netstat as well. Can you do this Windows?