meta data for this page
  •  

Különbségek

A kiválasztott változat és az aktuális verzió közötti különbségek a következők.

Összehasonlító nézet linkje

Előző változat mindkét oldalonElőző változat
Következő változat
Előző változat
linux [2019/01/24 10:55] adminlinux [2024/03/12 16:57] (aktuális) admin
Sor 1: Sor 1:
 ===== Linux okosságok ===== ===== Linux okosságok =====
  
-==== RAID megoldások ====+==== Dátum figyelés ====
  
-  * Standard RAID: [[http://en.wikipedia.org/wiki/Mdadm|mdadm]] +  function date_diff() 
-  * RAID1 TCP-n[[linux:DRBD|DRBD (Distributed Replicated Block Device)]] +  
-  * RAID1 fájlrendszer szinten: [[http://www.furquim.org/chironfs/index.en.html|ChironFS]]+    date='2020-08-12T16:00:10' 
 +    epoch=$(date -d "$date" +%s) 
 +    if [ "$epoch" -lt "$(date -d '1 minute ago' +%s); then 
 +  #[[ "$(date -d '2024-02-01 17:26:00' +%s)" -lt "$(date +%s)" ]] && echo elmult || echo nem 
 +        echo At least 3 days ago 
 +    else 
 +        echo Too recent 
 +    fi 
 +  }
  
-==== SSH okosságok ==== 
  
-=== SSH-n másolás köztes állomáson át ===+==== Reboot, ha nem megy a szabályos reboot ====
  
-  tar cvf file1 file2 | ssh KoztesHoszt "ssh -o \"StrictHostKeyChecking no\" CelHoszt \"cd CelMappa && tar -xvf -\""+  # echo s > /proc/sysrq-trigger 
 +  # echo u > /proc/sysrq-trigger 
 +  # echo s > /proc/sysrq-trigger 
 +  # echo b > /proc/sysrq-trigger
  
-=== Több parancs futtatása SSH-n ===+This requests the kernel to do:
  
-  ssh user@server "$( cat <<'EOT' +emergency sync of the block devices;  
-  echo "These commands will be run on: $( uname -)" +mount readonly of all filesystems;  
-  EOT +again sync;  
-  )"+force an immediate boot; (you can also use o for poweroff)
  
-Vagy csak simán az escape problémákra megoldás: +==== dm-* device-ok felderítése ====
  
-  ssh root@server ps uax \| grep ba[c] \| \'print \$2 }\' \> /tmp/back.tmp+  find /dev/ -name "dm-*" -exec readlink -n {} \; -exec echo " -->" {} \
 +==== SCSI (re)scan ====
  
-or you could double quote the single quotes instead of escaping them (in both cases, you need to escape the dollar sign)+  #!/bin/sh 
 +  for I in `ls -d /sys/class/scsi_device/*`; do 
 +        echo ${I} 
 +        echo "1" > ${I}/device/rescan 
 +  done
  
-  ssh root@server ps uax \| grep ba[c] \| "'{ print \$}'\> /tmp/back.tmp+  #!/bin/sh 
 +  for I in `ls -d /sys/class/scsi_host/host*`; do 
 +        echo ${I} 
 +        echo "- - -" > ${I}/scan 
 +  done
  
-=== Jelszavas sudo parancs futtatása SSH-===+ 
 +==== Yum-mal telepített csomagok listázása log fájlból ==== 
 + 
 +  cat /var/log/yum.log | sed "s#.\+: \?\(.\+\)#\1#" | sort 
 +==== Disk perf. teszt DD-vel ====
  
 <file> <file>
 #!/bin/bash #!/bin/bash
-read -a Pass -s -p "Jelszavad? : " +echo -"Fajl nev: " 
-expect -+read FNEV 
-      set timeout 5 +echo -n "Blokk meret (Byte): 
-      spawn ssh -tt -n $server \"echo -e \\"$Pass\\r\\" sudo -S <parancs>\" +read BS 
-      expect "Are you sure" { send "yes\r"timeout {} +echo -n "Fajl meret (MByte): " 
-      expect "?assword:" +read FS 
-      send \"$Pass\r\" +COUNT=$((FS*1024*1024 / $BS)) 
-      expect eof"+COUNT=$(echo $COUNT sed 's/\..*$/g/') 
 +echo -n "Diszk irasa (dd if=/dev/zero of=$FNEV bs=$BS count=$COUNT)… " 
 +SEC=$(timex dd if=/dev/zero of=$FNEV bs=$BS count=$COUNT 2>&1 | awk '/real/{print $2}' | awk -F'.' '{print $1}') 
 +echo "$(($FS / $SEC)) MB/s"
 </file> </file>
 +
 +==== BOOT probléma ====
 +
 +GRUB menüben a "quiet" paraméter helyére "dracut rdshell"-t betenni
 +
 +==== ~/.vimrc ====
 +
 +  set number background=dark
 +  syntax on
 +  highlight Comment    ctermfg=119
 +  highlight Identifier ctermfg=99AA00
 +  set ts=4 sw=4
 +  undolevels=1000
 +==== RAID megoldások ====
 +
 +  * Standard RAID: [[http://en.wikipedia.org/wiki/Mdadm|mdadm]]
 +  * RAID1 TCP-n: [[linux:DRBD|DRBD (Distributed Replicated Block Device)]]
 +  * RAID1 fájlrendszer szinten: [[http://www.furquim.org/chironfs/index.en.html|ChironFS]]
 +
 ==== MYSQL mentés ==== ==== MYSQL mentés ====
  
Sor 57: Sor 102:
   lvcreate -s -L 1G -n blabla /dev/vg/blablalv   lvcreate -s -L 1G -n blabla /dev/vg/blablalv
   lvdisplay -C -S lv_role=snapshot   lvdisplay -C -S lv_role=snapshot
 +
 +==== sudo jog másik userhez ====
 +
 +  non-root-user ALL = (appuser) NOPASSWD: ALL
 +
  
 ==== NMON adatgyűjtés ==== ==== NMON adatgyűjtés ====
Sor 79: Sor 129:
 </file> </file>
  
-==== Ismétlődő sorok számolása ====+==== Email címek extraktálása AIX alatt ====
  
-  cat file | sed 's/([^(]*)$/,&/' | awk -F'[,]' '{a[$2]++}END{for(k in a) print $1,k,$3,"("a[k]"x)"}'+  perl -wne'while(/[\w\.\-]+@[\w\.\-]+\w+/g){print "$&\n"}'
  
-==== /dev/stdin üres-e? (Van-e adat a pipe-ban?) ==== 
- 
-  [ ! -t 0 ] 
- 
-==== Bekezdésre greppelés Linux alatt (AIX: grep -p) ==== 
- 
-  awk 'BEGIN{RS=ORS="\n\n";FS=OFS="\n"}/Storage Slots/ 
- 
-==== Bash színkódok törlése szövegből ==== 
- 
-  sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" 
-==== 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 ([[http://openmaniak.com/iperf.php|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 ==== 
- 
-<file> 
-#!/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 --- 
-</file> 
- 
-==== Processz izolálása hálózaton ==== 
- 
-<file> 
-#!/bin/bash 
-[[ -e /var/run/netns/kalitka ]] || ip netns add kalitka 
-ip netns exec kalitka ip addr add 127.0.0.1/8 dev lo 
-ip netns exec kalitka ip link set dev lo up 
-ip netns exec kalitka $* 
-</file> 
 ==== Hiányzik az "add-apt-repository": ==== ==== Hiányzik az "add-apt-repository": ====
  
Sor 178: Sor 169:
 # Get current swap usage for all running processes # Get current swap usage for all running processes
 # Erik Ljungstrom 27/05/2011 # Erik Ljungstrom 27/05/2011
 +echo "Swappiness: $(cat /proc/sys/vm/swappiness)"
 SUM=0 SUM=0
 OVERALL=0 OVERALL=0
Sor 194: Sor 186:
 </file> </file>
  
-==== 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 ==== ==== Törölt fájlok, amik nem szabadították még fel a helyet ====
   lsof |(sed 1q; grep deleted)   lsof |(sed 1q; grep deleted)
-==== BASH változó manipulációk ====+     
 +==== Hosszú processz végeztéről értesítő email ====
  
-^Syntax^Meaning^ +<file> 
-|${#var} | String length (number of characters in $var).| +#!/bin/bash 
-|${var%%^^%%} | Uppercase alphanumeric characters in $var.+MAILTO="rvenyige@pcs.hu,pagoston@pcs.hu" 
-|${parameter?err_msg},${parameter:?err_msg} | If parameter set, use it, else print err_msg and abort the script with an exit status of 1Both forms nearly equivalent. The : makes a difference only when parameter has been declared and is null.| +SSH="ssh -i /home/pagoston/.ssh/id_rsa pagoston@sapeltora " 
-|${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.| +while [ $($SSH "ps -ef awk '{print $2}'" grep -c "$1") -gt 0 ]; do 
-|${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.| +        sleep 60 
-|${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.| +done 
-|${var#Pattern} | Remove from $var the shortest part of $Pattern that matches the front end of $var.| +echo Lefutott mail -s "Process $1 lefutott (${hostname})" $MAILTO 
-|${var##Pattern} | Remove from $var the longest part of $Pattern that matches the front end of $var.| +</file>
-|${var%Pattern| Remove from $var the shortest part of $Pattern that matches the back end of $var.| +
-|${var%%%%Pattern} | 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]]+==== processz elrejtése a PS kimenetből ====
  
-==== Gyakori BASH RC kódok ==== 
  
-^Exit Code Number ^Meaning ^Example ^Comments^ +<file> 
-|1 |Catchall for general errors |let "var1 = 1/0" |Miscellaneous errors, such as "divide by zero" and other impermissible operations| +/* https://unix.stackexchange.com/a/403918/119298 
-|2 |Misuse of shell builtins (according to Bash documentation) |empty_function() {} |Missing keyword or command| + * capture calls to a routine and replace with your code 
-|126 |Command invoked cannot execute |/dev/null |Permission problem or command is not an executable| + * gcc -Wall -O2 -fpic -shared -ldl -o shim_main.so shim_main.c 
-|127 |"command not found" |illegal_command |Possible problem with $PATH or typo| + * LD_PRELOAD=/.../shim_main.so theprogram theargs... 
-|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)| +#define _GNU_SOURCE /* needed to get RTLD_NEXT defined in dlfcn.h */ 
-|130 |Script terminated by Control-C |Ctl-C |Control-C is fatal error signal 2, (130 128 + 2, see above)| +#include <stdlib.h> 
-|255* |Exit status out of range |exit -1 |exit takes only integer args in the range 0 - 255|+#include <stdio.h> 
 +#include <string.h> 
 +#include <signal.h> 
 +#include <unistd.h> 
 +#include <dlfcn.h>
  
-==== Hiba csatorna színezése ====+typedef int (*pfi)(int, char **, char **); 
 +static pfi real_main;
  
-   $ parancs 2> >(while read line; do echo -e "\e[01;31m$line\e[0m"; done+/* copy argv to new location */ 
-    +char **copyargs(int argc, char** argv){ 
-==== Terminál kurzor pozícionálás ===+    char **newargv malloc((argc+1)*sizeof(*argv)); 
-   +    char *from,*to
-- Position the Cursor: +    int i,len;
-  \033[<L>;<C>H +
-     Or +
-  \033[<L>;<C>+
-  puts the cursor at line L and column C. +
-- Move the cursor up N lines: +
-  \033[<N>+
-- Move the cursor down N lines: +
-  \033[<N>+
-- Move the cursor forward N columns: +
-  \033[<N>+
-- Move the cursor backward N columns: +
-  \033[<N>D+
  
-- Clear the screen, move to (0,0): +    for(i = 0; i<argc; i++){ 
-  \033[2J +        from = argv[i]; 
-- Erase to end of line: +        len = strlen(from)+1; 
-  \033[K+        to = malloc(len); 
 +        memcpy(to,from,len); 
 +        memset(from,'\0',len);    /* zap old argv space */ 
 +        newargv[i] = to; 
 +        argv[i] = 0; 
 +    } 
 +    newargv[argc] = 0; 
 +    return newargv; 
 +}
  
-- Save cursor position: +static int mymain(int argc, char** argv, char** env) { 
-  \033[s +    fprintf(stderr, "main argc %d\n", argc); 
-- Restore cursor position: +    return real_main(argc, copyargs(argc,argv), env); 
-  \033[u+}
  
-==== "Homokóra" - progress icon ==== +int __libc_start_main(pfi main, int argc, 
-v1: +                      char **ubp_av, void (*init) (void), 
-<file> +                      void (*fini)(void), 
-a=1 +                      void (*rtld_fini)(void), void (*stack_end)){ 
-sp="/-\|" +    static int (*real___libc_start_main)() NULL; 
-echo -n ' ' + 
-while true +    if (!real___libc_start_main) { 
-do +        char *error
-    printf "\b${sp:a++%${#sp}:1}" +        real___libc_start_main dlsym(RTLD_NEXT, "__libc_start_main"); 
-done +        if ((error = dlerror()) !NULL) { 
-</file> +            fprintf(stderr, "%s\n", error); 
-v2: +            exit(1); 
-<file> +        } 
-spinner() +    } 
-+    real_main = main; 
-    local pid=$1 +    return real___libc_start_main(mymain, argc, ubp_av, init, fini, 
-    local delay=0.75 +            rtld_fini, stack_end);
-    local spinstr='|/-\' +
-    while [ "$(ps a | awk '{print $1}' | grep $pid)" ]do +
-        local temp=${spinstr#?+
-        printf [%c]  " "$spinstr+
-        local spinstr=$temp${spinstr%"$temp"} +
-        sleep $delay +
-        printf "\b\b\b\b\b\b" +
-    done +
-    printf "    \b\b\b\b"+
 } }
 </file> </file>
 +
 ==== Hasznos oldalak ==== ==== Hasznos oldalak ====
  
-  * [[http://agostonpeter.com/tsm-turi/letix.html|Linux parancsok, kezdőknek (www.letix.hu)]]+  * [[http://tsm.agostonpeter.com/letix.html|Linux parancsok, kezdőknek (www.letix.hu)]]
   * [[http://tldp.fsf.hu/HOWTO/sag-hu/index.html|Linux rendszeradminisztrátorok kézikönyve]]   * [[http://tldp.fsf.hu/HOWTO/sag-hu/index.html|Linux rendszeradminisztrátorok kézikönyve]]
   * [[http://linuxconfig.org/bash-scripting-tutorial|Bash scripting Tutorial]]   * [[http://linuxconfig.org/bash-scripting-tutorial|Bash scripting Tutorial]]
Sor 308: Sor 276:
   * [[http://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/|Keyboard Shortcuts for Bash]]   * [[http://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/|Keyboard Shortcuts for Bash]]
   * [[https://github.com/gdbtek/linux-cookbooks/blob/master/libraries/util.bash|Bash util functions]]   * [[https://github.com/gdbtek/linux-cookbooks/blob/master/libraries/util.bash|Bash util functions]]
 +  * [[https://ef.gy/forwarding-ipv4-to-ipv6|Forwarding IPv4 Ports to IPv6-only Hosts]]
 +  * [[https://www.techrepublic.com/article/how-to-setup-two-factor-authentication-in-linux|Két faktoros authentikáció linuxon]]
 +  * [[https://access.redhat.com/articles/17054|How do I find the FC ID (WWN) of a scsi device/LUN on Red Hat Enterprise Linux?]]