BASH scripting lesson 8 using TRAP to control scripts

preview_player
Показать описание
Now we really have some fun with our scripts adding in TRAP to help make the scripts more robust. We may need our script to exit correctly each time. We can do this by creating a PID file and checking for its existence. If it does exist then the script did not exit cleanly last time. we also then must make sure we provide a method to delete the file as we exit. Scripts normally do not respond to terminate signals sent from kill, but we too can eable this with traps to make sure we listen to calls from the system, I am sure this will help with your scripts and you will want to implement these ideas in some of your projects.
Рекомендации по теме
Комментарии
Автор

Hi,

A question, what would you do if you start a program in a subprocess (background), like a java application via your script and you still need to have PID files to protect your startup script from launching multiple java background apps and delete that .pid file when java app exits?

benjaminshtark
Автор

Hi Andrew, Great tutorial for trap, Since you have used many environmental variables and switches = flags within scripts with place holders, it is very hard to understand and in middle of flow we are getting lost... Please if you can make one separate video for BASH environmental variables and switches = flags to use within script. Very good tutorial but hard to follow after watching many times. Thanks.

arifpatel
Автор

Hello, why you use double parentheses or nest parentheses (( count < 10 )) and (( count ++ ))? is ( count < 10 ) wrong?

kevinh
Автор

Why behind trap statement you have EXIT in capital letters, while in loop exit is in small? is it always like that?

Starcom
Автор

Cool! Learnt more and indeed understand a bit deeper on Linux OS <3

muniu
Автор

What key did you press to exit from bash code??

mariusmurzea
Автор

Very nice explanation... Thank you !!!

sanjay
visit shbcf.ru