mardi 15 juillet 2014

If an Ubuntu machine become responseless


If the ubuntu machine locks up completely, you can REISUB it, which is a safer alternative to just cold rebooting the computer.
REISUB by:
While holding Alt and the SysReq (Print Screen) keys, type REISUB.

R:  Switch to XLATE mode
E:  Send Terminate signal to all processes except for init
I:  Send Kill signal to all processes except for init
S:  Sync all mounted file-systems
U:  Remount file-systems as read-only
B:  Reboot
 
REISUB is BUSIER backwards, as in "The System is busier than it should be", if you need to remember it. Or mnemonically - R eboot; Even; If; System; Utterly; Broken.

Environment variables

First of all, we have different places to setup environment variable. All the following files are applicable to both Ubuntu and Mac OS:
  • ~/.profile:
    use this for variables you want to set in all programs launched from the terminal (note that, unlike on Linux, all shells opened in Terminal.app are login shells).
  • ~/.bashrc:
    this is invoked for shells which are not login shells. Use this for aliases and other things which need to be redefined in subshells, not for environment variables that are inherited.

  • /etc/profile:
    this is loaded before ~/.profile, but is otherwise equivalent. Use it when you want the variable to apply to terminal programs launched by all users on the machine (assuming they use bash).

Ubuntu System

/etc/profile.d/:
All the script in this directory will be automatically executed. For more details, you can check the file /etc/profile


vim /etc/profile

then, you will see:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi



Mac OS X

  • ~/.MacOSX/environment.plist: this is read by login window on login. It applies to all applications, including GUI ones, except those launched by Spotlight in 10.5 (not 10.6). It requires you to logout and login again for changes to take effect. This file is no longer supported as of OS X 10.8. 
  • your user's launchd instance: this applies to all programs launched by the user, GUI and CLI (command line interface). You can apply changes at any time by using the setenv command in launchctl. In theory, you should be able to put setenv commands in ~/.launchd.conf, and launchd would read them automatically when the user logs in, but in practice support for this file was never implemented. Instead, you can use another mechanism to execute a script at login, and have that script call launchctl to set up the launchd environment.
  • /etc/launchd.conf: this is read by launchd when the system starts up and when a user logs in. They affect every single process on the system, because launchd is the root process. To apply changes to the running root launchd you can pipe the commands into sudo launchctl.








a

Set the colour in terminal of Mac OS X

set the colour for normal users.
1: Go to the home directory, and create the following file:

    vim .bash_profile

2: Insert the following content into the file:

    export TERM="xterm-color"

    PS1='\[\e[00;32m\]\u\[\e[0m\]@\[\e[00;32m\]\w\[\e[0m\]\$'

The definition of each colour can be referred to the previous article.

3: save the file. Make it validated.

    source .bash_profile
-------------------------------------
set the colour for root.
1: login as a root.

    sudo -i

and then, enter the password.

2: create the following file:

    vim .profile

3: Enter the following content into the file (can be the same as normal users):

    export TERM="xterm-color"

    PS1='\[\e[00;31m\]\u\[\e[0m\]@\[\e[00;31m\]\w\[\e[0m\]\$'

4: save the file and make it validated immediately.

    source .profile
-------------------------------------
THEN, THE WORLD BECOMES COLOURFUL! :-)

jeudi 10 juillet 2014

