Posts tagged ‘Linux’

Color that manpage!

Manpages are the last line of defence when it comes to unix troubleshooting. After you’ve tried everything you could have think of and it still doesn’t work you know it’s time to read the manual.

By default linuxes use the less command to display the man page requested by the user. The manpage is displayed as plain text and because of that it can be sometimes hard to find what you’re looking for. Keywords and special parameters are printed with a bold face to ease document navigation but sometimes this is not enough.

Navigation is done by using the up and down arrows , page up/ page down and the space key.
Searching through the document is done by typing the / character followed by the word or phrase to search for.

One useful hack is to color the manpage so that keywords parameters and so on are highlighted.

To do this you we have to set some environment variables:

export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;31m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[01;44;33m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[01;32m' # begin underline

The strange ‘\E0 strings stand for color codes used by the bash shell. You can check out some info about that on the bash-prompt-howto

After you have customized your colors you can save the above commands in your .bashrc file (the one in your home folder) so that the variables are set every time you logon.

Quickie: Wrap to 80 columns

I got a complaint that my submitted text file is not wrapped to 80 columns. Rather than work my butt to mix and match the text lines until i get to the bastard’s requirement I used the neat little tool called fold

cosu@cosu-desktop:~/Desktop$ cat file | fold -s
my monitor resolution is soooooooooooooooooo small that more than 80 colums of
text give me a segfault.

-s stands for break at spaces. man fold for more options.

Donez

Donez 4 stickere 1 sticker cu Ubuntu (4cmx1cm) si 1 cd cu ubuntu desktop 9.04 si 1 cd cu Ubuntu Server 9.04.

Doritorii sa se prezinte in EG101.

Silverlight pe linux

Dupa o vizita pe http://www.go-mono.com/moonlight/ si un restart de firefox obtinem asta:

Silverlight on linux

Silverlight on linux

Richard Stallman in Romania

RMS vine in Romania! Daca esti fan foss sau doar fan emacs atunci vino sa il vezi pe tatal proiectului gnu la eliberatica!

http://www.eliberatica.ro/2009/conference/speakers

Anul trecut prezenta din partea UPB a fost destul de strong.
Si putin fun cu utilitarul meu favorit: vrms! (virtual richard m stallman)

cosu@roadwarrior:~$ vrms
            Non-free packages installed on roadwarrior

gdb-doc                   The GNU Debugger Documentation
human-icon-theme          Human Icon theme
linux-generic             Complete Generic Linux kernel
linux-restricted-modules- Non-free Linux 2.6.22 modules on x86/x86_64
linux-restricted-modules- Non-free Linux 2.6.24 modules on x86/x86_64
linux-restricted-modules- Non-free Linux 2.6.24 modules on x86/x86_64
linux-restricted-modules- Non-free Linux 2.6.24 modules on x86/x86_64
linux-restricted-modules- Non-free Linux 2.6.24 modules on x86/x86_64
linux-restricted-modules- Non-free Linux 2.6.24 modules on x86/x86_64
linux-restricted-modules- Non-free Linux 2.6.24 modules on x86/x86_64
linux-restricted-modules- Non-free Linux 2.6.24 modules helper script
linux-restricted-modules- Restricted Linux modules for generic kernels
opera                     The Opera Web Browser
picasa                    Image management application from Google
rar                       Archiver for .rar files
sun-java6-bin             Sun Java(TM) Runtime Environment (JRE) 6 (architecture
sun-java6-jdk             Sun Java(TM) Development Kit (JDK) 6
sun-java6-jre             Sun Java(TM) Runtime Environment (JRE) 6 (architecture
sun-java6-plugin          The Java(TM) Plug-in, Java SE 6
tangerine-icon-theme      Tangerine Icon theme
unrar                     Unarchiver for .rar files (non-free version)
  Reason: Modifications problematic

  21 non-free packages, 1.1% of 1914 installed packages.

Find script path

Azi am avut nevoie sa gasesc calea in care sa gaseste un script chiar din scriptul respectiv. Fiserul se plimba prin diverse locuri si eu am nevoie de cai absolute ( hint java classpaths)

Solutie

MYPATH=”$(readlink -f $(dirname “$0″))”

hints: man readlink, man dirname

On screen

Screen este o scula foarte utila atunci cand ai multe de facut si putine terminale la dispozitie. Practic screen este un multiplexor de terminal, cam cum e gnome terminal sau yakuake in varianta lor cu taburi, doar ca totul e facut direct in consola.

Pe langa multiplexarea mai sus amintita screen ofera si un feature foarte util. programul este imun la semnalele de tipul sighup. Mai pe romaneste screen ramane pornit pe masina chiar daca ai inchis conexiunea ssh/fizica cu terminalul in care lucra. Utilitatea chestiei asteia se dovedeste atunci cand ai de facut un task peste o legatura la internet foarte proasta. De regula procesele pornite din un shell au ca parinte respectivul shell. In clipa in care legatura peste ssh moare, moare si shellul si cu el procesele copil. Foarte urat. Porinite din screen procesele raman active chiar si dupa terminarea legaturii remote. Deja ne vin in minte utilizari foarte productive: client de torenti in screen, download masiv cu wget si prietenii, stat pe irc cu irssi (sau alt irc client in mod text) compilari fara sfarsit si multe altele.

Utilizarea lui screen necesita putina acomodare. Pornirea lui se face direct ruland screen.
Comenzile se activeaza folosind shortcuturi de tipul Ctrl+A urmate de o litera(case sensitive) /cifra/simbol. Ctrl+A este cunoscut ca escape sequence (cine a lucrat cu minicom stie).
Combinatia Ctrl+A urmata de ? afiseaza pe ecran toate comenzile suportate de screen.
Cateva combinatii utile:

Ctrl+A c –> creeaza un terminal nou

Ctrl+A “ –> afiseaza o lista cu toate terminalele

Ctrl+A <cifra> trece la terminalul cu id-ul respectiv

Ctrl+A d –> detasare de screen (practic un fel de exit)

Ctrl+A n –> next

Ctrl+A p –> previous

Ctrl+A ESC –> copy mode

Personal am renuntat la Ctrl+A pentru caracterul `. Avand in vedere ca folosesc rar caracterul (si doar cand e vorba de scripturi bash.

Reatasarea la screen se poate face ruland screen –r –d. Putem avea mai multe procese screen ce ruleaza si putem da ca parametru sesiunea la care vrem sa ne atasam.

Screen se poate customiza folosind fisierul .screenrc

Al meu arata asa:

escape ``
hardstatus alwayslastline "%{= KW}%-w%{= wk}%50>%n %t%{-}%+w%<"
hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]%{=b C}[ %m/%d %c ]%{W}'
startup_message off
vbell off
msgminwait 0
msgwait 10

Si rezultatul este asta

image

Se observa in partea de jos 5 terminale deschise, fiecare fiind denumit dupa procesul executat (ifstat, htop, links).

umount: device is busy

Uneori cand vreau sa fac umount unui volum se mai intampla sa primesc mesaje de genul “device is busy”.

Solutiile sunt multiple si foarte complexe.

A doua solutie est este mai brutala: fortarea procesului de umount cu ajutorul parametrului –f :

umount –f /path/to/mount

In prima instanta aflam procesul care tine lucrurile pe loc cu ajutorul comenzii

fuser : fuser –m /path/to/mount/

Urmeaza o inspectie a procesului cu pidul returnat de fuser si un eventual SIGKILL si un umount bine meritat.

Cpuset

Cpuset este un wrapper scris in python ce permite rularea anumitor procese pe anume procesoare. Scula este utila cand stii ca ai un proces care rupe sistemul in doua si nu vrei sa pierzi total controlul masinii. Astfel limitezi procesul ala sa puna stapanire doar pe un anumite procesorare (sau core-uri :) ) si iti vezi  mai departe de treaba. O alta utilizare ar putea fi rezervarea unoui proc/core pentru taskuri critice pentru sistem – loguri,kernel threads, alte balarii.

Exemplu de utilizare:

cset set –cpu=3-4 –set=mycpus
cset proc –set=mycpus –exec /home/cosu/bin/eatprocessor
cset proc –list mycpus

 

Pentru download click aici iar pentru documentatie click aici

Playdeb

Playdeb este un proiect ce vrea sa puna impreuna cat mai multe jocuri ce ruleaza pe platforma linux, toate in format deb. Distributia tinta este (din pacate doar) Ubuntu. Lista completa de jocuri e aici:

http://www.playdeb.net/available_games.html

Instalarea e cea obisnuita, fiind nevoie sa adaugam in sources.list linia:

deb mirror://www.getdeb.net/playdeb-mirror/hardy/// hardy/

Recomandarile mele sunt Warsaw, Alien Arena si Warzone 2100.