Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux_wiki:use_shell_scripting_to_automate_system_maintenance_tasks [2016/09/21 23:11] billdozor |
linux_wiki:use_shell_scripting_to_automate_system_maintenance_tasks [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 4: | Line 4: | ||
Review of common shell scripting syntax. | Review of common shell scripting syntax. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Lab Setup ====== | ||
+ | |||
+ | The following virtual machines will be used: | ||
+ | * server1.example.com (192.168.1.150) -> Create and test some scripts | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Help ====== | ||
+ | |||
+ | Finding help in this section. | ||
+ | * Not many references. Be comfortable with basic bash scripting | ||
+ | * Variables | ||
+ | * Arguments | ||
+ | * Input | ||
+ | * Output | ||
+ | * Decisions (if statements, case) | ||
+ | * Loops | ||
---- | ---- | ||
Line 153: | Line 173: | ||
echo "The process($1) is no longer running." | echo "The process($1) is no longer running." | ||
</ | </ | ||
+ | |||
+ | ===== Case Evaluation ===== | ||
+ | |||
+ | Evaluate data and provide matches for expected values. | ||
+ | |||
+ | <code bash> | ||
+ | case $1 in | ||
+ | start) | ||
+ | start_program | ||
+ | ;; | ||
+ | stop) | ||
+ | stop_program | ||
+ | ;; | ||
+ | status) | ||
+ | status_of_program | ||
+ | ;; | ||
+ | *) | ||
+ | echo " | ||
+ | ;; | ||
+ | esac | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Debugging ====== | ||
+ | |||
+ | To debug a script, execute it with a special argument: | ||
+ | <code bash> | ||
+ | bash -x myscript.sh | ||
+ | </ | ||
+ | * -x -> Shows line by line what the script is doing, which allows easier debugging when it breaks | ||
---- | ---- | ||