amoeba Posted August 25, 2012 Share Posted August 25, 2012 Can someone help me make gen.sh from this php code? <?$total = 0; // Just for testing, can be removed$file = "known.list";$page = join("",file("$file"));$kw = explode("\n", $page);// Create known.out file with mac adresses from known.listexec("$ > known.out");for($i=0;$i<count($kw);$i++){$total = $i+1;exec("cat /tmp/dhcp.leases | grep $kw[$i] >> known.out");}// Create unknown.out file with all connected mac adresses excluding mac's from known.listexec("cat /tmp/dhcp.leases > connected.list");exec("cat connected.list > unknown.out");for($i=0;$i<count($kw);$i++){exec("sed -i '/$kw[$i]/d' unknown.out");}?>[/CODE] Quote Link to comment Share on other sites More sharing options...
amoeba Posted August 25, 2012 Author Share Posted August 25, 2012 I solved my problem #!/bin/bashrows=0;mac="xx:xx:xx:xx:xx"file="known.list"for f in known.list; do let rows+=`wc $f | awk '{print $1}'` done# Use known.list to filter mac adresses from dhcp.leasesrm known.outsaveIFS="$IFS"IFS=$'\n'array=($(<$file))IFS="$saveIFS"for i in "${array[@]}"; do cat /tmp/dhcp.leases | grep $i >> known.out; done# Create unknown.outcat /tmp/dhcp.leases > connected.listcat connected.list > unknown.outsaveIFS="$IFS"IFS=$'\n'array=($(<$file))IFS="$saveIFS"# echo ${array[0]} # outputs first linefor i in "${array[@]}"; do sed -i '/'$i'/d' unknown.out; done[/CODE] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.