SSH, les séquences d'échappement

Cela peut par exemple vous servir pour gérer ou retrouver vos tunnel.

Extrait du man :

 ESCAPE CHARACTERS
     When a pseudo-terminal has been requested, ssh supports a number of func-
     tions through the use of an escape character.

     A single tilde character can be sent as ~~ or by following the tilde by a
     character other than those described below.  The escape character must
     always follow a newline to be interpreted as special.  The escape charac-
     ter can be changed in configuration files using the EscapeChar configura-
     tion directive or on the command line by the -e option.

     The supported escapes (assuming the default `~') are:

     ~.      Disconnect.

     ~^Z     Background ssh.

     ~#      List forwarded connections.

     ~&      Background ssh at logout when waiting for forwarded connection /
             X11 sessions to terminate.

     ~?      Display a list of escape characters.

     ~B      Send a BREAK to the remote system (only useful for SSH protocol
             version 2 and if the peer supports it).

     ~C      Open command line.  Currently this allows the addition of port
             forwardings using the -L, -R and -D options (see above).  It also
             allows the cancellation of existing port-forwardings with
             -KL[<em>bind_address</em>:]<em>port</em> for local, -KR[<em>bind_address</em>:]<em>port</em> for re-
             mote and -KD[<em>bind_address</em>:]<em>port</em> for dynamic port-forwardings.
             !<em>command</em> allows the user to execute a local command if the
             PermitLocalCommand option is enabled in <a href="http://man.openbsd.org/">ssh_config(5)</a>.  Basic
             help is available, using the -h option.

     ~R      Request rekeying of the connection (only useful for SSH protocol
             version 2 and if the peer supports it).
rtfm  ssh 

Les variables système

La liste des variables système MySQL se trouve http://dev.mysql.com.

Il y est indiqué si ces variables sont dynamique ou non, si elle le sont, vous pouvez les changer a chaud (ne pas oublier de mettre a jour le fichier de configuration MySQL 😉 ).

[Lire]

Lister toutes les tables/base

Cette requête va lister toutes les bases/tables du serveur MySQL en ignorant les " bases " performance_schema et information_schema mais aussi en filtrant les tables dont le nom commence par tmp_ et la table test.

SELECT table_schema, table_name
 FROM information_schema.tables
 WHERE table_schema NOT IN ('performance_schema','information_schema')
  AND table_name NOT REGEXP '^tmp_|^test$
 ORDER BY table_schema;

Vous pouvez filtrer sur tout ce qui est dans la table " tables "

desc tables;
+-----------------+---------------------+------+-----+---------+-------+
| Field           | Type                | Null | Key | Default | Extra |
+-----------------+---------------------+------+-----+---------+-------+
| TABLE_CATALOG   | varchar(512)        | YES  |     | NULL    |       |
| TABLE_SCHEMA    | varchar(64)         | NO   |     |         |       |
| TABLE_NAME      | varchar(64)         | NO   |     |         |       |
| TABLE_TYPE      | varchar(64)         | NO   |     |         |       |
| ENGINE          | varchar(64)         | YES  |     | NULL    |       |
| VERSION         | bigint(21) unsigned | YES  |     | NULL    |       |
| ROW_FORMAT      | varchar(10)         | YES  |     | NULL    |       |
| TABLE_ROWS      | bigint(21) unsigned | YES  |     | NULL    |       |
| AVG_ROW_LENGTH  | bigint(21) unsigned | YES  |     | NULL    |       |
| DATA_LENGTH     | bigint(21) unsigned | YES  |     | NULL    |       |
| MAX_DATA_LENGTH | bigint(21) unsigned | YES  |     | NULL    |       |
| INDEX_LENGTH    | bigint(21) unsigned | YES  |     | NULL    |       |
| DATA_FREE       | bigint(21) unsigned | YES  |     | NULL    |       |
| AUTO_INCREMENT  | bigint(21) unsigned | YES  |     | NULL    |       |
| CREATE_TIME     | datetime            | YES  |     | NULL    |       |
| UPDATE_TIME     | datetime            | YES  |     | NULL    |       |
| CHECK_TIME      | datetime            | YES  |     | NULL    |       |
| TABLE_COLLATION | varchar(32)         | YES  |     | NULL    |       |
| CHECKSUM        | bigint(21) unsigned | YES  |     | NULL    |       |
| CREATE_OPTIONS  | varchar(255)        | YES  |     | NULL    |       |
| TABLE_COMMENT   | varchar(80)         | NO   |     |         |       |
+-----------------+---------------------+------+-----+---------+-------+

Lister les tables en InnoDB/MyISAM

Voici la requête SQL :

SELECT table_schema, table_name, engine
FROM information_schema.tables
WHERE table_schema NOT IN ('performance_schema','information_schema')
AND engine != 'NULL
ORDER BY table_schema;

Afficher les "scores" d'oom-killer

Les scores oom-killer sont stocké dans /proc

Ci-dessous une boucle pour afficher le top 20 des process qui se feront détruire en premier dans le cas ou le serveur a alloué 100% de la ram et swap.

#!/bin/sh
for procdir in $(find /proc -maxdepth 1 -regex '/proc/[0-9]+'); do
  printf "%10d %6d %s\n" \
    "$(cat $procdir/oom_score)" \
    "$(basename $procdir)" \
    "$(cat $procdir/cmdline | tr '&#92;&#48;' ' ' | head -c 100)"
done 2>/dev/null | sort -nr | head -n 20

Trier /etc/hosts par IP

En ajoutant quelques options a sort, comme ci-dessous, le tri par adresse IP se fait correctement

cat /etc/hosts | sort -n -t. +0 -1 +1 -2 +2 -3 +3 -4
Tips  Shell  sort  IP 

Mon .tcshrc

Contenue du fichier ~/.tcshrc

#{{{ Env
if ($tty == '') then
   exit 0
endif
setenv PATH /sbin:/usr/sbin:$PATH
setenv EDITOR      vim
setenv VISUAL      vim
setenv PAGER       more
setenv LESS        "-erX"
setenv GIT_PAGER   less
setenv LANG        en_US.UTF-8
setenv LC_TYPE     en_US.UTF-8

if ${?TERM} then
    switch( $TERM )
    case "xterm*":
        setenv TITLE "%{&#92;&#48;33]0;%n@%m [%~]&#92;&#48;07%}"
        breaksw;
    default:
        setenv TITLE ""
        breaksw;
    endsw
endif
#}}}
#{{{ Env tcsh
set myuid       = `id -u`
set stty        = `echo $tty | sed 's/tty//'`
set prompt      = "${TITLE}%h %n@%m-$stty [%B%.03%b]%# "
set prompt2     = "%n@%M-$tty >%R?<%# "
set time        = ( 1 "%Uu %Ss %Er %Pcpu %X+%Dk %I+%Oio %Fpf+%Wsw" )
set who         = "%n has %a %l from %M"
set fignore     = ( .o \~ \#\*\# )
set complete    = enhance
set watch       = ( 1 any any )
set autolist    = ambiguous
set correct     = cmd
set listjobs    = long
set history     = ( 5000 "%h (%D-%W-%Y %T) %R\n" )
set savehist    = ( 5000 merge )
set histfile    = ~/.tcsh_history
set histdup     = erase
set matchbeep   = nomatch
set promptchars = '>#
set listflags   = 'a
set printexitvalue
set autoexpand
set listlinks
set echo_style  = both
unset autologout

bindkey "^R"    history-search-backward
bindkey "^S"    history-search-forward
#}}}
#{{{ Alias
alias   l               'ls -Glh \!*
alias   ll              'ls -Glha \!*
alias   monip           'wget -q --no-check-certificate https://panel.pascalito.org/ip.php -O - ; echo ""
alias   mplayer-nova    'mplayer -ao pulse,alsa,sdl:aalib,coreaudio http://broadcast.infomaniak.net:80/radionova-high.mp3
alias   mplayer-play    'mplayer -ao pulse,alsa,sdl:aalib,coreaudio \!*
alias   mplayer-pls     'mplayer -ao pulse,alsa,sdl:aalib,coreaudio -loop 0 -playlist \!:1
alias   mplayer-plsr    'mplayer -ao pulse,alsa,sdl:aalib,coreaudio -shuffle -loop 0 -playlist \!:1
alias   mplayer-rfg     'mplayer -ao pulse,alsa,sdl:aalib,coreaudio http://www.radiofg.com/streams/fg.pls
alias   mplayer-rfg-c   'mplayer -ao pulse,alsa,sdl:aalib,coreaudio http://www.radiofg.com/streams/fgc.pls
alias   mplayer-rfg-r   'mplayer -ao pulse,alsa,sdl:aalib,coreaudio http://www.radiofg.com/streams/fgv.pls
alias   mplayer-rfg-h   'mplayer -ao pulse,alsa,sdl:aalib,coreaudio http://www.radiofg.com/streams/fgd.pls
alias   mplayer-rfg-u   'mplayer -ao pulse,alsa,sdl:aalib,coreaudio http://www.radiofg.com/streams/fgu.pls
alias   pls-create      'find ~/Music -ctime -\!:1  -iname "*.m4a" -o -iname "*.mp4" -o -iname "*.mp3" -type f -printf "/%AY%Am%Ad %p\r\n" | sort | sed "s/^.\{10\}//g" > ~/.mplayer/tmp.m3u
alias   rm              '\rm -i
alias   screenshot      'import -window root `hostname`-`date +%y%m%w-%H%M%S`.png
alias   src             'source ~/.tcshrc
alias   svnup           'find ~/Documents/svn -type d -depth 1 -exec svn up {} \;
alias   taroverssh      'tar cvpf - . | ssh \!:1 tar xpf - -C \!:2
alias   vi              'vim \!*
unalias ls
#}}}
#{{{ pmad
if ( -o ~/Documents/svn/scripts/dotfiles/pmad.tcsh ) then
    source ~/Documents/svn/scripts/dotfiles/pmad.tcsh
endif
if ( -d ~/Documents/svn/scripts/pmad ) then
    setenv PATH ~/Documents/svn/scripts/pmad:$PATH
endif
#}}}
#{{{ Completion
# tcsh
complete {fg,bg,stop}   c/%/j/ p/1/"(%)"//
complete kill           'c/%/j/' 'c/-/S/
complete chgrp          'p/1/g/
complete chown          'p/1/u/
complete find           'p/1/d/' 'n/-user/u/' 'n/-group/g/
complete cd             'C/*/d/
complete rmdir          'C/*/d/
complete lsd            'C/*/d/

complete git p/1/"(add am apply archive bisect branch config checkout clone commit  \
      count-objects describe diff fetch fsck gc grep init ls-files log merge mv pull push \
      prune rebase repack reset revert rm remote show show-branch status tag version)"/
complete cvs 'c/--/(help help-commands help-synonyms)/' \
      'p/1/(add admin annotate checkout commit diff \
      edit editors export history import init log login \
      logout rdiff release remove rtag status tag unedit \
      update watch watchers)/' 'n/-a/(edit unedit commit \
      all none)/' 'n/watch/(on off add remove)/
complete svn p/1/"(add blame cat checkout cleanup commit copy delete \
      diff export help import info list lock log merge mkdir move propdel \
      propedit propget proplist propset resolved revert status switch  \
      unlock update )"/

# signal names
# also note that the initial - can be created with the first completion
# but without appending a space (note the extra slash with no
# append character specified)
complete kill 'c/-/S/' 'p/1/(-)//

# use available commands as arguments for which, where, and man
complete which 'p/1/c/
complete where 'p/1/c/
complete man 'p/1/c/

# aliases
complete alias 'p/1/a/
complete unalias 'p/1/a/

# variables
complete unset 'p/1/s/
complete set 'p/1/s/

# environment variables
complete unsetenv 'p/1/e/
complete setenv 'p/1/e/
#(kinda cool: complete first arg with an env variable, and add an =,
# continue completion of first arg with a filename.  complete 2nd arg
# with a command)
complete env 'c/*=/f/' 'p/1/e/=/' 'p/2/c/

# limits
complete limit 'p/1/l/

# key bindings
complete bindkey 'C/*/b/

# groups
complete chgrp 'p/1/g/

# users
complete chown 'p/1/u/

# sudo
complete sudo 'n/-l/u/' 'p/1/c/

# You can use complete to provide extensive help for complex commands
# like find.
# Please check your version before using these completions, as some
# differences may exist.
complete find 'n/-name/f/' 'n/-newer/f/' 'n/-{,n}cpio/f/' \
     'n/-exec/c/' 'n/-ok/c/' 'n/-user/u/' 'n/-group/g/' \
     'n/-fstype/(nfs 4.2)/' 'n/-type/(b c d f l p s)/' \
     'c/-/(name newer cpio ncpio exec ok user group fstype type atime \
     ctime depth inum ls mtime nogroup nouser perm print prune \
     size xdev)/' \
     'p/*/d/

# set up cc to complete only with files ending in .c, .a, and .o
complete cc 'p/*/f:*.[cao]/

# of course, this completes with all current completions
complete uncomplete 'p/*/X/

# complex completion for ln
# In all cases, if you start typing, it completes with a filename
# But if you complete without typing anything you get this:
#   first argument:           adds "-s"
#   arguments that follow -s: reminds you of which argument is expected
complete ln 'C/?/f/' 'p/1/(-s)/' 'n/-s/x:[first arg is path to original file]/' 'N/-s/x:[second arg is new link]/

# set a printer list, for use with all print related commands
set printerlist=(hp1 hp2 color)
complete lp 'c/-d/$printerlist/
complete lpstat 'p/1/$printerlist/
complete lpq 'c/-P/$printerlist/
complete lpr 'c/-P/$printerlist/
complete enscript 'c/-d/$printerlist/
#}}}
#{{{ Other
switch($OSTYPE)
    #{{{ OSx
    case darwin:
        setenv PATH /opt/local/bin:/opt/local/sbin:$PATH
        alias  ggcontactsync '/System/Library/PrivateFrameworks/GoogleContactSync.framework/Versions/A/Resources/gconsync --sync com.google.ContactSync
        breaksw
    default:
        breaksw
    #}}}
    #{{{ Linux
    case linux:
        #{{{ Debian
        if ( -f /etc/debian_version ) then
            set ipackages = `dpkg --get-selections | awk '{print $1}'`
            set apackages = `apt-cache search '' | awk '{print $1}'`
            complete dpkg 'n/-L/$ipackages/
            complete apt-get \
                'c/--/(build config-file diff-only download-only \
                fix-broken fix-missing force-yes help ignore-hold no-download \
                no-upgrade option print-uris purge reinstall quiet simulate \
                show-upgraded target-release tar-only version yes )/' \
                'c/-/(b c= d f h m o= q qq s t x y )/' \
                'n/{source,build-dep}/x:<pkgname>/' \
                'n/{remove}/`dpkg -l|grep ^ii|awk \{print\ \$2\}`/' \
                'n/{install}/`apt-cache pkgnames | sort`/' \
                'C/*/(update upgrade dselect-upgrade source \
                build-dep check clean autoclean install remove)/

            complete apt-cache \
                'c/--/(all-versions config-file generate full help important \
                names-only option pkg-cache quiet recurse src-cache version )/' \
                'c/-/(c= h i o= p= q s= v)/' \
                'n/{search}/x:<regex>/' \
                'n/{pkgnames,policy,show,showpkg,depends,dotty}/`apt-cache pkgnames | sort`/' \
                'C/*/(add gencaches showpkg stats dump dumpavail unmet show \
                search depends pkgnames dotty policy )/
            if ($myuid == 0) then
                alias updateall 'apt-get update && apt-get upgrade && apt-get autoclean && apt-get dist-upgrade
            endif
        endif
        #}}}
    #}}}
    #{{{ Other
    default:
        breaksw
    #}}}
endsw
#}}}

Installer son FAMP (FreeBSD Apache MySQL PHP)

Un “FAMP” est une plateforme Apache/PHP/MySQL installé sur une FreeBSD 😉 et oui, ce n’est pas un L_inux_AMP !

Apache

cd /usr/ports/www/apache22/
make config install distclean
echo 'apache2_enable="YES"' >> /etc/rc.conf
echo 'apache2ssl_enable="YES"' >> /etc/rc.conf
echo 'accf_http_ready="YES"' >> /etc/rc.conf && kldload accf_http

PHP

cd /usr/ports/lang/php5
make config install distclean
cd /usr/ports/lang/php5-extensions
make config install distclean

MySQL

cd /usr/ports/databases/mysql51-server
make install WITH_OPENSSL=yes
make distclean
echo 'mysql_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/mysql-server start
/usr/local/bin/mysql_secure_installation