Linux okosságok

RAID megoldások

SSH okosságok

SSH-n másolás köztes állomáson át

tar cvf - file1 file2 | ssh KoztesHoszt "ssh -o \"StrictHostKeyChecking no\" CelHoszt \"cd CelMappa && tar -xvf -\""

Több parancs futtatása SSH-n

ssh user@server "$( cat <<'EOT'
echo "These commands will be run on: $( uname -a )"
EOT
)"

Vagy csak simán az escape problémákra megoldás:

ssh root@server ps uax \| grep ba[c] \| \'{ print \$2 }\' \> /tmp/back.tmp

or you could double quote the single quotes instead of escaping them (in both cases, you need to escape the dollar sign)

ssh root@server ps uax \| grep ba[c] \| "'{ print \$2 }'" \> /tmp/back.tmp

Jelszavas sudo parancs futtatása SSH-n

#!/bin/bash read -a Pass -s -p „Your password, please? : ” ssh server „echo -e \”$Pass\r\„ | sudo -S <some command you have sudo access to>”

MYSQL mentés

Mentés (/etc/mysql/debian.cnf is kell a jelszó miatt):

mysqldump -u root -ptitok --single-transaction --opt --all-databases -R

Visszaállítás:

mysql -u root -ptitok -B adatbazis < mentes.sql

LVM snapshot készítés

lvdisplay -C -olv_name,lv_path --noheadings
lvcreate -s -L 1G -n blabla /dev/vg/blablalv
lvdisplay -C -S lv_role=snapshot

NMON adatgyűjtés

#!/bin/sh

if [ $? -ne 0 ]; then exit 1; fi
ps -ef | grep '[n]mon ' | awk '{print $2}' | while read PID; do kill $PID; done
find /tmp/nmon/$(hostname)_* -type f -maxdepth 1 -mtime +30 -exec rm -f {} \;
# vagy betomoritve:
# find /tmp/nmon/$(hostname)_* -type f -maxdepth 1 -mtime +30 -print0 | xargs -0 tar zcvf $(hostname)_blabla.tar.gz

# Mintaveteli periodus (masodperc)
INTERVAL=60
# Meres idotartama (ora)
DURA=24

SAMPLES=`expr $DURA \* 3600 / $INTERVAL`
cd /tmp/nmon
nmon -f -s $INTERVAL -c $SAMPLES

Ismétlődő sorok számolása

cat file | sed 's/([^(]*)$/,&/' | awk -F'[,]' '{a[$2]++}END{for(k in a) print $1,k,$3,"("a[k]"x)"}'

Bekezdésre greppelés Linux alatt (AIX: grep -p)

awk 'BEGIN{RS=ORS="\n\n";FS=OFS="\n"}/Storage Slots/

Network socket darabszám mérő

netstat -an | awk '/^tcp/ {A[$(NF)]++} END {for (I in A) {printf "%5d %s\n", A[I], I}}'

Hálózati áteresztőképesség mérés

iperf-fel, 25-ös porton, Mb-ban kiírva, 45 mp-ig, 2 mp-enként kiírva az aktuális rátát, 3 szálon (bővebb tutorial):

[node2]# iperf -p 25 -s (server)
[node1]# iperf -f m -p 25 -c node2 -t 45 -i 2 -P 3 (client)

SSH-val (UNIX/Linux):

[node1]# cat /dev/zero | ssh node2 "cat > /dev/null"

FTP-vel (Unix/Linux):

[node1]# ftp node2
ftp> bin
ftp> put "| dd if=/dev/zero bs=32k count=10000 " /dev/null

Port scanning

nmap -sT hoszt

FC portok lekérdezése

#!/bin/sh
echo --- BEGIN ---
for port in $(ls -d /sys/class/fc_host/host*); do
  echo "$port: "
  printf "Port state: \t"; cat $port/port_state
  printf "Port speed: \t"; cat $port/speed
  printf "Port WWN: \t"; cat $port/port_name
  echo -----
done
echo --- END ---

Hiányzik az "add-apt-repository":

sudo apt-get install --reinstall python-software-properties && sudo dpkg-reconfigure python-software-properties

Java install:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
java -version

Mennyi helyet foglal egy bizonyos fájl csoport?

find / -name "*\.trc" -print0 | du --files0-from=- -hc | tail -n1

Milyen felbontásokat támogat a webcam?

