Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #!/bin/bash | 1 #!/bin/sh |
f.lopez
2018/05/04 01:50:54
please use /bin/sh instead of /bin/bash
This way
| |
2 | 2 |
f.lopez
2018/05/04 01:50:54
What is this script about? What is the intention o
| |
3 IFS=$'\n' lines=($(cat /dev/stdin)) | 3 # Filter out uninformative output lines from the ldap-sync cron job script |
f.lopez
2018/05/04 01:50:54
you may want to look into doing this with `read(2)
| |
4 | 4 |
5 for (( i=0; i < ${#lines[*]}; i++ )) | 5 last_action="" |
f.lopez
2018/05/04 01:50:54
and while you are looking into the comment above,
| |
6 do | 6 |
7 if [[ ${lines[$i]} != *"Updating"* ]] && [[ ${lines[$i]} != *"Found"* ]] && [[ ${lines[$i]} != *"Synchronizing"* ]] && [[ ${lines[$i]} != "#"* ]]; then | 7 while read line; do |
f.lopez
2018/05/04 01:50:54
the double square brackets (`[[`) is a bash featur
| |
8 echo ${lines[$i]} | 8 case "$line" in |
9 elif [[ ${lines[$i]} == *"Updating"* ]] && [[ ${lines[$i+1]} == *"->"* ]]; the n | 9 *-\>*) |
10 echo ${lines[$i]} | 10 if [ ! -z "$last_action" ] |
11 fi | 11 then |
12 echo "$last_action" | |
13 fi | |
14 | |
15 echo "$line" | |
16 last_action="" | |
17 ;; | |
18 --\ Found\ *\ users* | \ | |
19 \#* | \ | |
20 *Synchronizing\ *\ groups* | \ | |
21 \*\*\ Synchronizing\ *\ users* | \ | |
22 --\ Updating\ user\ \'*\'?\(*\)* | \ | |
23 --\ Updating\ group\ \'*\'* | \ | |
24 --\ Creating\ user\ \'*\'?\(*\)* | \ | |
25 --\ Creating\ group\ \'*\'*) | |
26 last_action="$line" | |
27 ;; | |
28 *) | |
29 echo "$line" | |
30 ;; | |
31 esac | |
12 done | 32 done |
LEFT | RIGHT |