Tuesday, March 8, 2011

Remote rhythmbox playing...teeheehee


This is awesome. I already have a very good use for this method as you will soon see...waking up my house mates by ssh-ing to my home computer and turning on Rhythmbox, and turning it on loud!

So I really just wanted to be able to play music from the terminal. Mainly, so I can do this on a remote computer via ssh. I thought it was a crazy idea and not possible, but how wrong I was. I soon realised also, that Rhythmbox probably isn't the most process efficient program to run, but hey, it was straight forward, and did what I wanted it to do so I'll stick with it for now.

This is a guide to running a program on a remote machine over ssh.

Firstly, you'll need to ssh to the desired computer. Many docs on how to do this. I used a variant of the following command with no -X option.

ssh me@192.168.1.1

Enter the password for 'me' on the host. Then, type the command below, I lost the link to where I found it sorry.

export DISPLAY=:0.0

When you press enter, nothing will happen. However, you have just given ssh somewhere to direct programs that require a GUI. This command is also used if you want to direct the program to display on the local computer, but instead of using 0.0, another option is used. This is a little more complicated though and some files need to be edited.

Ok, so to test that you can get a program to start-up, try xeyes.

xeyes

Much easier to know if it works if the computer you are ssh-ing to is right beside you. So now that it works, we want to get rhythmbox working. The command is:

rhythmbox-client

This opens rhythmbox and then allows users to send commands to the client via terminal. To find a list of options, run:

rhythmbox-client --help

Lastly, point your terminal to the folder where all your songs are located, and queue them like so:

rhythmbox-client --enqueue FOLDER-NAME

Vuola! Use the --play and --next options to get to the songs you want to play. Of course they have to be in the playlist to play.

I will probably find an easier method for playing songs soon, but hey, this works for now. The only problem I've run into thus far, is if you add a folder, it adds all the files that are in that folder, documents, images etc. Possible solution, run an ls with a grep option to select only song files. It should work, will try it soon.

Thanks and have fun waking up your neighbours!

Saturday, February 26, 2011

Setting up a server, the nanoTux way!

Good evening. I think I've built up enough oomph to attepmt AGAIN to setup a server. Using the nanoTux guide, http://nanotux.com/blog/the-ultimate-server/, I'm really hoping that it works and that I haven't gone insane by the time I reach the end of the HowTo. This guide was found on the Ubuntu Forums website in the Server Platforms area and seeing as it's had almost 27000 views, I'm sure it's the real McCoy.

For a complete HowTo, go to the address given above as this post will simply be making references to the code I use, and any workarounds that I implement. Begin! Shit...no coffee, plunger is missing...

To be continued...

Sunday, February 6, 2011

Just some useful stuff: bash networking commands


After all that clicking and scrolling for my last post, I ended up finding several other useful commands. Most of them are to do with networking and I'd just like to have them handy. Here goes.

Display total space and availability:
df -h

Display size of a folder, a couple of options here, may need to be sudo:
sudo du -hs /path/to/folder
sudo du -chks /path/to/folder

IP Scanning with range 192.168.1.1-192.168.1.254:
sudo nmap -sP 192.168.1.1-254

Scan operating system on target IP (cool!):
sudo nmap -O 192.168.1.3


...and that was all!

Ubuntu and Windows: admiring how they share


Up late again but I've struck some success. I've just found a neat little way to access a share folder located on a windows box on your current network. This will no doubt be a short How-To since it's 12:44AM and I didn't fall asleep till 3:30 this morning because it was so hot, great.

So, basically, you have a network, and because you are leet, you run a Ubuntu machine, but of course someone else will be running Windows (and others maybe even a Mac, God help me if I have to figure that out). If you have used Windows, then you will know that there is a somewhat simple way to setup folder sharing, but this requires you to be connected via a cable to the network. Not sure why.

To share a folder in Windows with the rest of the network, you just right-click on the folder you wish to share, then Properties > Sharing Tab > go down a bit. Then, you might see "Network Setup Wizard" or you'll see two check boxes:
1-"Share this folder on the network" and
2-"Allow network users to change my files".
If you see the wizard, then you need to follow it through and hopefully select everything correctly; there's a guide here at the MS site. For you (the leet user) to be able to access your mates'(clueless drongo) computer, both of these boxes must be ticked. And I'm sorry, but you can't do this without the owners consent...

