add header, a command and file content to bash script

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
3 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like