Variable is not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable is not working
# 8  
Old 01-16-2014
Quote:
Originally Posted by Scott
It would seem a bit pointless to chop up the hostname and use a variable containing the same hostname. I'd expect the variables AA and BB to contain a different name, therefore \$$(hostname ...) would be more apt if using eval. It's probably also possible to avoid hostname and cut if the HOSTNAME variable is set.
Code:
${HOSTNAME:0:2}

@Scott
Variable hostname
each server hostname has different network
as server hostname is AA1server.example.com
and Client hostname is AA1client.example.com
each and every time I do pinging test between client and server manually. we have 15 different network.
# 9  
Old 01-16-2014
When I responded I made a lot of assumptions:
  1. The current machine is named something like AAclient1 or BBclient2.
  2. The server for this client is AA1xx.example.com if the client's hostname starts with AA.
  3. The server for this client is BB1xx.example.com if the client's hostname starts with BB.
  4. The point of this exercise is to ping this client's server.
But, of course I had a typo in my response in message $6 in this thread (that has now been corrected) so it didn't work at all. If any of my assumptions were wrong, it might help to have a better explanation of what you're trying to do than just showing us code that isn't working and having us guess at what you're trying to do.
# 10  
Old 01-16-2014
Quote:
Originally Posted by Don Cragun
When I responded I made a lot of assumptions:
  1. The current machine is named something like AAclient1 or BBclient2.
  2. The server for this client is AA1xx.example.com if the client's hostname starts with AA.
  3. The server for this client is BB1xx.example.com if the client's hostname starts with BB.
  4. The point of this exercise is to ping this client's server.
But, of course I had a typo in my response in message $6 in this thread (that has now been corrected) so it didn't work at all. If any of my assumptions were wrong, it might help to have a better explanation of what you're trying to do than just showing us code that isn't working and having us guess at what you're trying to do.
@Don
Here I am trying generate connectivity reports from client to server,
when I run this script it should ping with correct server according to the client hostname. eg: AA has one of the group of servers and client.
AAClient will not ping with BB1XX server
this i want to use in multiple clients under the groups of servers.
# 11  
Old 01-16-2014
Quote:
Originally Posted by nith_anandan
@Don
Here I am trying generate connectivity reports from client to server,
when I run this script it should ping with correct server according to the client hostname. eg: AA has one of the group of servers and client.
AAClient will not ping with BB1XX server
this i want to use in multiple clients under the groups of servers.
OK. Good. In that case the suggestion I gave in message #6 in this thread should work as a template that can be easily expanded to handle the 15 servers on your network.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep with variable not working

Hello, I am using below code : export ORAR=orp712z.int.thomsonreuters.com #echo $ORAR; if echo $ORAR|grep -i "_" then ORACLE_SID1= echo $ORAR|cut -f2 -d "_" echo $ORACLE_SID1 ORACLE_SID=fgrep "$ORACLE_SID1" /etc/oratab|cut -f1 -d ":" #echo $ORACLE_SID else ORACLE_SID1= echo $ORAR|cut... (1 Reply)
Discussion started by: admin_db
1 Replies

2. Shell Programming and Scripting

Variable not working in grep from script

Hi, If I hard code a value in the grep it works fine from script, when I use variable it doesn't work. On a seperate note, some lines (during testing) works fine from command line but not from scirpt. #!/bin/bash # Will fetch the (oldest - as ls will sort by name by default)Date in the... (7 Replies)
Discussion started by: krish.m
7 Replies

3. AIX

Shell variable is not working

One of my shell script, I'm using shell variable to substitute parameter value to a oracle related command "tnsping". without substitution same value is working fine. see below example. Below is the result is expected with command: > tnsping "(ADDRESS = (PROTOCOL = TCP)(HOST = uedcb031)(PORT... (4 Replies)
Discussion started by: sendtoshailesh
4 Replies

4. Shell Programming and Scripting

export variable not working after su

I have a requirement to change user inside a shell script and execute group of commands. I have done it many times earlier but never came across the issue with exporting variables. Strangely if a var is exported afetr su, it is not working where as if it is does outside su, it works. Another issue... (8 Replies)
Discussion started by: sasiharitha
8 Replies

5. Shell Programming and Scripting

export of a variable isn't working

Hi I want export input data ... echo "month: " read m export m=$m also export m is not working ? the month-variable should be exportet for the use in other scripts, but it is not working like this. What i'm doing wrong? Thanks in advance! IMPe (10 Replies)
Discussion started by: IMPe
10 Replies

6. Shell Programming and Scripting

A simple variable subst is not working

Hi what i want: listing files in a special range ls -lrt 20120601{05..06}* ... -rw-rw-r-- 1 imp imp 279 1. Jun 07:51 201206010550 -rw-rw-r-- 1 imp imp 279 1. Jun 07:01 201206010600 -rw-rw-r-- 1 imp imp 279 1. Jun 07:11 201206010610 -rw-rw-r-- 1 imp imp 279 1. Jun 07:21... (1 Reply)
Discussion started by: IMPe
1 Replies

7. UNIX for Dummies Questions & Answers

grep'ing a variable - why not working

Hi all, Am writing a ksh script where I am looking for processes that has gone defunct and all of which has the same PPID PID is the variable that I need to match as this is the process ID of the processes that has gone defunct Am just curious how come the following DOES NOT work? ps... (6 Replies)
Discussion started by: newbie_01
6 Replies

8. Shell Programming and Scripting

Variable not working correctly.

Hi, I have a script where I am trying to set a local variable using the following, MYVAR="$NAME"_"$NAME2".txt where say, NAME = one NAME2 = two so I want the output one_two.txt but what I am getting is, two.txt basically the $NAME2 is overwriting, what am I doing wrong? ... (3 Replies)
Discussion started by: walsh_j
3 Replies

9. Shell Programming and Scripting

Basic variable expansion not working...

#!/usr/bin/bash if then echo "Not valid arguments entered. Just username should be entered." else USER_NAME=$1 FILE_NAME=$USER_NAME.info UNN=STUDIN\\\\$1 echo $UNN last STUDIN\\\\$1 last UNN If I type `last STUDIN\\eip060` it works but if I try to expand it with variable it is... (5 Replies)
Discussion started by: Zammy_bg
5 Replies

10. Shell Programming and Scripting

assign value to variable is not working

Hi :) The next script campares two files File1-Line1 vs File2-Line1, File1-Line1 vs File2-Line2... only if line contains "AS-", if LineX is not in File2 writes in aux, but "valor" is allways=1 never changes! :confused: What is wrong? valor changes to 0 before break, after brake is again 1 ... (3 Replies)
Discussion started by: agustincm
3 Replies
Login or Register to Ask a Question