Sponsored Content
Top Forums Shell Programming and Scripting If condition on shell not working , not sure what is the mistake I am doing? Post 303034951 by Varja on Thursday 9th of May 2019 11:51:09 PM
Old 05-10-2019
If condition on shell not working , not sure what is the mistake I am doing?

I have a requirement to perform specific set of tasks based on server , So I want to have the condition(s) defined based on server. Here is the script I came up with and I have read multiple blogs and couldn`t find any mistake from my script. Can you guide on what I am overlooking here ?

Code:
#!/bin/bash
SERVER_NAME=`hostname -s`
hostname -s
DBServer=(servr1 servr2 servr3 servr4)
echo "Values of DBServer seeing is ${DBServer[*]}"
Values of DBServer seeing is servr1 servr2 servr3 servr4
for i in ${DBServer[*]}
do
  echo "current value in I is $i"
  echo "The server name found is $SERVER_NAME"
  if [$SERVER_NAME == $i]
  then
    echo "I am on one of the servers and it is $i"
  fi
done

Output I see on server is

Code:
current value in I is servr1
The server name found is servr1
-bash: [servr1: command not found
current value in I is servr2
The server name found is servr1
-bash: [servr1: command not found
current value in I is servr3
The server name found is servr1
-bash: [servr1: command not found
current value in I is servr4
The server name found is servr1
-bash: [servr1: command not found


Last edited by Varja; 07-24-2019 at 01:09 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If condition not working

Hi Gurus, I have shell script in which i have to check if time is between to possible value or not. For that i am using following line of code if then echo 'Found In Between' echo $ftime ... (5 Replies)
Discussion started by: MANISH KU
5 Replies

2. Shell Programming and Scripting

Help with shell script to check the condition.

:) Hi, I want to script for this scenerio, OSR Settings Scenario : We are looking to find all the *.a files from the following locations in the filesystem of a server. OSR Directories /etc /bin /usr/bin /usr/sbin /var/adm These *.a files should have the permissions on... (12 Replies)
Discussion started by: sakthilinux
12 Replies

3. Shell Programming and Scripting

wild card in if condition not working

Hi, I am using RHEL5. I have following if condition. if In the above condition, if the value of a contains word WARNING, it should match. i.e., WARNING_MESSAGE, CRITICAL WARNING, WARNING ALERT etc. it should match. For b, alert error, ALERT ERROR, ERROR IMMEDIATE ACTION REQUIRED, etc... (2 Replies)
Discussion started by: user7509
2 Replies

4. UNIX for Advanced & Expert Users

If condition and htm not working

checkSync() { CONNECT_STRING=TLDB61/TLDB61@TL10G SQLPLUS_SETTINGS="SET PAGESIZE 0 LINESIZE 1500 ECHO OFF TRIMS ON TAB OFF FEEDBACK OFF HEADING OFF" SQL_RESULT_SYNC_PMCM=`sqlplus -s ${CONNECT_STRING} << EOF ${SQLPLUS_SETTINGS} (SELECT... (2 Replies)
Discussion started by: madfox
2 Replies

5. Shell Programming and Scripting

IF condition against a ARRAY in shell script

Hi, I want to check a particular string inserted by User to be checked against the values i already have in a ARRAY string using IF condition. Is this possible? if yes how to do that. example : i have a,b,c,d,e,f values in a array called values i asked user to enter a value: user entered... (2 Replies)
Discussion started by: kukretiabhi13
2 Replies

6. Shell Programming and Scripting

Using ssh to transfer file not working inside if-condition

Hi all, ssh uname@remote_server 'cat /tmp/remote_file_name > home_dir/a512386/new/local_file_name' The above given command is working fine. but if i try to move the file only if exists in the remote server i.e) giving the same within if condition it executes but the file is not stored in my... (1 Reply)
Discussion started by: Shri123
1 Replies

7. UNIX for Dummies Questions & Answers

While condition in shell script