Just to check if you or your friend have done the setup right, the shared folder will come up in Network Places (I think, not using Windows atm) under the workgroup that you chose in the wizard.

Ok, so the folder is being shared, how do I access it from Ubuntu? Well the simplest way is to just click there by going to Places > Network. It might take a while to load because it does some sort of search. The other way to access it is from the command line, useful for those who want to move stuff from a dead server box that doesn't have any USB ports! Lol...

I'm running Ubuntu 10.10 and I didn't have any dependency problems but that may be different on other distros. There are two packages, CIFS and smbfs which can be used to mount local machines to a place on your computer. Currently, it seems that they can only mount machines that have a wired connection. Maybe something to do with too many fingerprints...not sure.

Create a mount point on your computer first: I went with /mnt/test. But any will do.
sudo mkdir /mnt/test

Now, assuming that you know the IP address of your mates computer and have already obtained their username/password, run the following command for CIFS:
sudo mount -t cifs -o username=drongo,password=password //192.168.1.1/shared-folder /mnt/test

And for smbfs just remove the -t cifs:
sudo mount -o username=drongo,password=password //192.168.1.1/shared-folder /mnt/test

If they didn't use a password, just leave it out and when it prompts for one, just hit ENTER. I did run into one hiccup and I'll just voice that here. The IP address that you use has to be the address of the wired modem not the wireless modem, otherwise it won't work. That's it. I'm sure I've left some other important information out so please correct me if you find it.

Other than that, the folder should now be accessible at /mnt/test for you to copy, write, delete or even put stuff there. Maybe you're a nice friend and you want to give them some music? It's possible.

Don't forget to unmount!
sudo umount /mnt/test

Friday, January 28, 2011

Quick styling




Quick styling no embedding!

<style type="text/css">
pre.source-code {
  font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;
  color: #000000;
  background-color: #eee;
  font-size: 12px;
  border: 1px dashed #999999;
  line-height: 16px;
  padding: 10px;
  overflow: auto;
  width: 100%
}
</style>

<pre class="source-code"><code>Quick styling no embedding!
</code></pre>

Quick styling embedded! 

Getting a VM to work...the hard way


What am I talking about? I still don't really understand the concept of a computer running inside a computer. And I don't mean a laptop running inside a desktop case! I'm talking about Virtual-Machines. Loading an OS from a recently acquired image and then making it run in the background of an already running OS. Sounds like I might need a faster computer. Or get some liquid N2 and just frost up the bottom of my laptop. At least my palms wouldn't get hot. It does sound like a bit much.

Kernel-based Virtual Manager looks like a decent package. A bare bones kind of software that hopefully won't weigh down the running system. Problem is that I don't know how to use it, and I think that it runs from a command-line, which is what I want. There is an ever-so-useful HowTo at there site, and I'm testing that the procedures do work as I type this. I should go to bed.

Install the packages below as a start.
sudo apt-get -y install kvm qemu bridge-utils uml-utilities
sudo modprobe kvm
sudo apt-get -y install libvirt-bin
sudo apt-get -y install virt-manager

The last one is meant to be some sort of GUI but I have no idea how to use it, yet. The modprobe line reloads KVM without having to restart your computer, even though I've restarted mine several times before even getting this far.

Next, is you'll want to create a disk image for the guest-image, or in other words, a place where the virtual machine will live/sleep. From what I gather, Qcow2 is some sort of tool which creates a standalone image from a cluster of memory which is then scanned by the header when it needs to be read. I don't know. It's a thing. Create one like this:

/path/on/computer/where/it/will/live create -f qcow2 imagename.img 10G

Qcow2 will do it's thing, the last paramater is the size of the image, 10G -- I haven't played around with this much. When you have finally downloaded your Free and Open Source Linux distro that you so desire, just go ahead and install it.

sudo qemu-system-x86_64 -hda imagename.img -cdrom /path/where/.iso/is -m 512

