Based on this post, I want to automate this process, so i need to add a command and header to a bash script + the contents of a file to run ubuntu 18.04 and create a static arp table. Example my .sh:
lan=eth0
awk -F";" '{print $3 " " $2}' infile | xargs -I {} echo {} > outfile
note: infile content ip mac
output:
192.168.1.1 00:e0:1e:b4:12:42
192.168.1.2 00:e0:1e:b4:13:43
First problem: empty header. Need "#!/bin/sh" or "#!/bin/bash", solved by:
sed -i -e '1i#!/bin/bash\'
Second problem: missing add arp command "arp -i $lan -s". Solved by:
sed -e 's/^/arp -i $lan -s /'
now i need to bind these commands to get this output:
#!/bin/bash
arp -i eth0 -s 192.168.1.1 00:e0:1e:b4:12:42
arp -i eth0 -s 192.168.1.2 00:e0:1e:b4:13:43
What should I fix at my command to add this content? thk
Update (solved, but...)
lan=eth0
awk -F";" '{print $3 " " $2}' infile | xargs -I {} echo {} | sed -e 's/^/arp -i $lan -s /' | sed -e '1i#!/bin/bash\' > outfile
Now the problem is variable $lan
#!/bin/bash
arp -i $lan -s 192.168.1.1 00:e0:1e:b4:12:42
arp -i $lan -s 192.168.1.2 00:e0:1e:b4:13:43
instead of
#!/bin/bash
arp -i eth0 -s 192.168.1.1 00:e0:1e:b4:12:42
arp -i eth0 -s 192.168.1.2 00:e0:1e:b4:13:43