Sunday, February 12, 2017

Parse ACLs and comparison made between 2 files obtained through setacl.exe command

======================================================
copy wealth_source.csv source.csv /y
copy wealth_target.csv target.csv /y

sed -ie "/^\\\\/{n;d}" source.csv
sed -ie "s/   /;/g" source.csv
awk -F; "{if (NF!=0 && $1==\"\") {$1=prev} prev=$1}1" OFS=; source.csv >source2.csv
sed -i "/^\s*$/d" source2.csv
sed -ie "s/=/;/g" source2.csv
sed -ie "/.*;DACL/d"  source2.csv


awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\/,\";\",$2); print}" source2.csv >source3.csv
awk -F";" "BEGIN {OFS=\";\"} {print $0, $1\"\\\\\" $3}" source3.csv >source4.csv

sed -ie "/^\\\\/{n;d}" target.csv
sed -ie "s/   /;/g" target.csv
awk -F; "{if (NF!=0 && $1==\"\") {$1=prev} prev=$1}1" OFS=; target.csv >target2.csv
sed -i "/^\s*$/d" target2.csv
sed -ie "s/=/;/g" target2.csv
sed -ie "/.*;DACL/d"  target2.csv
del sed *.

awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\/,\";\",$2); print}" target2.csv >target3.csv
awk -F";" "BEGIN {OFS=\";\"} {print $0, $1\"\\\\\" $3}" target3.csv >target4.csv


awk -F";" "BEGIN {OFS=\";\"} {print $08, $0}" target4.csv >target5.csv
awk -F";" "BEGIN {OFS=\";\"} {print $08, $0}" source4.csv >source5.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\\\TargetServer\\software/,\"\",$1); print}" target5.csv >target6.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\\\OriginalServer\\Vol1/,\"\",$1); print}" source5.csv >source6.csv

sed -i "/^;/d" target6.csv
sed -i "/^;/d" source6.csv

awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" target6.csv source6.csv > BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV

awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" source6.csv target6.csv > Found-on-target.csv
sed -i "1 i\Value searched;File found on Target (Targetserver);Target Domain found;Target Group found;Target SID found;Target ACL found;Target ACL found;Target ACL found;Source value;Source file;Source Domain;Source group;Source SID;Source ACL;Source ACL;Source ACL" BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV

findstr /c:" Not Found" Found-on-target.csv >only-missings-on-source.csv

del sed *.
======================================================

Script on Windows with awk/sed to parse two files making a comparison between them.
Scenario: robocopied source to target
ReACL is required. Tool used: setacl.exe with mapping.csv file using OLDSID,NEWSID
This script removes what I don't care - Searches based on column or field 1: file/folder+GroupName, if not found it states not found.

0 comments:

Post a Comment