Monday, February 3, 2014

Minecraft on Linux - Minecraft Forge mods

OK, so you have Minecraft and you want to mod it.  This technique is for the Minecraft Forge mods.  This is supposed to make things easier for you and certainly it does compared to the old way which I will post later.


The idea is that rather than slamming files into Minecraft.jar you instead create a directory (folder) under your .minecraft directory called mods and stuff the zipped mod file in there.  Easy right -- that is until you realize you have a few more things to do.


1) create a mod directory under your .minecraft directory

mkdir /home/(user name)/.minecraft/mods

Remember a dot in front of a file name is Linux's way of hiding the directory.

2) Install Minecraft Forge.

You can find the link at

files.minecraftforge.net

Select (installer) and the latest version.  As of this writing, it works with Minecraft 1.74

Download the zip file

TIP:
IF you have a lot of adblockers you won't get past adfly but if you

(a) copy the link location by right clicking on the link
(b) pasting the link in a new window (don't hit enter)
(c) deletting everything until you see http:files... the first few entries of the header are for adfly

Now you are ready to install the zip file.

From the command line (terminal), move to the directory of your file...wherever you stored it.  IF it is the desktop, just do

cd /home/(user name)/Desktop  <use capital letters as you see for Desktop>

Now type

java -jar (name of your Minecraft forge file.

This will execute the java file and install minecraft forge.  Always remember to select 'client'

Now run Minecraft, and you'll see a new profile called 'forge'.  Select that profile and you should see your mod in action.

Whew...




Minecraft on Linux - Texture packs

Texture packs

Of all the things that Minecraft is known for, documentation is not one of them.  As a matter of fact, I found the documentation a bit confusing.  Part of the confusion is the fact that Minecraft has a multitude of versions with varying degrees of success. 


This documentation is written for 1.74


1) Download a texture pack.  This can be confusing as you may be stuck on a lot of ad sites.  Be careful and pick from Minecraft.org.

2) Copy whatever zip file you have...AS IS to the .minecraft/resourcepack directory.

3) Launch Minecraft

4) Select options and texture packs and pick the texture pack from a list. 

You are done.


NOTE:
If you get stuck on Addfly, you can easily bypass it by copying the link to a new browser window and deleting the first part of the URL with addfly in it up until the http:

Good luck.

Monday, April 15, 2013

VIm and plugins

KNOW - basic VIM
basic command line unederstanding.

VIM is probably one of the most misunderstood and under appreciated text editors available.  Known as the learning curve from hell, vim though is incredibly popular because it's so powerful and so customizable -- and yes HARD TO LEARN.

Today, I want to talk about plugins.  For the uninitiated, plugins for Vim are scripts that customize vim and do some pretty amazing things.  If there is something you want for Vim chances are there is a plugin for it. 

Of course, getting plugins is easy -- once you install Pathogen. Pathogen IS the plugin manager for the modern era.  SO let's start installing it.

NOTE:
~/ is a shortcut to the home directory.  If your name is Fred.

/home/fred
$HOME 
~/ 
 
all mean the same thing.
 
mkdir -p ~/.vim/autoload 
 
mkdir -p  ~/.vim/bundle 
 
curl -Sso ~/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
 
Easy.

First, we make a new directory.

