The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
what is wrong with this script? rs1969 UNIX for Dummies Questions & Answers 2 11-15-2007 07:16 AM
What's wrong with this script amitg1980 Shell Programming and Scripting 3 11-12-2007 07:00 PM
What is wrong with this script? heprox Shell Programming and Scripting 8 11-16-2006 05:43 AM
what is wrong with this script? circleW Shell Programming and Scripting 2 09-28-2004 09:27 PM
What is wrong with my script? Lem2003 UNIX for Dummies Questions & Answers 6 05-29-2003 02:17 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-09-2007
hankooknara hankooknara is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 80
what is wrong with this script?

why??? I don't get it..

while read line
do
count=$(ping -c 3 $line | grep 'received' | awk -F ',' '{print $2}' | awk '{print $1}')
if [ $count -eq 0 ] ; then
echo "Host: $line is down"
else
echo "Host: $line is up"
fi
done<host.list

sh -x ./hoststatus
./hoststatus: syntax error at line 5: `count=$' unexpected
~
  #2 (permalink)  
Old 06-09-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,556
what's the format of your host.list and your shell?
  #3 (permalink)  
Old 06-09-2007
hankooknara hankooknara is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 80
hello,

#! /bin/sh

and

host file looks like

server1
server2
server3
server4

and so on
  #4 (permalink)  
Old 06-09-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,556
another way to write:

Code:
for line  in $(tr '\n' ' ' < "file")
do
 count=$(ping -c 3 $line | grep 'received' | awk -F ',' '{print $2}' | awk '{print $1}')
 if [ $count -eq 0 ] ; then
   echo "Host: $line is down"
 else
   echo "Host: $line is up"
 fi
done

  #5 (permalink)  
Old 06-09-2007
hankooknara hankooknara is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 80
I will try that.. but can you please explain why my script did not work?
  #6 (permalink)  
Old 06-09-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
var=$(command)
is not supported by the old Bourne shell. On your OS, /bin/sh may be the old Borne shell... Solaris comes to mind as an example of that. Switch to ksh or bash and see if that helps.
  #7 (permalink)  
Old 06-09-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
For Bourne shell, replace :

Code:
$(command...)

by

Code:
`command...`

Jean-Pierre.
Closed Thread

Bookmarks

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 07:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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