Пошаговое исполнение /bin/sh скриптов

Очень часто для отладки скрипта нужно понять, что же именно сейчас делает bash в данный момент. Для этого открываем нужный нам скрипт:

nano /sbin/grub-install
 и заменяем в самом начале:   #!/bin/sh на #!/bin/sh -x

В итоге при запуске скрипта мы получим вот такой трейс:

+ for file in '${grubdir}/stage1' '${grubdir}/stage2' '${grubdir}/*stage1_5'
+ echo /boot/grub/stage1
/boot/grub/stage1
+ count=5
++ echo /boot/grub/stage1
++ sed 's|^/boot/grub|/grub|'
+ tmp=/grub/stage1
+ test 5 -gt 0
+ dump_boot_block '(hd0,1)' /tmp/grub-install.img.Fh5897
+ sync
+ /sbin/grub --batch --device-map=/boot/grub/device.map
+ grep 'Error [0-9]*: ' /tmp/grub-install.log.DD5898
+ :
+ sleep 1
++ expr 5 - 1
+ count=4
+ test 4 -gt 0
+ dump_boot_block '(hd0,1)' /tmp/grub-install.img.Fh5897
+ sync
+ /sbin/grub --batch --device-map=/boot/grub/device.map
+ grep 'Error [0-9]*: ' /tmp/grub-install.log.DD5898
+ :
+ sleep 1
++ expr 4 - 1
+ count=3
+ test 3 -gt 0
+ dump_boot_block '(hd0,1)' /tmp/grub-install.img.Fh5897
+ sync
+ /sbin/grub --batch --device-map=/boot/grub/device.map
+ grep 'Error [0-9]*: ' /tmp/grub-install.log.DD5898
+ :
+ sleep 1
++ expr 3 - 1
+ count=2
+ test 2 -gt 0
+ dump_boot_block '(hd0,1)' /tmp/grub-install.img.Fh5897
+ sync
+ /sbin/grub --batch --device-map=/boot/grub/device.map
+ grep 'Error [0-9]*: ' /tmp/grub-install.log.DD5898
+ :
+ sleep 1
++ expr 2 - 1
+ count=1
+ test 1 -gt 0
+ dump_boot_block '(hd0,1)' /tmp/grub-install.img.Fh5897
+ sync
+ /sbin/grub --batch --device-map=/boot/grub/device.map
+ grep 'Error [0-9]*: ' /tmp/grub-install.log.DD5898
+ :
+ sleep 1
++ expr 1 - 1
+ count=0
+ test 0 -gt 0
+ test 0 -eq 0
+ echo 'The file /boot/grub/stage1 not read correctly.'
The file /boot/grub/stage1 not read correctly.
+ exit 1

А если ключик -x заменить на -vx, то bash начнет выводить текст блоков кода до вывода трейса, что крайне удобно.


Комментарии

Популярные сообщения из этого блога

Проверка работы почтового сервера из командной строки

Как включить RDP на компьютерах через GPO