Vim uses .vim, a hidden directory (ls -al in case you don't know how to list directories that are hidden) and store them all in autoload.  That's where pathogen is going to store pathogen.
bundle is where ALL plugins are going to go from now on.

NOW...that we have pathogen installed, add pathogen to the .vimrc file.

(in case you don't know it, .vimrc is the hidden file that you can use to customize the look and feel of vim.

 "---------------------------- Load pathogen ----------------------------"
execute pathogen#infect()
syntax on
filetype plugin indent on
 
DONE!!!!!!!!!!!!!
Now let's grab some plugins.  Now I might add that the documentation I've personally found tends to say -- just use it.  Let's be nicer.
 
the git website is where all vim plugins are stored. 
 
https://github.com/vim-scripts
 
Now let's install the tagin plugin.  

https://github.com/vim-scripts/taglist.vim

(Any website that lists popular plugins will always include a link like this so don't worry.

ONCE you get to that page, feel free to be lost.  I was :)

Now look for a link that says:

git: read only
To the right of it is an address you want to grab as you'll need it.
In this example, I'm using the taglist one.
IF it's on http (e.g. 

http://github.com/vim-scripts/taglist.vim.git

this is simply a matter of changing the http to git as in:

git://github.com/vim-scripts/taglist.vim.git <- this is what you want!!!

git clone git://github.com/vim-scripts/taglist.vim.git 
 
 
Now since this is a clone you HAVE to make sure you are in a particular directory.  Specifically the bundle directory

cd ~/.vim/bundle

 

you can add a directory path if you want but keep it consistent.  I like everything under bundle myself so...
git clone git://github.com/vim-scripts/taglist.vim.git  /fred/bob

will put it there.  WHY you would WANT to is beyond me but you can.


Incidentally, if you don't have git, grab it. 
 
apt-get install git
yum install git (etc.)

Essentially what you are doing is syncing the files on the server with your local directory.  Granted you could...copy them down, make the directories, etc. but this is far easier.

DONE!
 
Have fun!
 
 

Tuesday, April 9, 2013

useradd details

KNOW: Linux command line


Adding a user to Linux, or any Linux flavor, on the surface is easy enough.

useradd <username>

So the add the user Fred, you would do:

useradd fred

Then of course you need to add a password.

passwd fred

Done...well not really.  The problem is that a home directory, or any configuration scripts are absolutely absent.  We also don't have a group to work with.  In short, you have not much of anything but a username floating in the ether.

useradd -d /home/fred -m fred

Hmmm....that's different.

-d as this defines the home directory.  Standards are the username being the name of the home directory although there is no law supporting that option for sure.

-m will actually create the home directory.  Ya...go figure.

Skeleton files
/etc/skel  is a directory you should know about.  The /etc/skel is located at...OK you know right?  Anyway the point of that directory is to provide basic configuration files so that the user has something to work with.  This means of course you can create a set of files on your own and they will be copied to the user's home directory. 

IF you want, you can use -k and specify an alternate directory for the skeleton files.  It's up to you.


Just in case, please note that passwd <username> will add the password.

On some systems you can use :

adduser >username>

this is a much more automated and up-to-date idea so try it if you have support for it.





Thursday, March 28, 2013

Disable Enter Key from Submit on Forms

Know:
Forms, Javascript, patience.

NOTHING and I mean NOTHING has frustrated me more than this annoyance.

By default, ALL forms treat <ENTER> the same as clicking a button.  This means the moment you press enter the form is submitted.  What, but what if I have a form with multiple fields and every one needs to be entered BEFORE submission.
Sure, you could disable the enter key but wow, that's fun for the user.  Pressing tab and not enter gets old REAL FAST.  So...what do I do.

Step 1:
Disable the form.

This is pretty easy and requires NO coding.

<Form id='myform' name='myform action='dosomething.php' >

Nothing special but we need to stop submit.  We will add ONE line.

onsubmit='return false'

Now...

<form id='myform' name='myform' action='dosomething.php' onsubmit='return false'>

This essentially is taking advantage of Javascript.  If you want to hook up an event to onsubmit you can do that.  Returning false will keep you in the form.  This is great for validating text, etc.  For now though, we're just going to return false.  OH NO.  Now I will NEVER have the form submit right?

WRONG!!!!

This is the key.
Create a button that will submit the form.  We're going to add a PAINLESS function in Javascript to submit the form.  Really, it's quick.

First the function.  You can either add it to the top of your html, OR, add it to your javascript library.  For this example, we'll just add it to a script.

<script>
function SubmitForm ('IdOfForm')  // that's the ID of the form.  Handy for submitting
{
    var SelectedForm = document.getElementById (IDOfForm);
     SelectedForm.submit ();

}

</script>

OK so now you have the script.  BUT WAIT???? Where do I put it?  Well an easy solution is with a button.

<!-- this is all one line but is wrapping on this blogspot --!>
<input type='button' class='your class (optional) value='Save' onsubmit='SubmitForm(this.id); return false;"></input>

The return false is VERY important.  Take it out and you'll have the return key submitting your form.  Try it.  Works great for me and have fun.

Too many quotes

KNOW:
php, Javascript

Ever came across this problem?

echo ('<input id='fred' ...etc)

The problem is that we have an embedded quote but you say -- no problem right?

echo ("<input id='fred' ...etc)

So far so good.  Here we have the id of the tag set to 'fred'.  We use single quotes for fred and double quotes for input...but!


echo ("<input id='fred' onclick='DoSomething ('Bob');'...mess!

The problem is that you only have two normal layers of quotes.  The single can be embedded in the double but the double...we don't have a triple.  What we do have is the escape.

The escape lets us embed as many quotes as we want with the use of the \ character.

\" means to tell the processor that we want a double quote as it.  So when PHP processes the code we will see a double quote.  This won't work for single quotes by the way.  Don't do \' and expect good things to happen.

Now...

echo (\"<input id=\"fred\" onclick=\"DoSomething (\"Bob\")\" >\" );

I agree, this takes a bit of getting used to but the advantage is that you don't have to deal with running out of characters for quotes.  It works this way.

The first quote is always \"
The second quote is always \"
The third quote is always \"

You can do as many as you want without pulling hairs.  Messy -- ya...but it works.

Javascript and the this statement

What to know:
PHP, basic Javascript.


Often times in php, I'm generating lists of objects -- specifically html objects -- and I will include a Javascript link to process the information.  That, in itself, is not my favorite option but php is server and Javascript is client (Browser).  This relationship can be a headache but here are some tips to aid the pain.

First things first.  Javascript does provide a painless way to extract information from any object -- this.  The 'this' object gives you all the tools you need to gather anything you want about an object and pass it along to a procedure. 

Example
<input id='fred' value='bob' onclick='DoSomething (this) >this is nice</input>

This is your gateway to freedom.  The 'this'.  Don't believe me?

In your function

function DoSomething (Value)
{


}


You can extract:
The ID of the object, the value of the object and the text past the object

Now, let's see how

function DoSomething (Value)
{

   alert (Value.id);   // get the ID of the object or in this case 'fred'
   alert (Value.value) // get the value of the object or in this case 'bob'
   alert (Value.innerHTML) // get the text or in this case 'this is nice'
}

Now if you're worried about extracting information about an object, you need worry no more.

I'm no expert on Javascript and try to avoid it when I can but I can't deny its usefulness.



 

Monday, March 11, 2013

VIM Registers and Macros

TO KNOW: Basic VIM beyond :w of course.
TO KNOW: how to copy/paste/delete text.
TO WANT: Make your life much easier.


Registers in VIM may be a lousy term.  A better term might be buffers.  Vim stores a variety of buffers and uses them for a variety of tasks. Copy and paste AND Macros are just two examples.

Now, if you've never seen a vim register, type this:

1) Press [ESC] ...as many times as needed to ensure you are in command mode.
2) Type ':' {minus the quotes} and reg ( :reg) or (:registers).

If you did everything correctly you should see a messy list on the screen.  Pay CLOSE attention to the letters and/or numbers on the LEFT side of the screen.

"0  (blah blah)
"1 (blah blah)
"2 (blah blah)
...
"A (blah blah)

Each of these "0, "1, etc. represents a register -- a letter representing a buffer.  So what right? Well hold on OK!

In case you are wondering...

0 (yank register), 
1 to 9 (shifting delete registers), 
_ (like /dev/null, this is a black hole), 
" (default register, hence the Ctrl-R, "), 
- (small delete register), 
/ (the search pattern register), 
: (last command register), 
a to z for your own use (capitalized A to Z are for appending to corresponding registers).


Well they are important. Really, I get it, but these really are USEFUL!

COPY A BUFFER
First, let's get the contents into our document.

The command to get into the buffers are the double quote (") vs the command mode colon. (:)  Ya, it's strange but really...we're talking VIM here.

The sequence is...

(double quote) (name of buffer) (p for paste)

You may recall that p is pasting.

So, for example we want to access the k register -- assuming we see it in reg.

"ky  (" for the register access, k for k register, and p for paste)

If you did everything right, you will see the contents of the register in your document.

SO WHAT!!!!!!!!!!!!!!
Here is why.  This is ALL leading to Macros and it took me some time to gather these tidbits.  They are all out there...in pieces of documentation.

MACROS!!!!!!!!!!
Anyway:

Let's say you have a set of keystrokes you type OVER and OVER and OVER again.  BORING!
Macro it!!!

The command for macros (assuming command mode of course (press [ESC]) is

q (name of register or  buffer but everyone calls them registers)

So to record a macro in the b register type:

qb (NO COLON!!!!)
and you should see recording

EVERYTHING and I mean everything you type is now stuffed into the register.   Now as you type commands it will be recorded but STOP...I have to stop recording endless commands!

No problem

type
q to end the macro.  YA!

RUNNING A MACRO
:@ (letter of register)  (now you can use that colon)

So in our case...

:@b

But...it go away when me leave VIM so BAD RIGHT?

Yes and we need better English for me to understand your question so let's try again

But...it goes away when we leave VIM?

That's much better.

SAVING A MACRO FOREVER
Here's how.  Using our example of qb for the 'b' buffer and assuming we have the macro.  We need to get it into a document.

type

"bp

That command (not British Petroleum by the way) pastes the b register into the document. (Remember we did that earlier)

Now, load up .vimrc.  That's a hidden file that stores commands that vim can access.  Essentially, it's a huge configuration file.  If you don't have one -- shame on you -- make one and store it in your home directory on the linux workstation.

NOW...

Copy all those messy commands into your .vimrc...and it will work right?

ALMOST

Do this:

let @b = '  (your text in between the quotes -- single quotes mind you)'

Remember the text between quotes is the text from the register

(for this you would type "bp" to paste it in RIGHT BETWEEN the quotes.  This way you make NO typing mistakes

(save the file .vimrc but you know that right :)

NOW when you run vim...ya...it's remembered.  Isn't that AWESOME.

OH YA

to access the macro remember to type:

@b  (where b is the name of the register and @ is the command to run the macro.



Sunday, February 24, 2013

Ubuntu Apache2 Can't find fully qualified domain name

TO KNOW:
Linux, VIM or any text editor.

This is a QUICK and DIRTY fix to this problem.  It works and for a local (off the web server) you can call it a day.  Lots more to do if you want to make this a production webserver of course.

vim /etc/apache2/httpd.conf

By default this is a blank file.

Add this line exactly:

Servername Localhost

Restart

/etc/init.d/apache2 restart

Cheers!

Install Imagick in Ubuntu or CentOS

KNOW:
How to setup a LAMP Webserver in either CentOS or Ubuntu
How to program in PHP
Actually have a need for this library for viewing graphic images.

What is Imagick???
Imagick, a horrible name by the way, is a great alternative to the built in GD library supplied by PHP for viewing images.  It's much faster and more structured.
Sadly the documentation to install the software is PAINFUL and lacking.  I checked many a forums and blogposts for a variety of BAD information.  It's amazing.  
Anyway, let's figure out how to do it. 

Please note I am using repositories rather than download from source as I hate involving those headaches.  I'd rather have others instead.  These have been tested with the OS in question and I personally recommend that approach

CentOS: (for old-outdated version)
By far the most work.  If you want to use the CentOS repositories, I have set this up as a script for you. This should work just fine but I honestly don't recommend it.  Imagick is horribly out of date with many basic functions not even included.


!#/bin/bash
yum install ImageMagick.386 -y

# need to investigate.  Do we need the devel.
yum install ImageMagick-devel.386 -y

# you need this and pear for the next two steps.
yum install gcc gcc-c++ autoconf automake -y
yum install pear -y

# update the pear channel
pecl channel-update pecl.php.net

# use pear to install it
pecl install imagick -y

# make a new file called imagick.ini and have one line in it to alert php of this new feature
# It will not work installing in php.ini
echo 'extension=imagick.so' > /ect/php.d/imagick.ini
service httpd restart

# just to test it from the command line
php -m | grep imagick

BUT WAIT!!!!!!!!!!!!!!
This version of Imagick ???  You might as well have downloaded the Model-T. 

TRICKY!!!!
The easiest way is to simply use a repository.  REMI is an excellent repository for the most up-to-date RPM's for CentOS  Keep in mind that you now will deal with two repositories so their are some basic bookkeeping issues here. 

1) ALWAYS use -- enablerepo=remi --disablerepo=* when dealing with this repo for installing and removing packages.  
2) Be sure to think about integrated packages.  In this case we need both php AND Imagick so we will be getting both.  You can live with the old versions of Mysql and Apache as they won't conflict. 

Now, here's the messy ugly steps you need to do.

As of 2013 this is the valid link
#!/bin/bash

# get the data to support REMI Link is valid for 2013

wget http://rpms.famillecollet.com/enterprise/remi.repo
 

# tell YUM to enable the repo
yum --enablerepo=remi

# remove your current outdated version of PHP.  VERY IMPORTANT as we don't want library conflicts.
yum remove php

# Install php and ImageMagik and pear
# NOTE --disablerepo=* we disable EVERY repo for PHP and just use REMI otherwise
# messy dependency issues reveal its ugly head

yum install --disablerepo=*  php ImageMagick2 php-pecl-imagick --enablerepo=remi
 

# restart apache
service restart httpd

# php -m | grep imagick


Ubuntu 12.04 (somewhat easier right :)

!#/bin/bash

apt-get install imagemagick libmagickcore-dev -y
apt-get install php-5-imagick -y
You went through all that work and I'm not showing you how to test it.  That's not nice.  Here's a quick and dirty test file you can generate.  I called my Test.php since I was in a hurry.


<?php

       $FullPathName = '(put your test image here. I'd recommend using the full path ';

       // setup a new image and import from file.
        $Image = new Imagick ($FullPathName);
       
        // generate a header for display
         header('Content-type: image/jpeg');

        // If 0 is provided as a width or height parameter,
        // // aspect ratio is maintained
    
        $Image->thumbnailImage (100, 0);
        //
        echo $Image;
        //
        die ();

?>




Helpful ImagMagick commands


What to know:
Php programming.
That you are insane enough to tackle photos with php

REFERENCES
// at least it gives you the function lists
http://php.net/manual/en/book.imagick.php 

// nice function list with ACTUAL examples
http://eclecticdjs.com/mike/tutorials/php/imagemagick/imagick_1.php

// nice article on EXIF info (turn off your scriptblocker to see the actual script on the blog site)
http://blog.jmoz.co.uk/imagick-strip-exif-data

For those working with Imagick and its libraries you know how 'well' documented the information is.  Well let's help you out with some valuable functions.

EXIF information
There are several, barely documented features for EXIF data in JPG files.  
$File = '(Name of File)';
$Image = new Imagick($File); 
 
// GET EXIF data 
print_r($Image->getImageProperties ('exif:*')); 
 
// STRIP EXIF data 
$Image->stripImage(); 
 
// WRITE file WITHOUT EXIF data 
$DestFile = 'Fred.jpg';
$Image->writeImage ($DestFile); 
 
// read image data 
$Image->readImage($DestFile); 

// output the data
print_r($Image->getImageProperties('exif:*'));

Wednesday, February 20, 2013

Css Tag Styles - updated

WHAT you need to know:
Basic CSS:
HTML:

My first draft, was...terrible...so I have corrected it and made it much easier and  much more complete.  Here we go!

In CSS (cascading style sheets),  one of the first things you need to know is how to label a tag.  For people not that familiar with CSS, basically CSS allows you to move the configuration of HTML tags to another file and call that file ((something).css) for a variety of customizations. 

Now labeling a tag for configuration has some flexibility but also some confusion.  Let's try to move away from confusion to understanding.  For the purposes of this tutorial, I'll be using one line of code for configuration.  I'll change the background color to red (I dare you to do red in a document and like it :)

 1) Basic Tag selection (Tag Selector)
If you want the least painful and quickest way to tag something than look no further than call your selector the tag itself.  That's right, you can actually configure a tag in html by it's actual name.
Example.  Suppose I want the background color of a button to be red (ug).  Anyway:

IN HTML
<button>(not complete of course)

IN CSS
button
{

   background-color:red

}

Now this has one big advantage. Anytime I call the stylesheet, the button tag in html will be red.  The disadvantage is that this has zero customization.  EVERY button will have the background color of red.  If that's what you want then go for it, but CSS gives us some more flexibility than that.

1) Class Selector (a period)

This is pretty basic.  Using a period for the label, you can assign a label to a variety of tags.  This means that anytime I use this label, buttons, body, etc will all inherit this tag.  The key is that this is designed to be used over and OVER and OVER again.  Therefore use it when you need to use it a LOT for a variety of element.s

HTML
<body class='Fred'>
<button class='Fred'>
<input class='Fred'>

CSS
.Fred
{
    background-color:red;

}



Ya, you can use this class with any element your heart desires.  However, what if you want to filter it to only certain elements.  NO PROBLEM.  CSS gives us a nice feature and in my coding, most of the time I do it this way.

HTML
<body class='Fred'>
<button class='Fred'>
<input class='Fred'>

Fred.button
{
   background-color:red;
}

Yes in this case ONLY the button will see red color.  I filtered it so that only a button can have that feature (if you consider ugly red a feature).  Now don't get discouraged.  Using a comma we can actually do more than one element.  Using the same example.

HTML
<body class='Fred'>
<button class='Fred'>
<input class='Fred'>

Fred.button, Fred.input
{
   background-color:red;

}

Now both button and input get the red color. Body will be left alone.  Cool!


ID Selectors (a pound symbol)

IDENTICAL except that you use this only ONCE.  If you only need this label once use this; otherwise use the Class selector.  As it's called, the ID selector means you use the id label of an element.  Given that ID's must be unique to an element, this is something useful if you have need for it in only one element.

#Fred
{
  background-color:red;
}

<table id = 'Fred'>

That's it.  Now isn't CSS labeling flexible?  Their are a few misc. things you can do but stick with the basics.  Most of the time this will be just fine for your issues. 

Thursday, January 3, 2013

Finding Duplicates in MySQL

NEED TO KNOW:
MySQL

NOTES:
Can be slow but heck, it's a powerful command.

Finding duplicates in MySQL isn't that hard.  For the purposes of clarity, all SQL commands are in caps.  Nuff said. 

So anyway, you have a billion record table and you want to see the duplicate values.  Use the following command from MySQL

HAVING count( Field in question) > 1

count will automatically determine any records that are duplicated.  We use > 1 to distinguish those that are unique.  Conversely you can change it to =1 to find unique records. 

In our example. we'll be using TABLE365 for the example.  The field we'll be using is InputDate for finding duplicates. 

SELECT * 
FROM TABLE365
GROUP BY InputDate
HAVING count(InputDate) >1

MySQL is annoyingly picky about count.  Don't add a space (e.g. count (InputDate)) otherwise it will WHINE back at you over your harseness and cruelty. 

NOW the problem with this query is that it won't show the duplicates, only the first appearance - not good but a start.  We can embed a query to essentially have MySQL run a query ON a query.

SELECT * 
FROM TABLE365
WHERE InputDate IN (  -> The query we just used <- ) 
ORDER BY InputDate

As you can see, the second query is buried in parantheses.  Of course you can use this to do a query on a query.  It's a way to avoid generating a table just to perform a special query on it. 


FINALLY, the entire piece of code looks like this:

SELECT *
FROM TABLE365
WHERE InputDate
IN (


SELECT InputDate
FROM TABLE365
GROUP BY InputDate
HAVING count( InputDate ) >1
)
ORDER BY InputDate

Of course you can modify this for PHP such as:
$QueryString = 'Select * from TABLE365 where InputDate in ( Select InputDate FROM...
You got the idea.

Saturday, August 18, 2012

Testing a Hard Disk

SKILLS -> Knowing your command line.

http://www.cyberciti.biz/tips/linux-find-out-if-harddisk-failing.html

This is the source article that I got the information from.  They do a great job of detailing the operation.  If the link is broken, here's the basic outline.

Install the software

apt-get install smartmontools -y

This basic command installs the smartmontools. You figured that didn't you :)

(sdx refers to one of the hard disks on your sytem.  sda,sdb,sdc,sdd)  If you don't know how to tell I would suggest using sda since that's the first in line.  If you have a second hard disk generally that's sdb.  That's generally of course.



(therefore smartctl -s on -d ata /dev/sda tests the first hard disk)





IS my harddisk smartcapable.  Usually it is but if you want to check:


smartctl -i /dev/hdx

[NOTE: If its not throw it out.  It's a junk hard disk ] 


This enables the function.


smartctl -s on -d ata /dev/sdx


Now we can read the error logs

smartctl -l error /dev/hdx

Send data to your email to yourself if you want.

/dev/sdx -m fred@myemail.com


The tests are more and more detailed but here are the basic command line structures.

 smartctl -d ata -H /dev/sdx
smartctl --attributes --log=selftest /dev/sdx
smartctl -d ata -a /dev/sdx

Short and Long tests for the hard disk

smartctl -d ata -t short /dev/sdx
smartctl -d ata -t long /dev/sdx

(output)
smartctl -a /dev/sdx

What's this?  Well if you want it all combined into a graphic interface, they use gsmartcontrol which is the graphic frontend.  
 
apt-get install gsmartcontrol

Have fun!
 






Wednesday, August 15, 2012

Remove old Kernels

Thanks to this website:

http://askubuntu.com/questions/138026/how-do-i-delete-kernels-from-a-server

At the bottom of the page is the actual script to do the job.

Ever had a problem of endless kernels on your system without the storage to manage it?

No prob.  You can remove old kernels with this script.

IMPORTANT:

If using GRUB legacy, be sure the menu.1st file contains an actual kernel you can use.  Its easy to check the current kernel running with this command:

uname -R

NOTE this will reference the running kernel and is tied to the menu.1st.  If you deleted the running kernel, just make sure you have an alternate.  ALL kernels are stored in:

/boot.

Just ls to get a list of kernels. 


DELETE all kernels.  Note this is actually one line of text.  The '\' is used to separate lines.  Save it as a file.

#!/bin/sh
dpkg -l linux-*  | \
awk '/^ii/{ print $2}' | \
grep -v -e `uname -r | cut -f1,2 -d"-"` | \
grep  -e '[0-9]' | xargs sudo apt-get -y purge

Monday, May 14, 2012

Mounting a USB device

ASSUME:
Command line knowledge
How to get to be a root user

Despite all the promises, Linux often chokes when it comes to mounting a USB device such as a camera, phone, etc, it often chokes and its frustrating not knowing a way to get it to work.  Here it goes:

FIRST:
You need to be a root user to get this to work.  Often times that just means SUDO but you can also use SU as well.  If you type SUDO, type your username

(e.g. SUDO foo)...or whatever your name is.

Type in your normal password and you're a root user.  SU works the same way but you don't need to type a username...just SU (super user in other words) and you need to know the ROOT password to do it.  Most distros are going the SUDO route so chances are try that.

SECOND:
lsusb  (list USB devices...linux people hate to type)

This will just ensure you have a USB device in there. Look for the term 'usb in the list.

Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 004 Device 002: ID 045e:00dd Microsoft Corp. Comfort Curve Keyboard 2000 V1.0
Bus 004 Device 003: ID 045e:0040 Microsoft Corp. Wheel Mouse Optical
Bus 001 Device 006: ID 22b8:70c6 Motorola PCS

In this example, you'll see the USB-2.04-Port HUB.  Ya, that looks about right and this tells us that USB is working. 

You could also type:

lsusb | grep USB

This would filter out the list to only show anything with USB in the name.  Don't ya love greg!

THIRD
Now that we KNOW we have a USB device, let's see what the drive is that mounts it.  Fortunately, we have a miracle command called DMESG.  This lists all the messages recently printed.  Naturally we want the find any USB devices. 


dmesg (let it scroll past you.  We want the end of the list...NOT...anything else.


[ 2432.904237] sr 8:0:0:2: Attached scsi generic sg6 type 5
[ 2432.914538] sd 8:0:0:1: [sde] Attached SCSI removable disk
[ 2432.918523] sd 8:0:0:0: [sdd] Attached SCSI removable disk
[ 2435.563830] sd 8:0:0:1: [sde] 15572992 512-byte logical blocks: (7.97 GB/7.42 GiB)
[ 2435.565942] sd 8:0:0:1: [sde] No Caching mode page present
[ 2435.565950] sd 8:0:0:1: [sde] Assuming drive cache: write through
[ 2435.570814] sd 8:0:0:1: [sde] No Caching mode page present
[ 2435.570820] sd 8:0:0:1: [sde] Assuming drive cache: write through
[ 2435.573677]  sde: sde1
[ 2441.705601] sd 8:0:0:0: [sdd] 9050112 512-byte logical blocks: (4.63 GB/4.31 GiB)
[ 2441.707717] sd 8:0:0:0: [sdd] No Caching mode page present
[ 2441.707720] sd 8:0:0:0: [sdd] Assuming drive cache: write through
[ 2441.712716] sd 8:0:0:0: [sdd] No Caching mode page present
[ 2441.712718] sd 8:0:0:0: [sdd] Assuming drive cache: write throug




NOTICE: the 'removable disk.  Ya, that's what we want.  In this example we have sdd and sde telling us that there are two drives associated with the device.  We'll mount both.

Now, on some distro's they create a /media directory and you mount things there.  The default is always /mnt but honestly you can mount it anywhere.  I tend to use /mnt but its up to you.

mkdir /mnt/FRED
mkdir /mnt/FRED2

mount /dev/sdc /mnt/FRED
mount /dev/sde /mnt/FRED2

HU???

Well, easy.  mount is the command that tells us to mount the device.  It takes two parameters.  The first is the source and the second is where you want to mount it.

/dev/sdc comes from dmesg and /mnt/FRED is the directory (folder) I created to mount the device.  Ya, Fred isn't too original but you can come up with something more original.

That's it.  You should now see the data in /mnt/FRED and /mnt/FRED2

I tend to just cd into that directory (I'm not covering cd here) but you can use a file manager such as nautilus if you want.


Sunday, May 13, 2012

Kernel Parameters

ASSUME:
This is advanced so no beginners for this one.
How to edit grub to modify the kernel parameters
Know what a kernel parameter is:


Editing the kernel is one thing but modifying boot options is another.  In this entry, we're going to modify some kernel parameters that are really useful -- especially when headaches arrive. 
In Grub1, or Grub2 you are allowed to edit the Kernel parameters by simply modifying the line that launches the kernel.



(Yes I know it wraps to the next line...sorry
kernel        /vmlinuz-3.2.0-23-generic-pae root=UUID=65c84575-96be-4380-b4d8-1b1d6292816d ro

This is a typical line for a kernel in the grub menu.

kernel - saying we have a kernel
where to find the kernel - /vmlinuz-3.2.0-23-generic-pae root=UUID=65c84575-96be-4380-b4d8-1b1d6292816d

ro - make it read only...handy

Anyway, here are some items you can place to the right of that line to make it more functional.

quiet - 
I don't like this but its typically found to display displaying the bootup process.

splash -
 throw up a splash screen which I don't like either.

text - 
VERY handy.  Boot to text mode to avoid autoloading the graphic screen (GNU, XFCE, etc.)

nomodeset
Some distros (Ubuntu in particular) make the text screen a huge tiny size.  If you just want 80 * 25 for the size, make this option available.
NOTE: For Ubuntu, if you do that, you'll get one UGLY font.  Do this>

dpkg-reconfigure console-setup

check VGS not FIXED and you'll get a nice clean font.

noacpi, pci=noacpi
These are two separate options but essentially work on the same idea.  If you are having hang problems with an operating system, try this option(s).  It disables polling of the PCI bus for interrupts.  It can stabilize a system.  Treat this as a diagnostic.  If it works after this, chances are your BIOS is a problem.  Upgrade the bios.

That's it.

Wednesday, May 9, 2012

Smurf bug in Adobe

If you:

(a) Have the latest Adobe Flash player plugin
(b) Have the proprietary NVidia driver

You will see blue people due to a hue problem with the flash player. 


In short, try this:

sudo add-apt-repository ppa:tikhonov/misc
sudo apt-get update
sudo apt-get install libvdpau1
 
 
The patch is located here:
 
http://lists.freedesktop.org/archives/vdpau/2012-May/000022.html
 
This is a patch that works around the adobe flash problem. What is the problem????
 
Read this link in its entirety.
 
http://askubuntu.com/questions/117127/flash-video-appears-blue

Sorry this is so short but there are only so many hours in a day.

 
Try another link:
http://www.nvnews.net/vbulletin/showthread.php?t=177380

Monday, May 7, 2012

Install Grub2 from a LiveCD

KNOW:
Command line basics
chroot
grub

You would think that installing Grub...or GRUB2 from a LiveCD will be an easy task -- think again.  There is a lot to know so let's get to it.

1) Boot to a liveCD.  Most graphic LiveCD's take 20 years to bootup -- Ubuntu being a great one for that but you can get text only LiveCD's so look for em.

2) Run terminal.  You need to get to a terminal to make this work.

3) We're now going to make the installed version of linux work instead of the LiveCD. This is tricky so let's get to it.

(a) you MUST know the partitian for your boot (/boot) and your mnt (/) locations.
In this example, we're going to use /sdb6 for our root (/) and /sdb1 for our boot.  Most installations don't separate the two but I'm giving you the extreme example.

sudo /mnt/sdb6 /mnt

Here we mount the entire partitian to the /mnt directory.

sudo /mnt/sdb1 /mnt/boot

(IF your boot partitian is different, otherwise leave alone)

Now we're going to point three directories (/proc /dev /sys) to our new mount point.

mount -t proc none /mnt/proc
mount -o bind /sys /mnt/sys
mount -o bind /dev /mnt/dev  (the devices)
cp -L /etc/resolv.conf /mnt/etc/resolv.conf

The purpose of this is to simply avoid host name errors

chroot /mnt/ /bin/bash  (most critical)
env-update 
source /etc/profile 
export PS1="(chroot) $PS1"

NOTE:
cp /proc/mounts /etc/mtab

(use this if you plan to reinstall grub)

sudo grub-install /dev/sdb1

That should shove it on the boot of the drive.

 

Monday, March 19, 2012

Bad video display in XFCE fix from command line

BUG:

XFCE is kind of dumb. It doesn't back out of bad display setting such as 1280*1024 which, for whatever reason, you're card or monitor can't handle. Instead it leaves that whole crappy display up there for you to suffer with.  Here's how to fix it.

You would think that modifying /etc/xorf.conf would be your go-to center for changing the display settings from the command line in XFCE.  NO!

Nope, there is a profile saved with each user -- which I suppose has its benefits.  Here is where you modify it...get ready for a long path.

vim ~/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml

Set the proper resolution in displays.xml.

Whatever it is, a safe choice is 800*600.  Then you can take it from there. 

I am also told that:

xfconf-query works but I've never found it useful.