Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i'm newbie on script,i looking for how to create script then run the command <cat/proc/net/arp> if the 'HW address' show <incomplete>, then run <sudo ifconfig eth0 down> and <sudo ifconfig eth0 up> ,thx
have you figured out how to do this on the command line?
line 2 : if yes, then put the commands in a schipt to automate it.
if no, then figure out how to do this on the command line, then go to line 2, and complete it.
i'm newbie on script,i looking for how to create script then run the command <cat/proc/net/arp> if the 'HW address' show <incomplete>, then run <sudo ifconfig eth0 down> and <sudo ifconfig eth0 up> ,thx
To check if the command cat /proc/net/arp outputs the string incomplete, you can do this:
Code:
if cat /proc/net/arp | grep -q incomplete
then
do whatever you want to do in this case
fi
This means:
the output of the cat command goes into a pipe
the grep command gets its input from the pipe. I.e. it gets the output of the cat command.
the grep command checks if the string incomplete appears in its input
if yes, the if condition is true, and the code between then and fi is executed.
You should probably put the ifconfig command there.
if not, the if condition is false, and the code between then and fi is skipped
the -q option ("quiet") tells grep not to output anything
Rather than ifconfig, I suggest using the ip command. It's up-to-date and can handle more networking features that the aging ifconfig:
create script then run the command <cat/proc/net/arp> if the 'HW address' show <incomplete>, ????
then run <sudo ifconfig eth0 down>
and <sudo ifconfig eth0 up>
Are you sure that is all you want to do?
First work it out in a terminal to check your commands and out put.
put that and the commands to bring down then up your net.
Code:
#!/bin/bash
#if not , or is empty then bring down then up net
[[ -z "$(cat /proc/net/arp | awk 'FNR==2 { print $4}')" ]] && { sudo ifconfig eth0 down ; sudo ifconfig eth0 up ; }
will it do what you want? I do not know, I only completed the steps in your objective, and I do not know your output for the cat command.
Though, I'd say that @berndbausch knows more about the nic interphase output for eth0 because he says to use grep, and suggests to use the 'ip' commands. They supersede ifconfig.
i looking for how to create script then run the command <cat/proc/net/arp> if the 'HW address' show <incomplete>, then run <sudo ifconfig eth0 down> and <sudo ifconfig eth0 up> ,thx
Read the LQ Rules about text-speak, and not using it. And since you know the steps, have 12 years experience with Linux, and have access to the thousands of bash-scripting tutorials you can find online, show us what YOU have done/tried of your own; read the "Question Guidelines".
We are happy to help, but you are just asking people to write scripts for you, and showing no effort of your own.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.