?
Solved

Shell Scripting, I need to a certain line from a file

Posted on 2006-07-23
3
Medium Priority
?
217 Views
Last Modified: 2010-04-22
I'm not really new to shell scripting, but I've never done anything beyond real basic stuff.  I am trying to write a simple shell script to test a network connection.  It is going to be used by people who don't know anything about computers.  I would like for the user to execute a script that will ping a computer on the network and IF the ping is succesful I would like the script to output "Host Alive", if the ping is not succesful I want it to output "Network Down"

So far I've gotten:

echo "Testing Network..."
ping - c 5 [computer]>results


My thoughts were to output the results to the "results" file and then add an IF statement along the lines of:

IF [Line 6]=*ms
     echo "Host Alive"
else echo "Network Down"

My problem is I don't know how to reference the 6th line of a different file.  

I'm kind of in a hurry to figure this out, I would like to have it working by tomorrow so I'm going to give this question 500 points.  Thank you in advance for any help you can give.  And if you know of a better way of accomplishing the same thing (using a shell script) I'm open to a different way of doing this.  Thanks again.
0
Comment
Question by:goffer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 2000 total points
ID: 17164211
ping -c 1 coputer && echo "Host Alive" || echo "Network Down"

# check your ping's man-page, -c option might be -n and things like that ...
0
 

Author Comment

by:goffer
ID: 17164331
Thank you, that works great.  Can you explain why that works though.  What is does && do?  
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17164363
&& and
|| or
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question