Example Bash
Различия
Здесь показаны различия между двумя версиями данной страницы.
Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
example:example_bash [18.03.2019 16:33] admin Approved(admin 2019/03/18 16:33) |
example:example_bash [30.08.2019 11:12] (текущий) admin Approved(admin 2019/08/30 11:12) |
||
---|---|---|---|
Строка 1: | Строка 1: | ||
+ | ==== help ==== | ||
+ | <code bash> | ||
+ | # как узнать версию linux ###version ###linux ###redhat-release ###lsb_release ###uname ### | ||
+ | cat /etc/issue | ||
+ | cat /etc/*-release | ||
+ | </code> | ||
==== syntax ==== | ==== syntax ==== | ||
<code bash> | <code bash> | ||
- | # bash case ###bash ###case ##select | + | # bash case ###bash ###case ###select |
case "$VM_TMPLT_OS" in | case "$VM_TMPLT_OS" in | ||
centos-6*|centos6*) | centos-6*|centos6*) | ||
Строка 11: | Строка 17: | ||
esac | esac | ||
- | </code> | ||
- | ==== grub ==== | ||
- | <code bash> | ||
- | # grub запустить ядро 1 раз ###savedefault ###default=0 ###once | ||
- | grub> savedefault --default=0 --once | ||
- | grub> quit | ||
</code> | </code> | ||
- | ==== perf ==== | ||
- | <code bash> | ||
- | # профилирование ###perf ###oprofile ###nmi | ||
- | yum --enablerepo='base-debuginfo' install kernel-debuginfo-`uname -r` kernel-devel perf oprofile gdb kexec-tools crash | ||
- | perf top -d 5 -U | ||
- | perf top -d 5 -g -U | ||
- | perf stat -e task-clock,cycles,instructions,cache-references,cache-misses sleep 5 | ||
- | perf record -a sleep 5 и потом perf report | ||
- | # профилирование ###perf ###oprofile ###nmi | ||
- | echo 0 > /proc/sys/kernel/nmi_watchdog | ||
- | opcontrol --deinit | ||
- | opcontrol --init | ||
- | opcontrol --reset | ||
- | opcontrol --start --vmlinux=/usr/lib/debug/lib/modules/2.6.32-642.el6.x86_64/vmlinux | ||
- | # но иногда можно и --no-vmlinux если нам не важно про ядро, а только про юспейс | ||
- | # если баг Failed to open profile device: Device or resource busy, то стопаем все виртуалки KVM, одна из них залочила nmi | ||
- | sleep 10 # ждем сбора статистики | ||
- | opcontrol --stop | ||
- | # включаем watchdog обратно | ||
- | echo 1 > /proc/sys/kernel/nmi_watchdog | ||
- | </code> | ||
==== find ==== | ==== find ==== | ||
Строка 46: | Строка 25: | ||
# Найти все файлы исключая скрытые файлы и скрытые каталоги ###find ###exclude ###hidden | # Найти все файлы исключая скрытые файлы и скрытые каталоги ###find ###exclude ###hidden | ||
find $SRC -type f -not -path '*/\.*' | find $SRC -type f -not -path '*/\.*' | ||
+ | find . -name 'objects' -not -path '*.trash*' | ||
# Найти и обработать файлы с пробелами ###find ###xargs | # Найти и обработать файлы с пробелами ###find ###xargs | ||
Строка 51: | Строка 31: | ||
# заменить во всех файлах по маске шаблону текст ###find ###sed | # заменить во всех файлах по маске шаблону текст ###find ###sed | ||
- | find . -type f -name '*.css' -exec sed -i 's/http:/https:/g' {} \; | + | find . -type f -name '*.css' ! -path '*/.git/*' -exec sed -i 's/http:/https:/g' {} \; |
или find . -type f | xargs -n 1 sed -i 's/fox-vz/fox_vz/' | или find . -type f | xargs -n 1 sed -i 's/fox-vz/fox_vz/' | ||
Строка 154: | Строка 134: | ||
exit 0 | exit 0 | ||
</code> | </code> | ||
- | ==== Статистика и диагностика ==== | ||
- | <code bash> | ||
- | # Кто использует swap ###swap | ||
- | smem -kts swap | ||
- | # Насколько используется диск ###disk ###io ###iostat | ||
- | iostat -kt 1 | ||
- | # Кто использует диск ###iotop ###disk ###io | ||
- | iotop -kPd 5 | ||
- | #Разовый top по всем процессам ###top | ||
- | top -n 1 -b | ||
- | # Кто использует swap ###swap | ||
- | smem -kts swap | ||
- | # Просмотр swap активности за дату 21 число в 16 часов ###sar ###stat ###loadavg | ||
- | LANG=C sar -q -f /var/log/sa/sa21 | grep 16: | ||
- | # Просмотр swap активности за дату 21 число в 16 часов ###sar ###stat ###loadavg | ||
- | LANG=C sar -q -f /var/log/sa/sa21 | grep 16: | ||
- | </code> | ||
==== Прочее ==== | ==== Прочее ==== | ||
<code bash> | <code bash> | ||
Строка 295: | Строка 258: | ||
</code> | </code> | ||
- | ==== ssh back-connect ==== | ||
- | <code bash> | ||
- | # В данной заметке пойдёт речь про более хитрое использование SSH для оказания удалённой помощи серверу, находящемуся за NAT. | ||
- | # Заходим на машину клиента: | ||
- | ssh root@10.90.10.150 | ||
- | # На машине клиента выполняем команду | ||
- | ssh -R 1522:localhost:22 root@gate.carbonsoft.ru -p 22 | ||
- | # Вводим пароль и установливаем соединение. | ||
- | # Далее на gate.carbonsoft.ru выполняем вход к клиенту. | ||
- | ssh root@localhost -p 1522 | ||
- | </code> | ||
- | ==== systemd ==== | ||
- | Очистка кэша DNS | ||
- | |||
- | <code> | ||
- | systemd-resolve --flush-caches | ||
- | </code> | ||
~~OWNERAPPROVE~~ | ~~OWNERAPPROVE~~ | ||