Informatique

DD

Bench IO disk via dd :

Write :

1
time dd if=/dev/zero of=testfile bs=1024k count=1000 && sync

Read :

1
time dd if=testfile of=/dev/null bs=1024k

At

Commande

1
2
# atq
13 Mon Jun 30 19:53:00 2014 a jerem

Liste les taches plannifiées

1
atrm 13

Efface une tache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
at 17:33
at now + 4 min
at now + 4 minutes
at now + 2 hours
at 10pm + 3 days
at 10pm + 3 months
at 10am Jul 31
at 10am tomorrow
at midnight
at noon
at teatime (16h)
...
at> echo "toto" > /tmp/zob
at> echo "pouya" >> /tmp/zob
at> <EOT>
job 13 at Mon Jun 30 19:53:00 2014

at + la date souhaitée
ensuite, une liste de commande (enter entre chaque)
et “Ctrl-d” pour sortir

Delete huge dir

1
rsync --delete-before -a -H /tmp/EMPTY/ TODELETE/
1
perl -e 'for(<*>){((stat)[9]<(unlink))}'

Secure delete

shred -vfuz -n 10 file
shred –verbose –random-source=/dev/urandom -n 1 /dev/sda

scrub -p dod /dev/sda
scrub -p dod -r file

badblocks -s -w -t random -v /dev/sda
badblocks -c 10240 -s -w -t random -v /dev/sda

srm -vz /tmp/file
sfill -vz /local
sdmem -v
swapoff /dev/sda5 && sswap -vz /dev/sda5

Mysql multi thread slave

Depuis mysql 5.6 on peut multi threader la repli

Nombre de thread

1
slave_parallel_workers

Mémoire par thread

1
slave_pending_jobs_size_max

defaut 16M
/!\ The value for this option must not be less than the master’s value for max_allowed_packet

Atop

Conf le daemon

1
2
3
4
5
6
cat /etc/default/atop 
# /etc/default/atop

INTERVAL=600
LOGPATH="/var/log/atop"
OUTFILE="$LOGPATH/daily.log"

Lire le resultat

1
2
atop -r /var/log/atop.log.1
atop -r /var/log/atop.log.1 -b 13:00 -e 13:30

ou atop pour le regarder en live facons top (ensuite ‘z’ permettra de mettre en pause)

  • i = changement d’interval en secondes (defaut 10)
  • t/T = avancer/reculer dans les intervales
  • Ctrl+f ou b = page suivante/precedente
  • c/g = bascule processlist ou general
  • ? = liste commande

Rsyslog

TIPS

Ne pas faire logguer postfix dans syslog en plus de mail.log, ainsi que virer cron de syslog

1
*.*;mail.none;mail.error;auth,cron,authpriv.none             -/var/log/syslog

Disable mail.info qui double mail.log

1
2
3
#mail.info                      -/var/log/mail.info
#mail.warn -/var/log/mail.warn
#mail.err /var/log/mail.err

1
cron.*                          /var/log/cron.log
  • En cas d’erreur
1
Apr 11 16:17:46 myserver rsyslogd-2177: imuxsock lost 99 messages from pid 3607 due to rate-limiting
1
2
root@myserver/:# vi /etc/rsyslog.conf
$SystemLogRateLimitInterval 0 # turn off rate limiting
  • Le signe “-“ :
    You may prefix each entry with the minus ``-‘’ sign to omit syncing the file after every logging. Note that you might lose information if the system crashes right behind a write attempt. Nevertheless this might give you back some performance, especially if you run programs that use logging in a very verbose manner.

L ami logger

1
# echo "test" | logger -s -p auth.notice -t youpee
<37>Oct 28 15:41:08 youpee: test
# tail -1 /var/log/auth.log
Oct 28 15:41:08 thcol-exp-logs-01 youpee: test

Shell tips

Tips en vrac

Minuscule à majuscule :

1
2
echo "EEdddzZ" | tr '[:lower:]' '[:upper:]' 
EEDDDZZ

Supprime les sauts de ligne

1
2
tr -d '\r\n'
awk '!x[$0]++' truc > zob

Demande de pass interactive :

1
echo -n Password: ; read -s pass ; for i in ` ls access.log*` ; do echo $pass | scp --stdin access.log* root@10.0.0.1:/toto ; done

