The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Info msgobinathan Shell Programming and Scripting 1 11-03-2007 05:17 PM
cpu info vijayca HP-UX 1 08-27-2007 08:51 AM
How get more LUN info itsupplies Red Hat 0 10-26-2006 04:22 AM
exe info sumsin High Level Programming 6 11-17-2005 05:15 AM
SU info afflack UNIX for Dummies Questions & Answers 4 01-20-2005 09:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-29-2008
ad4m88 ad4m88 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 8
Some Info.

Hiya all ... i am a newbie to UNIX,

Just want to knwo what this command does:
/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

I think, 'grep shows the line with 'inet addr' (which is the 2nd line, displaying the IP Address, Broadcast Address and Subnet Mask) ... Is this correct?

What does the Second part do? {cut -d: -f2}?

Thanks in advance.

Kind Regards
ad4m88
  #2 (permalink)  
Old 03-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You should find the manual pages for your system. If you are not at the computer, you can easily find them in Google.

This invocation of cut extracts the second field in a colon-delimited line (or sequence of lines, more generally). Similarly, the awk program prints the first field on a space-separated line (or sequence of lines, more generally).

Bottom line, it extracts the IP address of the interface out of the ifconfig output.

The whole process could have been done more elegantly using just ifconfig and awk, possibly at a modest decrease in maintainability, or ifconfig, grep, and two invocations of cut.
  #3 (permalink)  
Old 03-29-2008
ad4m88 ad4m88 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 8
Thanks for your help.

Best Regards.
  #4 (permalink)  
Old 03-29-2008
ad4m88 ad4m88 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 8
Sorry to bother again, but what command will show the name of
1)the running system, &
2)the O/S.

I tried uname -a, how would i cut the info from this using awk or grep. Also by doing uname -o it displays: 'GNU/Linux'. So is that sufficent for the second part?

Thnxs
  #5 (permalink)  
Old 03-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The question about OS is not really well-defined. Probably uname -o is sufficient, yes. It is customary if somebody asks to include more or less all of uname -a

uname -n prints the system's name, so you don't have to use awk for that. grep is not really the right tool for this (although it could probably be done).

Generally a well-designed Unix tool will have an option to generate output in a form which is useful for scripting. Unfortunately, not nearly all system utilities are well-designed by this criterion. (ls comes to mind, and, oh, ifconfig.)

This message box is too small for a good awk tutorial (and I'm not the right person to write that) but a general pattern is awk '/text which is unique for the line you want/ { print $n }' where n is the field number (space-separated, starting from 1) on that line. There are various facilities for using something other than spaces as separators, and, well, awk is a Turing-complete programming language, so your imagination is really the only limit.
  #6 (permalink)  
Old 03-29-2008
ad4m88 ad4m88 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 8
Thanks mate,

Hope im not asking for too much but, How would i write a script in a bash shell that can:
a) reboot the box
b) prefix a reboot with a suitable warning and pause
c) ping an IP address specified by the user and report on the response
d) kill a processes as specified by the user
e) add and delete a user

If you can give me the code for each one, i know how to put it into a menu (if, else if .... etc)

Thanks
  #7 (permalink)  
Old 03-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Are you sure this isn't homework?
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0