Visit Our UNIX and Linux User Community


shell script question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script question
# 8  
Old 07-27-2009
well, I surprised that you never heard something like "code tags" during your one year.

anyways, Whenever you post the code (or part of your code), Please select the code and click on the "#" button on the toolbar.
you can see the difference between your post and others reply in this thread.


about your problem:
Code:
server_status= some command | grep "Total error: 0"

what is the actual command here?
also if there is a command then you have to use "$()" or "``".
Code:
server_status=$(some command | grep "Total error: 0")

# 9  
Old 07-27-2009
I never realised that...anyways here is the command

Code:
part_sync_status_edir2=`/opt/novell/eDirectory/bin/ndspath ndsrepair --config-file /srv/eDirectory/edir2/nds.conf -E | grep "Total errors: 0"`;

this is basically novell edirectory related command. when I run this command normally I get output the screen, I'm trying to run this command with shell script to automatically run that command. But when I run that command I'm getting output to the screen instead of going to next line. here is my full script

Code:
if [ -f "/srv/eDirectory/edir2/nds.01" ]; then

part_sync_status_edir2=`/opt/novell/eDirectory/bin/ndspath ndsrepair --config-file /srv/eDirectory/edir2/nds.conf -E | grep "Total errors: 0"`;
  if [ "$part_sync_status_edir2" == "" ]; then
	echo "Edir2 Partition Synchronization Error(s)!! Please Check!!" | mail -s "Edir2 Health Check: Edir2 Partition Sync. Error(s)!" admin@company.com
  fi

Thanks
# 10  
Old 07-27-2009
if you add "set -x" to the beginning of your script you can see what is happening as well as what the variables are set to while it's running. Is it possible the output of the ndspath is different than what you're expecting? Also, I was wondering if your output is going to stderr instead of stdout.
# 11  
Old 07-27-2009
Dont worry about the output coming on to the screen for now.
That can be fixed with a redirection.

1. In the output that you see on the screen, do you see the line
"Total errors: 0"

2. In the below line:
Code:
if [ "$part_sync_status_edir2" == "" ]; then

Why are you using "==" ?
Should it not be "=" ?
I think the below code is good enough:
Code:
if [ "$part_sync_status_edir2" ]; then



---------- Post updated at 03:54 PM ---------- Previous update was at 02:44 PM ----------

Dont you think this will be good enough?
Code:
 
if [ -f "/srv/eDirectory/edir2/nds.01" ]; then
   /opt/novell/eDirectory/bin/ndspath ndsrepair --config-file /srv/eDirectory/edir2/nds.conf -E
   if [ "$?" = "0" ]; then
      echo "All is fine.....removethisline later"
   else
      echo "Edir2 Partition Synchronization Error(s)!! Please Check!!" | mail -s "Edir2 Health Check: Edir2 Partition Sync. Error(s)!" admin@company.com
   fi
fi

# 12  
Old 07-28-2009
Code:
if [ "$part_sync_status_edir2" ]; then

This seems to be working ok but need to do some more testing. I have a question here.
is that work if "part_sync_status_edir2" value not equal to 0 or if there is any other value. Some times i get server may be down error when I run the command. does it work either scenarios?
# 13  
Old 07-28-2009
Try this:

Code:
server_status=`some command | grep "Total error: 0"`

the symbol ` is the back quote. It is needed to redirect output of your command line to variable.

Last edited by gch; 07-28-2009 at 05:08 PM..
# 14  
Old 07-28-2009
Quote:
Originally Posted by s_linux
Code:
if [ "$part_sync_status_edir2" ]; then

This seems to be working ok but need to do some more testing. I have a question here.
is that work if "part_sync_status_edir2" value not equal to 0 or if there is any other value. Some times i get server may be down error when I run the command. does it work either scenarios?
1. Actually, if the return value is not "0",then IF will work accordingly, take care of it.

2. I dont know what "part_sync_status_edir2" does. You will have to experiment.
Within "part_sync_status_edir2" if you ECHO "THIS FAILED", then because the last command executed is ECHO, which was successful, then it will be considered as 0.
But if the last command is an EXIT command with a value, like "exit -1" then you are good to go.

3. Let us take your case. see the code.
Code:
 
part_sync_status_edir2=`/opt/novell/eDirectory/bin/ndspath ndsrepair --config-file /srv/eDirectory/edir2/nds.conf -E | grep "Total errors: 0"`;

Here, because grep is the last command, you will "greps" failure code and not ndspath's failure code.

So the best practise is change the code to (&& instead of a |):
Code:
 
part_sync_status_edir2=`/opt/novell/eDirectory/bin/ndspath ndsrepair --config-file /srv/eDirectory/edir2/nds.conf -E && grep "Total errors: 0"`;

Hope I have successfully confused enough. Smilie

Is "part_sync_status_edir2" a script?

Previous Thread | Next Thread
Test Your Knowledge in Computers #207
Difficulty: Easy
Open Shortest Path First (OSPF) is a routing protocol for Internet Protocol (IP) networks which uses a link state routing (LSR) algorithm.
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