LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-16-2012, 10:31 AM   #1
Joeblah
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Rep: Reputation: Disabled
Help needed for simple IP reset script


Hello,
Alright so I am more of a Windows guy still trying to learn Linux.
I need to create a simple script to reset the IP and check it.

These are what I was hoping to run, just when I tried to create my own script, it fails.

I know this is not right but I was trying, can someone can please help me with creating this properly. I was wondering if it is also possible just to display an IFCONFIG on eth0?

Code:
#!/bin/bash
clear
#
/etc/init.d/networking restart
#
ifconfig

Last edited by Joeblah; 07-16-2012 at 10:48 AM.
 
Old 07-16-2012, 10:36 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
You don't need to call echo in front of ifconfig.
Just run ifconfig and it presents it output magicaly

What are you trying to achive? Comparing the two outputs before and after?

Just a little hint. GEt familiar with the ip command. It's the new way of doing things.
 
Old 07-16-2012, 10:46 AM   #3
Joeblah
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Okay, sorry I should of explained a little better.
It's a little Eee PC machine I use for work to test connectivity through ports and firewalls at remote sites. However I did not originally set up the machines so not everything that we would like is installed. Example, vi will not open an editor, had to use gedit.

They were given static addresses to connect through a 3002 VPN. Some locations like Hotels do not allow you access until you accept their TOA. Now I had to manually do this with a customer and it was annoying to constantly have him type and hit the Up arrow for commands.
So I changed it to DHCP but I need to be able to reset the IP of eth0 between a privately given IP from the hotel and the one the 3002 VPN wants to give it (172.31.1.2).

I would also like to try and display the IP so that we can confirm what it is currently at. It's difficult to try and correct this when I am unsure of what I am doing still.

I did try at first without the Echo but I failed to even see a terminal appear or anything.
 
Old 07-16-2012, 10:53 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Okay. First thing is that linux is case sensitive. As you have Echo in your line 4 which gives
Code:
./trial.sh: line 4: Echo: command not found
just use echo with all lower chars.

Another thing is that you don't need to use echo in front of commands they print what they print to the output. echo is for output of message for the user like
Code:
echo 'Restarting network'
/etc/init.d/networking restart
echo 'Showing IP settings'
ip addr
 
Old 07-16-2012, 11:15 AM   #5
Joeblah
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Okay, So the only thing I am having an issue with is trying to print this for the user to see what is going on. It happens in a flash and I remember how to do it in a batch file but not a shell script

Code:
#!/bin/bash
clear
#
echo 'Restarting Network'
/etc/init.d/networking restart
echo 'Displaying IP Address'
ip addr show eth0
zhjim,
I want to thank you for the taking the time to help me with this. I know its trivial for you but it is also what makes me want to get into linux when I know people are willing to help through all the entry level questions.
 
Old 07-16-2012, 11:27 AM   #6
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Try this one
Code:
#!/bin/bash
clear
#
echo 'Restarting Network'
/etc/init.d/networking restart
echo 'Displaying IP Address'
ip addr show eth0 | grep inet | awk '{print $2 }'
read
'|' is the pipe symbol and forwards output to next commands input
grep searches for a string. I guess you only want the ip address
awk is for printing stuff nice and other things. We want the second field which holds the ip.
read just waits for input. This makes sure the window stays open.

You get the ipv4 as well as the ipv6 address. Suite to your likings.



Quote:
Originally Posted by Joeblah View Post
zhjim,
I want to thank you for the taking the time to help me with this. I know its trivial for you but it is also what makes me want to get into linux when I know people are willing to help through all the entry level questions.
You're welcome. We all started somewhere. I'd say on linuxquestions you'll find a lot of helpful people as long as you adopt some simple rules. Just like in any forum. Be nice, be as explicit as it can be, and have a crate of beer in reach
If you feel so you can click the "Was that post helpfull" to fill my karma a bit.

Last edited by zhjim; 07-16-2012 at 11:29 AM. Reason: read explained added
 
1 members found this post helpful.
  


Reply



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
Help needed with simple bash script clifford227 Linux - Newbie 4 10-03-2011 10:46 AM
simple script needed for file renaming frankkky Programming 8 09-20-2008 10:19 AM
simple shell script help needed vbsaltydog Linux - Networking 10 05-02-2006 01:47 AM
simple script needed drum2jc Linux - Software 1 01-05-2006 12:28 AM
simple backup script needed ferret_dude Programming 4 05-24-2004 08:45 AM

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

All times are GMT -5. The time now is 09:29 PM.

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