Jump to content

Php To Bash Script Help


amoeba

Recommended Posts

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.list
exec("$ > 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.list
exec("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]

Link to comment
Share on other sites

I solved my problem


#!/bin/bash
rows=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.leases
rm known.out
saveIFS="$IFS"
IFS=$'\n'
array=($(<$file))
IFS="$saveIFS"
for i in "${array[@]}"; do cat /tmp/dhcp.leases | grep $i >> known.out; done
# Create unknown.out
cat /tmp/dhcp.leases > connected.list
cat connected.list > unknown.out
saveIFS="$IFS"
IFS=$'\n'
array=($(<$file))
IFS="$saveIFS"
# echo ${array[0]} # outputs first line
for i in "${array[@]}"; do sed -i '/'$i'/d' unknown.out; done
[/CODE]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...