hello,
I want to compare list of default shells with list of shells on a host (to get "missing" and superfluous shells configured on a host).
Below is my current solution in ksh script using arrays.
Do you see it could be done more efficient/easier with e.g. awk or the solution I paste is good enough?
I want to compare list of default shells with list of shells on a host (to get "missing" and superfluous shells configured on a host).
Below is my current solution in ksh script using arrays.
Do you see it could be done more efficient/easier with e.g. awk or the solution I paste is good enough?
Code:
$ cat ./test_arr
#!/bin/ksh
set -A stdshells $(echo $S1|sed s/\,/\ /g)
set -A hstshells $(echo $S2|sed s/\,/\ /g)
checkshells ()
{
for a in "${stdshells[@]}"; do
if [[ " ${hstshells[*]} " != *" $a "* ]]; then
printf "$a(-),"
fi
done
for a in "${hstshells[@]}"; do
if [[ " ${stdshells[*]} " != *" $a "* ]]; then
printf "$a(+),"
fi
done
}
checkshells | awk '{sub(/,$/,"");print}'
$ export S1=/bin/bsh,/bin/csh,/bin/false,/bin/ftponly
$ export S2=/bin/bsh,/bin/csh,/bin/extra,/bin/ftponly
$ ./test_arr
/bin/false(-),/bin/extra(+)
$ export S1=/bin/bsh,/bin/csh,/bin/false,/bin/ftponly,/bin/csh
$ ./test_arr
/bin/false(-),/bin/extra(+)
$ export S2=/bin/bsh,/bin/csh,/bin/extra,/bin/ftponly,/bin/csh,/bin/csh
$ ./test_arr
/bin/false(-),/bin/extra(+)
$ export S1=/bin/bsh,/bin/csh,/bin/false,/bin/ftponly,/bin/csh,/bin/csh2
$ ./test_arr
/bin/false(-),/bin/csh2(-),/bin/extra(+)
$ export S2=/bin/bsh,/bin/csh,/bin/extra,/bin/ftponly,/bin/csh,/bin/csh,EXTRA
$ ./test_arr
/bin/false(-),/bin/csh2(-),/bin/extra(+),EXTRA(+)
$