$ lsusb
  Bus 001 Device 002: ID 5986:0241 Acer, Inc BisonCam, NB Pro
$ lsusb -s 001:002 -v | egrep "Width|Height"
  wWidth    640
  wHeight   480
  wWidth    1280
  wHeight   1024
...

Helyhasználat listázása fájlrendszerben userenként

find / -printf '%u %k\n' | awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}'

Sztringek hexa értelmezésének kiküszöbölése

Pl:

$((10#`date +%H`))

A grep "-o" kapcsolójának kiváltása perl-lel

perl -lne '/reguláris kifejezés/ && print $&'

Törölt fájlok, amik nem szabadították még fel a helyet

lsof |(sed 1q; grep deleted)

BASH változó manipulációk

SyntaxMeaning
${#var} String length (number of characters in $var).
${parameter?err_msg},${parameter:?err_msg} If parameter set, use it, else print err_msg and abort the script with an exit status of 1. Both forms nearly equivalent. The : makes a difference only when parameter has been declared and is null.
${parameter-default},${parameter:-default} If parameter not set, use default. ${parameter-default} and ${parameter:-default} are almost equivalent. The extra : makes a difference only when parameter has been declared, but is null.
${parameter=default},${parameter:=default} If parameter not set, set it to default. Both forms nearly equivalent. The : makes a difference only when $parameter has been declared and is null.
${parameter+alt_value},${parameter:+alt_value} If parameter set, use alt_value, else use null string. Both forms nearly equivalent. The : makes a difference only when parameter has been declared and is null.
${var#Pattern} Remove from $var the shortest part of $Pattern that matches the front end of $var.
${var##Pattern} Remove from $var the longest part of $Pattern that matches the front end of $var.
${var%Pattern} Remove from $var the shortest part of $Pattern that matches the back end of $var.
${varPattern} Remove from $var the longest part of $Pattern that matches the back end of $var.
${var:pos} Variable var expanded, starting from offset pos.
${var:pos:len} Expansion to a max of len characters of variable var, from offset pos.
${var/Pattern/Replacement} First match of Pattern, within var replaced with Replacement. If Replacement is omitted, then the first match of Pattern is replaced by nothing, that is, deleted.
${var//Pattern/Replacement} Global replacement. All matches of Pattern, within var replaced with Replacement. If Replacement is omitted, then all occurrences of Pattern are replaced by nothing, that is, deleted.
${var/#Pattern/Replacement} If prefix of var matches Pattern, then substitute Replacement for Pattern.
${var/%Pattern/Replacement} If suffix of var matches Pattern, then substitute Replacement for Pattern.
${!varprefix*},${!varprefix@} Matches names of all previously declared variables beginning with varprefix.

forrás: http://tldp.org/LDP/abs/html/parameter-substitution.html

Gyakori BASH RC kódok

Exit Code Number Meaning Example Comments
1 Catchall for general errors let „var1 = 1/0” Miscellaneous errors, such as „divide by zero” and other impermissible operations
2 Misuse of shell builtins (according to Bash documentation) empty_function() {} Missing keyword or command
126 Command invoked cannot execute /dev/null Permission problem or command is not an executable
127 „command not found” illegal_command Possible problem with $PATH or a typo
128 Invalid argument to exit exit 3.14159 exit takes only integer args in the range 0 - 255 (see first footnote)
128+n Fatal error signal „n” kill -9 $PPID of script $? returns 137 (128 + 9)
130 Script terminated by Control-C Ctl-C Control-C is fatal error signal 2, (130 = 128 + 2, see above)
255* Exit status out of range exit -1 exit takes only integer args in the range 0 - 255

Terminál kurzor pozícionálás

- Position the Cursor:

\033[<L>;<C>H
   Or
\033[<L>;<C>f
puts the cursor at line L and column C.

- Move the cursor up N lines:

\033[<N>A

- Move the cursor down N lines:

\033[<N>B

- Move the cursor forward N columns:

\033[<N>C

- Move the cursor backward N columns:

\033[<N>D

- Clear the screen, move to (0,0):

\033[2J

- Erase to end of line:

\033[K

- Save cursor position:

\033[s

- Restore cursor position:

\033[u

Hasznos oldalak

linux.txt · Utolsó módosítás: 2018/04/20 11:15 szerkesztette: admin
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0