There is meant to be some sort of read error and the host os will be unable to determine if the system you are installing is 32 or 64 bit, so by assigning qemu-system-x86_64 as the pathway, no one gets confused. Although, it might actually be part of the command, not sure. The final -m tells qemu how much RAM you want to allocate to the VM. I'm finding out now that maybe I should have used -m 1024, 36mins57s remaining...uhg!

1:29:40AM - Still waiting...

1:34:46AM - Meanwhile, test that the printer works

1:49:05AM - Printer works, going to bed, check the install in the morning.

5:35:19AM - Still going, stupid WINS param...

8:54:24AM - Yay! It's working! I'm now running Debian 2.22.3

Lastly, when you need to start up the VM from scratch, it is a simple call of the OS file created and the image memory, or whatever you want to call it. As you will probably find out, it's much simpler to create a directory and store both of these files there, that's what I did.
qemu-system-x86_64 -hda /path/to/imagename.img

So that's it. The system seems to be working fine. I have somehow lost track of where the KVM functionality is taking place, as Qemu seems to be doing all the work. My understanding of KVM has been rewritten, again - I must have missed something.

Sunday, January 2, 2011

Creating an autorun script for when a specific USB device is plugged into your Computer

Much of my information came from this thread, very helpful: http://ubuntuforums.org/showthread.php?t=502864

Several steps are involved and several locations will be accessed heavily. These are:
/etc/udev/rules.d - where the .rules file will be kept for the computer to access when the USB device of choice is plugged in, this ultimately points to the script file below
/usr/local - or wherever your script file is located.
/home/... - any other places where script files that will be used are stored, python, C etc

/etc/udev/rules.d
A README file is available in this folder and it is helpful to read. You will need to create a file here which will be picked up by your computer and read when an action occurs.

The file must begin with two digits followed by a - and end with .rules, 70-filename.rules. It will contain the following script:

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0d49", ATTRS{idProduct}=="7350", RUN+="/usr/local/script_file.sh", SYMLINK+="my_device"

If you are lost, just take a look at the files in /etc/udev/rules.d and make a similar filename.

To make it work for a specific device, with the device plugged in, run lsusb in a terminal and find the device Vendor and Product numbers. For the Kodak Co. device below, Vendor is 040a and the Product is 0576:
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 040a:0576 Kodak Co.
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000

The RUN+= is the location of your script file. It is very important that this file has user executable permission as well as for all other .py files etc that will be used by the script. To do this, go to the directory with the file and run:

$ sudo chmod u+x filename

and check the permissions with

$ ls -all

It should be: -rwxr--r--
These are the permissions that work for me, I'm not sure if this is across all platforms.
The location of the script file is not important, but make it an easy place to remember. SYMLINK+= is a feature I'm not familiar as yet, however it does allocate the device to the variable given to a spot in the /dev folder, /dev/Maxtor.
The ATTRS before {idVendor} and {idProduct} can be changed to SYSFS if the device is not being recognised once plugged in. This can only be tested by you and your product, although there may be better explainations about this.

The SUBSYSTEM variable can be left out completely, however it does give useful information to the computer. Other variables such as usb_device and pci... exist but usb is the one that works for me.

At first, it is advised to make the script file a simple copy code like a cp command of a file you know to a place you know. If after you plug in the device, you find that the file has been copied to the new destination, you can be sure that the .rules file has been successfully read. This is definately the hardest part of the setup of this 'autorun' script.

Before I wrap things up, I did want to add a work-around for the .sh file, the file pointed to by the .rules file. I had problems when plugging in my device because the .sh file would read first, and then any other code already on the computer would read last. This was a problem because I wanted to point to a folder on the device but the device hadn't been mounted yet. I could have mounted it myself but I ran into a dead end. An alternative was using the sleep command followed by my code, inside some curly braces {}, looking like this:
{

sleep 5
cp -ar /a/folder/on/my/computer /folder/on/device

} &

The {} tells the interpreter to read to code, but run it in the background. With the sleep command, there is a 5 second pause while the computer runs it's usual code of mounting the device. After the 5 seconds it now copies the folder to the location on the device.

If you have a know fix for mounting a device manually using the /dev location, I'd be happy to hear. I'm now using this method to auto update my Uni files on my external HD whenever I plug it in. This is my first How-To so enjoy, rate, comment.