|
42 | 42 | \# Completed on Thu Mar 5 11:22:52 2020
|
43 | 43 |
|
44 | 44 | cat /etc/rsyslog.d/40-iptables.conf
|
45 |
| - :msg, regex, "iptables:" -/var/log/firewall.log \ |
| 45 | + :msg, regex, "iptables:" -/var/log/firewall.log |
46 | 46 | & ~
|
47 | 47 |
|
48 | 48 | sudo /etc/init.d/rsyslog restart
|
@@ -75,96 +75,103 @@ Ejemplo fichero netplan:
|
75 | 75 | # Bash
|
76 | 76 |
|
77 | 77 | ## Ejemplo Bucle For
|
78 |
| -> for i in $(ls -a); do echo "fichero ${i}"; done |
| 78 | + for i in $(ls -a); do echo "fichero ${i}"; done |
79 | 79 |
|
80 | 80 | ## Ejemplo Bucle While infinito
|
81 |
| -> while [ true ]; do echo "hello world\n"; sleep 3; done |
| 81 | + while [ true ]; do echo "hello world\n"; sleep 3; done |
82 | 82 |
|
83 | 83 | ***
|
84 | 84 |
|
85 | 85 | # Shell-script
|
86 | 86 |
|
87 | 87 | # Inicio bash
|
88 | 88 |
|
89 |
| -> #!/bin/bash \ |
90 |
| -> \ |
91 |
| -> ECHO=$(which echo) \ |
92 |
| -> CAT=$(which cat) \ |
93 |
| -> NMAP=$(which nmap) \ |
94 |
| -> RM=$(which rm) \ |
95 |
| -> DIFF=$(which diff) \ |
96 |
| -> ... |
| 89 | + #!/bin/bash |
| 90 | + |
| 91 | + ECHO=$(which echo) |
| 92 | + CAT=$(which cat) |
| 93 | + NMAP=$(which nmap) |
| 94 | + RM=$(which rm) |
| 95 | + DIFF=$(which diff) |
| 96 | + ... |
97 | 97 |
|
98 | 98 | # Function
|
99 | 99 |
|
100 |
| -> function Usage () { \ |
101 |
| -> ${ECHO} -e "SYNTAX ERROR: ${0} [opcion1|opcion2] <nombre>\n" \ |
102 |
| -> exit 1 \ |
103 |
| -> } \ |
| 100 | + function Usage () { |
| 101 | + ${ECHO} -e "SYNTAX ERROR: ${0} [opcion1|opcion2] <nombre>\n" |
| 102 | + exit 1 |
| 103 | + } |
104 | 104 |
|
105 | 105 | ## if - elif - else - fi
|
106 | 106 |
|
107 | 107 | Verificamos los parametros si son nulos, y si primer parametro contiene valor correcto.
|
108 | 108 |
|
109 |
| -> if [[ -z ${1} ]] || [[ -z ${2} ]] ; then \ |
110 |
| -> Usage \ |
111 |
| -> elif [[ "${1}" != "opcion1" ]] && [[ "${1}" != "opcion2" ]] ; then \ |
112 |
| -> Usage \ |
113 |
| -> else \ |
114 |
| -> accion="${1}" \ |
115 |
| -> nombre="${2}" \ |
116 |
| -> fi |
| 109 | + if [[ -z ${1} ]] || [[ -z ${2} ]] ; then |
| 110 | + Usage |
| 111 | + elif [[ "${1}" != "opcion1" ]] && [[ "${1}" != "opcion2" ]] ; then |
| 112 | + Usage |
| 113 | + else |
| 114 | + accion="${1}" |
| 115 | + nombre="${2}" |
| 116 | + fi |
117 | 117 |
|
118 | 118 | Si fichero existe entonces lo borramos:
|
119 | 119 |
|
120 |
| -> if [[ -f "${nombreFichero}" ]] ; then \ |
121 |
| -> ${RM} ${nombreFichero} \ |
122 |
| -> fi |
| 120 | + if [[ -f "${nombreFichero}" ]] ; then |
| 121 | + ${RM} ${nombreFichero} |
| 122 | + fi |
123 | 123 |
|
124 | 124 |
|
125 | 125 | ## Petición parámetros
|
126 | 126 |
|
127 |
| -> ${ECHO} "Introduce un nombre:" \ |
128 |
| -> read -s nombre |
| 127 | + ${ECHO} "Introduce un nombre:" |
| 128 | + read -s nombre |
129 | 129 |
|
130 | 130 | ## Case
|
131 | 131 |
|
132 |
| -> case $opcion in \ |
133 |
| -> 0) \ |
134 |
| -> ${ECHO} -e "[CORRECTO];" \ |
135 |
| -> ;; \ |
136 |
| -> *) \ |
137 |
| -> ${ECHO} -e "[INCORRECTO];" \ |
138 |
| -> ;; \ |
139 |
| -> esac \ |
| 132 | + case $opcion in |
| 133 | + 0) |
| 134 | + ${ECHO} -e "[CORRECTO];" |
| 135 | + ;; |
| 136 | + *) |
| 137 | + ${ECHO} -e "[INCORRECTO];" |
| 138 | + ;; |
| 139 | + esac |
140 | 140 |
|
141 | 141 | ***
|
142 | 142 | # Diff
|
143 | 143 |
|
144 | 144 | ## Ejemplo visualización en columnas
|
145 |
| -> diff -y fichero1.txt fichero2.txt |
| 145 | + |
| 146 | + diff -y fichero1.txt fichero2.txt |
146 | 147 |
|
147 | 148 | ## Ejemplo comparar sin diferenciar espacios en blanco ni tabuladores
|
148 |
| -> diff -wEZB fichero1.txt fichero2.txt |
| 149 | + |
| 150 | + diff -wEZB fichero1.txt fichero2.txt |
149 | 151 |
|
150 | 152 | ## Ejemplo modo silencioso
|
| 153 | + |
151 | 154 | Importa el resultado del commando diff result=0 EXIT OK, result=1 FAIL.
|
152 |
| -> result=$(diff -q --ignore-matching-lines="ntp clock-period" fichero1.txt fichero2.txt) |
| 155 | + |
| 156 | + result=$(diff -q --ignore-matching-lines="ntp clock-period" fichero1.txt fichero2.txt) |
153 | 157 |
|
154 | 158 | ## Ejemplo ignorando lineas
|
| 159 | + |
155 | 160 | Las líneas con contenido "ntp clock-period" son ignoradas.
|
156 |
| -> diff --ignore-matching-lines="ntp clock-period" fichero1.txt fichero2.txt |
| 161 | + |
| 162 | + diff --ignore-matching-lines="ntp clock-period" fichero1.txt fichero2.txt |
157 | 163 |
|
158 | 164 | ## Comandos utilies del diff
|
159 |
| -> diff \ |
160 |
| -> --suppress-blank-empty suppress space or tab before empty output lines \ |
161 |
| -> -y, --side-by-side output in two columns \ |
162 |
| -> -w, --ignore-all-space ignore all white space \ |
163 |
| -> -B, --ignore-blank-lines ignore changes where lines are all blank \ |
164 |
| -> -i, --ignore-case ignore case differences in file contents \ |
165 |
| -> -E, --ignore-tab-expansion ignore changes due to tab expansion \ |
166 |
| -> -q, --brief report only when files differ \ |
167 |
| -> --suppress-common-lines do not output common lines \ |
| 165 | + |
| 166 | + diff \ |
| 167 | + --suppress-blank-empty suppress space or tab before empty output lines |
| 168 | + -y, --side-by-side output in two columns |
| 169 | + -w, --ignore-all-space ignore all white space |
| 170 | + -B, --ignore-blank-lines ignore changes where lines are all blank |
| 171 | + -i, --ignore-case ignore case differences in file contents |
| 172 | + -E, --ignore-tab-expansion ignore changes due to tab expansion |
| 173 | + -q, --brief report only when files differ |
| 174 | + --suppress-common-lines do not output common lines |
168 | 175 |
|
169 | 176 | ***
|
170 | 177 |
|
|
0 commit comments