Affiche sans les commentaires

1
sed -e '/^[ ]*#/d' -e '/^$/d'

exec a partir de awk

1
cat /etc/hosts  | awk '{ system("echo " $2" "$1)}'

Append 2 files in columns

1
paste -d " " fileliste1 fileliste2

Dos2unix

1
$ cat mon_fichier.txt | tr -d '\r' > mon_nouveau_fichier.txt

Kill un process zombi

1
gdb -p <zombi_pid>

Affiche de 1 à 5

1
for i in {1..5} ; do echo $i ; done

Compare 2 lists

1
$ comm list1.txt list2.txt

Chmod +x only directory

1
$ chmod -R +X dir/

Random sleep max 10s

1
sleep $(( RANDOM % 10 ))

Proxy tcp

1
mkfifo /tmp/fifo.socket
nc -lk -p 8080 </tmp/fifo.socket | nc www.unvrai.info 80 >/tmp/fifo.socket

Close shell keeping all subprocess running

1
disown -a && exit

Edit a file on a remote host using vim

1
vim scp://user@host//etc/fstab

Find duplicate files (based on MD5 hash)

1
find -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 33

Show current working directory of a process

1
pwdx <pid>

Limit the cpu usage of a process

1
cpulimit -p pid -l 50

Start a command on only one CPU core

1
taskset -c 0 <command>

Find which directory in one filesystem that contains most inodes or files.

1
find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n | tail                                                                                                                                                                        │

bash shortcut

Ctrl + a Go to the beginning of the line (Home)
Ctrl + e Go to the End of the line (End)
Ctrl + p Previous command (Up arrow)
Ctrl + n Next command (Down arrow)
Alt + b Back (left) one word
Alt + f Forward (right) one word
Ctrl + f Forward one character
Ctrl + b Backward one character
Ctrl + xx Toggle between the start of line and current cursor position

Editing:
Ctrl + L Clear the Screen, similar to the clear command

Alt + Del Delete the Word before the cursor.
Alt + d Delete the Word after the cursor.
Ctrl + d Delete character under the cursor
Ctrl + h Delete character before the cursor (Backspace)

Ctrl + w Cut the Word before the cursor to the clipboard.
Ctrl + k Cut the Line after the cursor to the clipboard.
Ctrl + u Cut/delete the Line before the cursor to the clipboard.

Alt + t Swap current word with previous
Ctrl + t Swap the last two characters before the cursor (typo).
Esc + t Swap the last two words before the cursor.

ctrl + y Paste the last thing to be cut (yank)
Alt + u UPPER capitalize every character from the cursor to the end of the current word.
Alt + l Lower the case of every character from the cursor to the end of the current word.
Alt + c Capitalize the character under the cursor and move to the end of the word.
Alt + r Cancel the changes and put back the line as it was in the history (revert).
ctrl + _ Undo

Ctrl+I = Tab
Ctrl+J = Newline
Ctrl+M = Enter
Ctrl+[ = Escape

Ctrl + r Recall the last command including the specified character(s)
searches the command history as you type.
Equivalent to : vim ~/.bash_history.
Ctrl + p Previous command in history (i.e. walk back through the command history)
Ctrl + n Next command in history (i.e. walk forward through the command history)

Ctrl + s Go back to the next most recent command.
(beware to not execute it from a terminal because this will also launch its XOFF).
Ctrl + o Execute the command found via Ctrl+r or Ctrl+s
Ctrl + g Escape from history searching mode
!! Repeat last command
!abc Run last command starting with abc
!abc:p Print last command starting with abc
!$ Last argument of previous command
ALT + . Last argument of previous command
!* All arguments of previous command
^abc­^­def Run previous command, replacing abc with def

Ctrl + C Interrupt/Kill whatever you are running (SIGINT)
Ctrl + l Clear the screen
Ctrl + s Stop output to the screen (for long running verbose commands)
Then use PgUp/PgDn for navigation
Ctrl + q Allow output to the screen (if previously stopped using command above)
Ctrl + D Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT)
Ctrl + Z Send the signal SIGTSTP to the current task, which suspends it.
To return to it later enter fg ‘process name’ (foreground).