Determine 32bit or 64bit of your mac OS


  • 1
    Launch Terminal app (see Applications/Utilities)
  • Determine if You're running the 32 Bit or 64 Bit Kernel in Mac oSX Step 2.jpg
    2
    At prompt, type the following: "uname -a" (without the quotes) (note the blank space between "uname" and "-a" strings.
  • Determine if You're running the 32 Bit or 64 Bit Kernel in Mac oSX Step 3.jpg
    3
    The terminal will display two lines of text. At the end of the 2nd line, you'll find something like either
    • RELEASE_I386 i386 ; the latest "i386" means that you're running 32bits kernel
    • RELEASE_X86_64 x86_64 ; the latest "x86_64" means that you're running 64bits kernel

  • Original Link: http://www.wikihow.com/Determine-if-You're-running-the-32-Bit-or-64-Bit-Kernel-in-Mac-oSX

    lundi 7 juillet 2014

    Change the Command-Line Prompt Colour in the Ubuntu/Linux Terminal

    How to Change the Command-Line Prompt Colour in the Ubuntu/Linux Terminal

    The terminal for running commands in Ubuntu and any other Linux distro is dull to look at, but you can easily spice it up a little with some colour.
    Simply run the following command in a terminal:
    gedit ~/.bashrc
    When .bashrc opens, locate and uncommentforce_color_prompt=yes” (that is, remove the hash, so it no longer looks like: #force_color_prompt=yes).
    Save the file, and open a new terminal window, and you should already see a change (the prompt should be Light Green, which is defined by 1;32). You can then change any colour value you like; eg: 0;35 = Purple.
    To edit the colour values, locate the following section, and change the default values with some of the examples listed further down:
    if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '
    else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    fi
    You can check out this Bash colour chart for a full range of colour values, but here are a few basic ones you can play around with (note that “Light” isn’t what you might think – it actually means “bold”):
    Black 0;30Dark Gray 1;30Blue 0;34Light Blue 1;34Green 0;32Light Green 1;32Cyan 0;36Light Cyan 1;36Red 0;31Light Red 1;31Purple 0;35Light Purple 1;35Brown 0;33Yellow 1;33Light Gray 0;37White 1;37
    For those curious about the codes used in the example pic, here’s the line from that section:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    As you can see, 1;35 is the Light Purple user and machine name, while the 1;34 is the Light Blue tilde (~). If you want yours a bit brighter, try:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u@\h\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '
    … which will give you Light Cyan and Light Red, and look like the following:
    In case you’re wondering about the colon and dollar sign, you can change those as well, but you need to do more than just edit the colour values. You’ll need to insert code in the appropriate places, so the line looks like this:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u@\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\$ '
    You’ll notice the first highlighted code is just before the colon (:) while the second is before the dollar sign ($). In this example, both are yellow, with the result looking like:
    Now, if you want to go even further, you can make the user name stand out by doing the following:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;35m\]@\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\$ '
    That extra bit of code is specifying Light Purple for the @ and the desktop name, making it now look like:
    And of course, one last bit of fiddling and you can have every element a different colour. In this last example, we’re going to make the computer name the same as the user name, and have them broken up by red, as with the yellow elements:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;31m\]@\[\033[01;36m\]\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\$ '
    As you can see, the @ is now Light Red, while the code before \h is specifying Light Cyan, like the user name:
    You’ll also notice when you type commands that the colour of the text will match that of the $, which can be preferable if using a “light” colour, since the bold text is easier to see.
    Lastly, in case you’re wondering whether the prompt can end in anything other than a $, the answer is yes, and it’s as easy as opening the Character Map (sudo apt-get install gucharmap if you don’t have it), selecting a character, and pasting it over the $ at the end of the line of code:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;31m\]@\[\033[01;36m\]\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\] '
    In that example, I simply selected a cool looking character from the font Runic, and replaced the $ with that. You’ll also note one other thing you’ll have to do, and that’s remove the \ before it, or else that will appear too (obviously, that doesn’t happen if using the $, but will with other characters).
    Have fun experimenting!

    Original Link: http://ubuntugenius.wordpress.com/2011/07/11/how-to-change-the-command-line-prompt-colour-in-the-ubuntulinux-terminal/

    and

    http://www.arwin.net/tech/bash.php

    dimanche 6 juillet 2014

    Enable remote desktop for Ubuntu for multiple users

    1: install xrdp

        sudo apt-get install xrdp

    2: if now, you use remote desktop connector, you can only see a blank desktop. So a few more steps are needed:

        sudo vim /etc/xrdp/startwm.sh 

    And then, add the following line in front of ". /etc/X11/Xsession":

        echo "gnome-session --session=ubuntu-2d" > .xsession





    So, the file now looks like:

        #!/bin/sh

        if [ -r /etc/default/locale ]; then
          . /etc/default/locale
          export LANG LANGUAGE
        fi

        echo "gnome-session --session=ubuntu-2d" > .xsession

        . /etc/X11/Xsession





    3: Start the xrdp


        /etc/init.d/xrdp start

    Other useful commands:

        /etc/init.d/xrdp restart
        /etc/init.d/xrdp stop

    4: start the remote desktop connector, and enter the IP address of the Ubuntu machine, then follow the instructions.

    vendredi 24 mai 2013

    BEAMER customize the navigation bar (tree)


    \documentclass{beamer}
    \useoutertheme{tree}
    
    \makeatletter
    \setbeamertemplate{headline}
    {%
        \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
        \end{beamercolorbox}
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
          leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
          \usebeamerfont{title in head/foot}\insertshorttitle
        \end{beamercolorbox}
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
          leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
          \usebeamerfont{section in head/foot}%
          \ifbeamer@tree@showhooks
            \setbox\beamer@tempbox=\hbox{\insertsectionhead}%
            \ifdim\wd\beamer@tempbox>1pt%
              \hskip2pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
              \hskip1pt%
            \fi%
          \else%  
            \hskip6pt%
          \fi%
          \insertsectionhead
          \usebeamerfont{subsection in head/foot}%
          \ifbeamer@tree@showhooks
            \setbox\beamer@tempbox=\hbox{\insertsubsectionhead}%
            \ifdim\wd\beamer@tempbox>1pt%
              \ \raise1.9pt\hbox{\vrule width 5pt height0.4pt}%
              \hskip1pt%
            \fi%
          \else%  
            \hskip12pt%
          \fi%
          \insertsubsectionhead\hfill\insertframenumber/\inserttotalframenumber\hspace{0.5em}
        \end{beamercolorbox}
        \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
        \end{beamercolorbox}
    }
    \makeatother
    \title{Tree Outer Theme}
    \begin{document}
    
    \section{Test Section}
    \begin{frame} test \end{frame}
    \subsection{Test Subsection One}
    \begin{frame} test \end{frame}
    \subsection{Test Subsection Two}
    \begin{frame} test \end{frame}
    
    \end{document}