while do if ;then read driverName else driverName="" fi done can anyone please explain what exactly is happening on 1st line...is it like the conditions being ORed...I have no clue about this. (4 Replies)
Discussion started by: rtagarra
4 Replies

8. Shell Programming and Scripting

Shell variable as awk condition

Hi, I'm trying to automate part of a script which uses awk to grab out some lines of a log file based on certain fields matching. For example, my log file looks something like the following (but 1000s of lines): 1 Tom 123 abc 345 2 Dick 345 abc 678 3 Harry 567 abc 345 4 Tom 345 cde 345... (3 Replies)
Discussion started by: chrissycc
3 Replies

9. Shell Programming and Scripting

Need Help to add Condition in Shell Script..

Hi Team, I m very new to shell scripting , i want to add following condition in my script . Can anybody help me. There are three port in My node "$port" port_A port_B port_C I Want to add following Conditions in my script. If Node is connected to port_A and port_B script... (10 Replies)
Discussion started by: Ganesh Mankar
10 Replies

10. UNIX for Beginners Questions & Answers

If condition is not working and getting error

Hi Team, If condition is not working properly and getting below error # ./score1.sh Enter your score ('q' for quit): 102 Enter your score ('q' for quit): q ./score1.sh: line 9: q: integer expression expected Average is: 102%. Exit. Actual code # Calculate the average of given... (3 Replies)
Discussion started by: Torrid
3 Replies
pthread_cond_init(3T)													     pthread_cond_init(3T)

NAME
pthread_cond_init(), pthread_cond_destroy() - initialize or destroy a condition variable SYNOPSIS
PARAMETERS
cond Pointer to the condition variable to be initialized or destroyed. attr Pointer to the attributes object that defines the characteristics of the condition variable to be initialized. If the pointer is NULL, default attributes are used. DESCRIPTION
The function initializes the condition variable cond with the attributes attr. If attr is NULL, the default condition variable attributes are used to initialize the attributes object. See pthread_condattr_init(3T) for a list of the default condition variable attributes. After successful initialization, the condition variable may be used in condition variable operations. A condition variable should be ini- tialized only once or the resulting behavior is undefined. The function provides a way to ensure that a condition variable is only ini- tialized once. The macro can be used to initialize condition variables that are statically allocated. These condition variables will be initialized with default attributes. The function does not need to be called for statically initialized condition variables. If the process-shared attribute in the condition variable attributes object referenced by attr is defined as the condition variable must be allocated such that the processes sharing the condition variable have access to it. This may be done through the memory-mapping functions (see mmap(2)) or the shared memory functions (see shmget(2)). destroys the condition variable cond. This function may set cond to an invalid value. The destroyed condition variable can be reinitial- ized using the function If the condition variable is used after destruction in any condition variable call, the resulting behavior is unde- fined. A condition variable should be destroyed only when there are no threads currently blocked on it. Destroying a condition variable that is currently in use results in undefined behavior. RETURN VALUE
Upon successful completion, and return zero. Otherwise, an error number is returned to indicate the error (the variable is not set). ERRORS
If any of the following occur, the function returns the corresponding error number: The system does not have the available resources (other than memory) to initialize the condition variable. The specified condition variable is an already initialized condition variable. However, getting for reinitializing the condition variable cannot be expected all the time since the behavior of reinitializing the condition variable is undefined. The cond parameter points to an illegal address. The value specified by cond or attr is invalid. There is insufficient memory available in which to initialize the condition variable. If any of the following occur, the function returns the corresponding error number: An attempt to destroy cond while it is in use by another thread. cond is not a valid condition variable. WARNINGS
The space for condition variable must be allocated before calling Undefined behavior will result if the process-shared attribute of attr is and the space allocated for the condition variable is not accessible to cooperating threads. AUTHOR
and were derived from the IEEE POSIX P1003.1c standard. SEE ALSO
pthread_cond_signal(3T), pthread_cond_wait(3T). STANDARDS CONFORMANCE
Pthread Library pthread_cond_init(3T)
All times are GMT -4. The time now is 06:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy