Visit Our UNIX and Linux User Community


shell script question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script question
# 1  
Old 07-24-2009
shell script question

I have script as following..

server_status= some command | grep "Total error: 0"
if [ "$server_status= "server may down""]; then
echo " Server $(hostname) is Down" >>Result
fi
else
echo " Server is OK on $(hostname)" >>Result


the if command seems to be not working properly for some reason. I dont even see the out put file.

when I do
server_status= some command | grep "Total error: 0"

it gave me the error "server may down".

Any ideas. Please help
# 2  
Old 07-24-2009
Your 'fi' is in the wrong place.

Code:
if [ something ] then;
  do something
else
  do something else
fi

# 3  
Old 07-24-2009
if I put 'fi', it should give me the error right?

if [-f /src/srv1] then
server_status= some command | grep "Total error: 0"
if [ "$server_status= "server may down""]; then
echo " Server $(hostname) is Down" >>Result
fi
else
echo " Server is OK on $(hostname)" >>Result
fi

its going to else condition, and now I got a output file and i see that server is OK, even the server is down. I think problem with "if [ "$server_status= "server may down""]; then" . I'm really not sure if this is right. Thanks.
# 4  
Old 07-24-2009
If you used code tags it would be easier to read for everyone who's trying to help you.

Last edited by Scott; 07-24-2009 at 05:59 PM..
# 5  
Old 07-24-2009
Please use the code tags to make this more readable. I didn't at first notice the nested if statements. Also, something burned into my head in high school (many, many moons ago) was code formatting for easier reading/debugging.

Code:
if [-f /src/srv1]
then
  server_status= some command | grep "Total error: 0"
  if [ "$server_status= "server may down""]
  then
    echo " Server $(hostname) is Down" >>Result
  else
    echo " Server is OK on $(hostname)" >>Result
  fi
fi

your code will say the server is OK only if /src/srv1 doesn't exist. I've moved the code around a bit, give this a go.
# 6  
Old 07-24-2009
Fix your code.
Code:
if [ "$server_status= "server may down""]

Change it to:
Code:
if [ "$server_status" = "server may down"]

# 7  
Old 07-27-2009
Thanks for your reply. code tags???

I tried with

if [ "$server_status" = "server may down"]

but I dont see the out file name when server is down. I think as soon as it reads this line "server_status= some command | grep "Total error: 0" and as the server is down, it's giving error saying server is down. it should go to the next line and check if condition, then it should create a file.

small change is the code, instead of checking for file, I'm checking for the directory with -d option.
Thanks

Previous Thread | Next Thread
Test Your Knowledge in Computers #488
Difficulty: Medium
Some languages are interpreted, not compiled, and the source code is contained in a file usually referred to as a text-based assembly unit.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script question

As per code it is getting matched. not sure why it assigning to cols=0. Any inputs please. Input : passed is shell.sh c tablename. if ; then cols=1 table=$2 else cols=0 table=$1 fi (1 Reply)
Discussion started by: ramkumar15
1 Replies

2. Shell Programming and Scripting

Shell script question

Hi all, can you plz check whether the below code is correct & some inputs. I need to read the below file and process it. input : /home/ibm/var.txt urgent not urgent not needed. #!/usr/bin/ksh VAR=/home/ibm/var.txt if ] then (7 Replies)
Discussion started by: ramkumar15
7 Replies

3. Homework & Coursework Questions

question in shell script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a Bourne shell script which: Has one command line argument. If the command line argument is a... (5 Replies)
Discussion started by: abood1190
5 Replies

4. Homework & Coursework Questions

question on shell script

hiiiiiiiiiiiii,,I found an error on my following script but couldnt find it!!! Can you please help me as soon as possible?! echo "enter a number " read n i=0 first=0 second=1 result=0 prime="true" echo –n " $first $second " while do result=`expr $first + $second` first=$second... (10 Replies)
Discussion started by: moonlips
10 Replies

5. Homework & Coursework Questions

Question on shell script

Hiiiiiiiiiiiii all, Please i want your help fast, the teacher gave us this assignment can u help me to write it? this is the question: Write a shell script to point all prime numbers from the fibonacci series of integer N? using Red hat Os Thanks all and waiting for ur answers... (1 Reply)
Discussion started by: moonlips
1 Replies

6. Shell Programming and Scripting

shell script question

Hi, The contents of my file is below: Name,Location,Degree,Gender,Awards Robert,Philadelphia,Accounting,Male,5 Jane,Chicago,Business,Female,2 Allan,New York,Engineering,Male,6 Tom,Detroit,Computer Science,Male,10 Nancy,Milwaukee,Engineering,Female,4 I want to add a "ID" in the 1st line... (2 Replies)
Discussion started by: xinoo
2 Replies

7. Shell Programming and Scripting

Shell Script question

Hello Experts, I am new at this and need some help. I am looking for a delete command that allows me after I grep for the hostname to delete all the lines between two characters. for example I want to delete the first line all the way up to the } character host test019 { hardware ethernet... (10 Replies)
Discussion started by: ryanique
10 Replies

8. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies

9. Shell Programming and Scripting

Shell script question

Hello, i am doing a project for school and i cannot figure out whats wrong with my 2 programs they dont seem to work at all. the first program is called isprime and naturally it checks to see if hte number is prime or not here is my code: #!/usr/bin/bash num=$1 echo you typed if ... (2 Replies)
Discussion started by: jbou1087
2 Replies

10. Shell Programming and Scripting

shell script question

I am using ksh. There is a report having amounts in the following format, 34343.67- 2343.45 23434.89- I want to sum up all the amounts. For this I first need to find out if there is a minus sign at the end and prefix it before summing up. How to achieve this? I thought of using an... (2 Replies)
Discussion started by: tselvanin
2 Replies

Featured Tech Videos