===== Linux okosságok ===== ==== Dátum figyelés ==== function date_diff() { 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 } ==== Reboot, ha nem megy a szabályos reboot ==== # echo s > /proc/sysrq-trigger # echo u > /proc/sysrq-trigger # echo s > /proc/sysrq-trigger # echo b > /proc/sysrq-trigger This requests the kernel to do: emergency sync of the block devices; mount readonly of all filesystems; again a sync; force an immediate boot; (you can also use o for poweroff) ==== dm-* device-ok felderítése ==== find /dev/ -name "dm-*" -exec readlink -n {} \; -exec echo " -->" {} \; ==== SCSI (re)scan ==== #!/bin/sh for I in `ls -d /sys/class/scsi_device/*`; do echo ${I} echo "1" > ${I}/device/rescan done #!/bin/sh for I in `ls -d /sys/class/scsi_host/host*`; do echo ${I} echo "- - -" > ${I}/scan done ==== 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 ==== #!/bin/bash echo -n "Fajl nev: " read FNEV echo -n "Blokk meret (Byte): " read BS echo -n "Fajl meret (MByte): " read FS COUNT=$((FS*1024*1024 / $BS)) 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" ==== 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 ==== 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 ==== sudo jog másik userhez ==== non-root-user ALL = (appuser) NOPASSWD: ALL ==== 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 ==== Email címek extraktálása AIX alatt ==== perl -wne'while(/[\w\.\-]+@[\w\.\-]+\w+/g){print "$&\n"}' ==== 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]}}' ==== SWAP használat listázása processzenként ==== #!/bin/bash # Get current swap usage for all running processes # Erik Ljungstrom 27/05/2011 echo "Swappiness: $(cat /proc/sys/vm/swappiness)" SUM=0 OVERALL=0 for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do PID=`echo $DIR | cut -d / -f 3` PROGNAME=`ps -p $PID -o comm --no-headers` for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'` do let SUM=$SUM+$SWAP done echo "PID=$PID - Swap used: $SUM - ($PROGNAME )" let OVERALL=$OVERALL+$SUM SUM=0 done echo "Overall swap used: $OVERALL" ==== Törölt fájlok, amik nem szabadították még fel a helyet ==== lsof |(sed 1q; grep deleted) ==== Hosszú processz végeztéről értesítő email ==== #!/bin/bash MAILTO="rvenyige@pcs.hu,pagoston@pcs.hu" SSH="ssh -i /home/pagoston/.ssh/id_rsa pagoston@sapeltora " while [ $($SSH "ps -ef | awk '{print $2}'" | grep -c "$1") -gt 0 ]; do sleep 60 done echo Lefutott | mail -s "Process $1 lefutott (${hostname})" $MAILTO ==== processz elrejtése a PS kimenetből ==== /* https://unix.stackexchange.com/a/403918/119298 * capture calls to a routine and replace with your code * gcc -Wall -O2 -fpic -shared -ldl -o shim_main.so shim_main.c * LD_PRELOAD=/.../shim_main.so theprogram theargs... */ #define _GNU_SOURCE /* needed to get RTLD_NEXT defined in dlfcn.h */ #include #include #include #include #include #include typedef int (*pfi)(int, char **, char **); static pfi real_main; /* copy argv to new location */ char **copyargs(int argc, char** argv){ char **newargv = malloc((argc+1)*sizeof(*argv)); char *from,*to; int i,len; for(i = 0; i ==== Hasznos oldalak ==== * [[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://linuxconfig.org/bash-scripting-tutorial|Bash scripting Tutorial]] * [[http://sed.sourceforge.net/sed1line.txt|Handy one-liners for SED]] * [[http://www.grymoire.com/Unix/Sed.html|Sed - An Introduction and Tutorial by Bruce Barnett]] * [[http://tldp.org/LDP/abs/html/index.html|Advanced Bash-Scripting Guide]] * [[http://gsteph.blogspot.hu/2007/04/bash-reading-text-file.html|BASH: Reading Text File]] * [[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://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?]]