LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-14-2019, 09:17 PM   #1
hkcyber
LQ Newbie
 
Registered: May 2007
Posts: 7

Rep: Reputation: 0
how to create script for network restart? thx


Dear All

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
 
Old 04-14-2019, 09:57 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.
 
Old 04-14-2019, 10:15 PM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by hkcyber View Post
Dear All

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:
Code:
sudo ip link set eth0 up
Some distros don't deploy ifconfig anymore.
 
1 members found this post helpful.
Old 04-14-2019, 11:54 PM   #4
hkcyber
LQ Newbie
 
Registered: May 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Smile

Quote:
Originally Posted by berndbausch View Post
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:
Code:
sudo ip link set eth0 up
Some distros don't deploy ifconfig anymore.
It work! Thankyou
 
Old 05-04-2019, 04:16 AM   #5
jenniT
LQ Newbie
 
Registered: May 2019
Posts: 1

Rep: Reputation: 0
not understand
 
Old 05-04-2019, 09:46 AM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by jenniT View Post
not understand
OK: steps:
Objective:
Quote:
Originally Posted by jenniT
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.
Code:
$ cat /proc/net/arp
  1                  2         3             4                  5         6
IP address       HW type     Flags       HW address            Mask     Device
1xx.xx.xx.x      0x1         0x2         9c:1c:12:c9:7a:f0     *        wlan0
that requires you use something to get the HW address. awk in this case
Code:
$ cat /proc/net/arp | awk 'FNR==2 { print $4}'
9c:1c:12:c9:7a:f0
put that into a variable then check to see if it is empty or not.
Code:
[ -n "$(cat /proc/net/arp | awk 'FNR==2 { print $4}')" ]] && { echo "up" ; }
up
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.

what just hold on : jenniT is not even the OP...

Last edited by BW-userx; 05-04-2019 at 09:58 AM.
 
Old 05-05-2019, 10:29 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by hkcyber View Post
Dear All
i'm newbie on script,
A 'newbie', who's been here for TWELVE YEARS???
Quote:
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.
 
  


Reply

Tags
arp, incomplete



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to import a variable from C++ program to TCL script? THX haiying7 Linux - Software 4 09-24-2012 07:31 PM
[SOLVED] Have to restart network on restart? sapslaj Linux - Networking 5 06-30-2012 02:02 PM
How do I set the regulatory daemon to restart when I restart the network service? zahadumy Linux - Networking 0 11-05-2006 11:24 AM
Diskless With WINDOWS98,someone tell mei HOW TO,,thx xblue Linux - Networking 1 10-11-2002 02:15 AM
THX Trickykid! fxlee Linux - Newbie 2 01-30-2002 10:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration