• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

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

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
goffer
Asked:
goffer
  • 2
1 Solution
 
ahoffmannCommented:
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
 
gofferAuthor Commented:
Thank you, that works great.  Can you explain why that works though.  What is does && do?  
0
 
ahoffmannCommented:
&& and
|| or
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now