![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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. |
|
||||
|
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 |
|
||||
|
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. |
|
||||
|
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 |
|
||||
|
Are you sure this isn't homework?
|
| Sponsored Links | ||
|
|