FastNetMon

Monday 15 November 2010

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

Часто для отладки нужно понять, что же именно сейчас делает bash в данный момент, это весьма легко, открываем нужный нам скрипт:
vi /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 начнет выводить текст блоков кода до вывода трейса, что крайне удобно.

No comments :

Post a Comment

Note: only a member of this blog may post a comment.