Pages

Wednesday, March 7, 2012

my .zshrc file



# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=100000
SAVEHIST=10000
setopt autocd
bindkey -v
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/home/cgerada/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall

#the following lines were added by cgerada
#autocompletion of hostname from ,ssh/known_hosts

local _myhosts
_myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} )
zstyle ':completion:*' hosts $_myhosts
#Spelling autocorrect
setopt  correct

#coloured prompt
autoload -U colors && colors
PS1="%{$fg_bold[green]%}%n%{$reset_color%}@%{$fg_bold[blue]%}%m %{$fg_bold[yellow]%}%~ %{$reset_color%}%% "
# right hand prompt simple date and time only
 RPROMPT="[%D,%T]"

#Extension aliases very cool
alias -s doc=libreoffice
alias -s xls=libreoffice
alias -s doc=libreoffice
alias -s pdf=evince

~                                                                                                                                                          
~                          


~                                                                                                                                                          
~                                                                                                                                                          
~                                    

Moving from Bash to ZSH




I have Stopped using Bash and am now using ZSH as my new shell of Choice.
ZSH has many awesome features that make it a No brainer (for me anyway) to make the switch

Here's what I love about ZSH

1:) Your History is shared across sessions. Multiple simultaneously running zsh sessions can share history with each other. how many times have you looked into your bash history to find a recent command that you used, only to find that that command was run on a different terminal session and is no longer available to you.

2:) Tab Auto completion works between remote machines over SSH.

rsync -avr remotemachine:/home/cgerada/Documents/very/long/directory/na (at this point you can hit tab and provided that you connect to your remote host using ssh Key authentication instead of password authentication  zsh will autocomplete for you.

3:)No need to type cd to change into a Directory.
/home/cgerada/directory   enter

will change to /home/cgerada/directory  for you.
Considering how often you use the cd command, this is a real time saver.

4:) Tab auto completion works for command options
     rsync -av (hit tab here) will show you all possible options for the rsync command

5:) Built in Spell check
     How many times have you typed something like aptg-et or other mangled commands? Well,
     if you do that in zsh,You  get a message asking: “zsh: correct 'aptg-et' to 'apt-get' [nyae]? “

6:) Built in pager.
     If your Lazy like me. And I think you are.  zsh comes with a pager directly in the shell. This means you
     can type things like " > README  and it is equivalent to less README or cat README | less"


7:)Right hand prompt
    Zsh supports a second (right hand prompt) great for adding the date and time (see screen shot above)
    or if you own a laptop you can also display your Battery capacity.  The right hand prompt will not get in
    your way as it disappears when your typing reaches it. or you can just not enable it if you don't want it.

8:) Known hosts auto completion. ZSH can even tab autocomplete hostname entries of remote machines that  
     you connect to from your .ssh/knownhosts file.

     in fact auto completion in all areas is far more superior in ZSH.

9:) Extension aliases

alias -s doc=libreoffice





putting the above in your .zshrc file allows you to open up a .doc file simply by typing its filename. eg

officedoc.doc  [enter]

will open up officedoc.doc using libre office (in Bash you would have had to type

libreoffice officedoc.doc
you can do the same for all extensions eg
alias -s pdf=evince
                      
ZSH has loads more awesome features, and is highly customizable .  it behaves extremly similar to bash, in fact you can use it exactly the way you use bash and not learn or change a single thing and you won't be missing anything.

Right, so if you are convinced to make the change and jump right in.

install zsh by typing  yum install zsh or apt-get install zsh.

once installed simply type
chsh to change your shell  .
you will be asked for your user password
once typed in correctly you will be asked
New shell [/bin/bash]
type /bin/zsh   enter

and the next time you log into your shell with your username you will be in the ZSH shell.

If for what ever reason, you do not like zsh and want to revert back to bash
simply type
chsh
enter your password once again
and then type
/bin/bash

will change your shell back to Bash.











Thursday, February 9, 2012

X11 connection rejected because of wrong authentication.



When you need to run an X window application over SSH.
You ssh -X into the remote machine, running X applications works fine, until you
sudo or su to another user to run an X application , You get the following error.
"X11 connection rejected because of wrong authentication.

X connection to localhost:10.0 broken (explicit kill or server shutdown)."

or if you connected using putty the error will read.
“Xlib: PuTTY X11 proxy: wrong authentication protocol attempted”.


How to fix?


ssh cgerada@remote-server -X


cgerada $ su – oracle
oracle‘s Password:
oracle $ xclock


"X11 connection rejected because of wrong authentication.
X connection to localhost:10.0 broken (explicit kill or server shutdown)".

or if you connected with putty the error reads


"Xlib: PuTTY X11 proxy: wrong authentication protocol attempted
xclock Xt error: Can’t open display: localhost:10.0"


On newer versions of  OpenSSH Server releases, you can simply enable “ForwardX11Trusted yes” in the /etc/ssh/sshd_config file and restart the OpenSSH server.
If you’re using an older version of  OpenSSH Server release then
You need to temporarily transfer the authorization to the other account. First, get the key from your account:
cgerada $ xauth list
fileserver/unix:10  MIT-MAGIC-COOKIE-96951c0622f80fd52186129dd06f2f6
Next, sudo/su to the other account and add the authorization key.
cgerada $ su – oracle
oracle $ xauth add fileserver/unix:10  MIT-MAGIC-COOKIE-96951c0622f80fd52186129dd06f2f6
Now, you should be able to start any X Windows application, 
oracle $ xclock

Saturday, January 28, 2012

Installing Fedora 16 on a System that can not boot GPT Labelled Disks

Some Systems Particularly Fujitsu Siemens Life books, Apple Macs and some others,
Cannot Boot If the Hard drive is Formatted using this Newer GPT  format.

Fedora 16 uses the new GPT format since it does have some benefits.
However if you want to install Fedora 16 on a Lifebook or an Apple mac, you need to do the following.

You need to pass parameter nogpt to the Fedora installer.

To do this, at the initial bootloader menu for the Fedora installation, where you can select to install, install in basic graphics mode, boot to the rescue mode and so on, hit the Tab key, then edit the command line for the Fedora installer and add the word nogpt.  you can do this when using the Live CD or the Complete distribution DVD.

Then install as normal and your Machine should now boot and work as expected.

Do not choose custom partitioning layout, You must let the system create it's own layout first and then if you want , You can edit what it creates to suite your requirements. If you choose custom layout, the 1MB problematic BootBios partition is created and this will give you the following error "
"you have not created a bootloader stage1 target device"

Monday, January 23, 2012

mount.nfs: access denied by server while mounting

If your nfs mounts stop working
and mount-a gives you the following error.
mount.nfs: access denied by server while mounting /blah_blah_blah/blah_blah


Chances are, your machine has been upgraded and now uses the NFS version 4 as default nfs version
 instead of 3

To fix this issue you need to explicitly tell nfs to mount your share using the older nfs version 3

simply add nfsvers=3  to your nfs mount stanza in your /etc/fstab file


eg
vi /etc/fstab


192.168.1.10:/shared/files  /mnt/files nfs soft,intr,nfsvers=3 0 0

save the file and type
mount -a  

Your nfs mounts will now work.

Friday, January 6, 2012

Resolve transparency issues with Guake

If you set Guake to start automatically when your computer starts, depending on how quickly your Gnome session loads, there  may be an issue with it starting before Gnome has completed it's full initialization. 

when this happens, the transparency in quake does not work as it should, You cannot see the windows behind the Guake terminal, It lets you see your Background wallpaper only.

A solution for this is to delay the start up of Guake, so that Gnome is allowed to initialize fully before Guake starts.

To do this , run 
gnome-session-properties

under startup-programs edit your entry for Guake.

and add  sleep 8 && infront of guake, 
like so

 sleep 8 && guake 

This gives guake an 8 second delay before starting, and should be enough to let Gnome fully initialize, and your transparency will work as it should.

Wednesday, January 4, 2012

Problem mounting a LVM

To  manually mount a drive that contains a LVM (Logical Volume)
do the following.

lvdisplay

will output info about your logical volume
the important thing to note here is
the line which says VG Name
VG Name               vg_lvm

sometimes you will get a lv status as not available
to make it available type

vgchange -a y

this will activate any LVMS that werent active and make them available.

then to mount the LVM simply type

mount /dev/vg_lvm   /mnt







Saturday, December 31, 2011

Problem installing Oracle Virtual box extension pack

If you would like to use the USB ports on your virtual machine in virtual box.
You need to install the virtual box extension pack available from the download section at www.virtualbox.org

However opening the downloaded extension pack from virtualbox and clicking the install button, sometimes gives the following error

"Failed to install the Extension Pack Oracle_VM_VirtualBox_Extension_Pack-.vbox-extpack.  The installer failed with exit code 127: The value for the SHELL variable was not found the /etc/shells file    This incident has been reported..  Result Code: NS_ERROR_FAILURE (0x80004005) Component: ExtPackManager Interface: IExtPackManager "

I find that installing the extension pack using the command line fixes this problem.
simply cd into the folder were the extension pack you downloaded resides,
and type the following. replacing the xxxx with the version of the extension pack you downloaded.

 sudo VBoxManage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-4.1.xxxx.vbox-extpack 


and it will install properly, you should get the following back.


0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Successfully installed "Oracle VM VirtualBox Extension Pack".



Wednesday, December 7, 2011

Free up space on your hard drive.


ext2/ext3 and ext4, file systems automatically reserve space for themselves. (5% by default)
This is necessary for your root partition, so that  if you fill up the hard drive, Linux will still have space to write to the log files and to allow privileged processes to run so that they can avoid file system fragmentation.
However, if your hard disk is say a 650GB or bigger hard drive, that 5% amounts to a significant amount of disk space, and is a total overkill.
Additionally, you do not need this reserved space on hard drives that are only used for storage (ie are not part of your root partition)
so, how do we take back this valuable hard disk real estate ?
We use tune2fs.


so as an example,  type


tune2fs -m 1 /dev/sda2
to change the 5% to 1% on /dev/sda2


if /dev/sda was a 650GB hard drive this would give you an additional 26 GB Free!


tune2fs -m 0 /dev/sda2
will  reduce the 5% to 0%


to add reserved space for privileged processes back to a  drive
type
tune2fs -r 20000 /dev/sda2
will give back 20000 blocks, which should be more than sufficient


you can run tune2fs on  Logical volumes as well.


tune2fs -m 1 /dev/mapper/vg-lv_home 
will reclaim space from your logical volume


Just change /dev/mapper/vg/-lv_home to the name of your logical volume.
you can see all your volumes and partitions by typing df -h

Thursday, December 1, 2011

Simple Webserver

python -m SimpleHTTPServer

Will serve your current Directory tree at
http://IP_of_machine_you_ran_the_command_on:8000



Wednesday, November 30, 2011

Check your spelling

yum install aspell

or apt-get install aspell for Ubuntu systems

then in future  when ever  you need to know how to spell a word simply type

aspell -a <<< 'word'


Wednesday, November 23, 2011

save man pages as pdf

man -t ls | ps2pdf - ls.pdf


Will save the man pages for ls to ls.pdf


substitute ls for the programme man pages you want to save as a pdf

Tuesday, November 22, 2011

Script Terminal Session



script -f /tmp/filename
will place all output of the terminal, including carriage returns, to a file (/tmp/filename)

So then on another terminal session type
tail -f /tmp/filename

 This file can be tail -f by one or more terminals to display Live the information of the main terminal.
Great  way to share your screen on short notice.


to Stop scripting type
 <Cntrl> D

Sunday, November 20, 2011

Ascii Digital Clock


install banner

yum install banner
then type


watch -n1 'banner `date +%T`'

Saturday, November 19, 2011

How To Add a start up script to be Run at Boot time in Ubuntu


First Save your script in

  /etc/init.d/


then type:


sudo update-rc.d script_name defaults

This script will now run each time you boot up.

Wednesday, November 16, 2011

sort the contents of a text file in place

This will sort the contents of a file without the need to pipe it into a second file.

great for cron jobs



sort -g name_of_file_to_sort.txt -o $_

Monday, November 14, 2011

Dropbox Free 2GB account

Always have your stuff when you need it with Dropbox.
2GB account is free!


Click Here To open an account

Dropbox will allow you to share folders across multiple computers.


Friday, November 4, 2011

Removing old unused Kernels from your Fedora system

Old unused Kernels can take up a fair amount of Disk Space.
to install old ones.


Install yum utils
yum install yum-utils

package-cleanup --oldkernels --count=2

will remove all old kernels except for the last 2.

 Make Amount of Installed Kernels Permanent
Edit /etc/yum.conf and set installonly_limit

 
installonly_limit=2
 

Friday, October 21, 2011

Integrate google contacts into your Mutt address Book

Goobook will alow you to interact with your gmail contacts from the command line and also enable mutt to access them

install goobook
type


easy-install -U goobook

Once installed create .netrc  file in your home folder with the credentials to your google account
Vim ~/.netrc


inside .netrc put the following

machine google.com
login yourgmailaddress@gmail.com
password yourpassword

save the file

to test if it is working type

goobook dump_contacts

this will dump all your contact information from gmail to stn out

to search for a string from your gmail contacts type

goobook query query

eg to search for clive type

goobook query clive

if you want to use goobook from mutt

edit your .muttrc file and add in the following line:

set query_command="goobook query '%s'"

to query the address book from inside mutt use the "Q" key



If you want to be able to use to complete email addresses instead of Ctrl-t add this:
bind editor complete-query
To add email addresses (with "a" key normally bound to create-alias command) add the following line:

macro index,pager A "goobook add" "add the sender address to Google contacts"

If you want to add an email's sender to Contacts, press "a" while it's selected in the index or pager.