Pass hotname from command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pass hotname from command
# 1  
Old 09-05-2006
Pass hotname from command

I have a problem, which is,
I have servers as
$hostname : Serverxxd
$hostname : Serverxxs
$hostname : Serverxxl
$hostname : Serverxxp
d=dev, s=sit, l=stg, p=prd
The packages will be in all the boxes and my script contains $ENV which I should be
getting from 'hostname'
I am not able to determine how I could look for the last letter in hostname and use it in script to call the ENV variable.

Please help/advise
Thanks
Chiru
# 2  
Old 09-05-2006
One way --
Code:
lastletter=$(expr substr $hostname $(expr length $hostname) 1)

# 3  
Old 09-05-2006
Thankyou..it worked !!!
# 4  
Old 09-05-2006
question

Glenn,

I got a small question. How do you assign variable value with : here. What's the significance here.

Quote:
$hostname : Serverxxd
$hostname : Serverxxs
$hostname : Serverxxl
$hostname : Serverxxp
could you ever assign a varialbe value with :

Please let me know
# 5  
Old 09-05-2006
I think the original poster was just defining in non-programming terms what the $hostname variable could be. I don't believe the ":" has any significance beyond that.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass root password with su and command?

Hello, I have list of around 400 devices. I need to restart a service /etc/init.d/psap23.sh in all of them, but it should restart by root only. Those have some other kind of light Linux. There is no sudo package in that and we can't/shouldn't install. Direct root login is not allowed. I login... (5 Replies)
Discussion started by: solaris_1977
5 Replies

2. Shell Programming and Scripting

Pass ls command output to diff

Hi , Can some one help me how to pass ls command output to diff command ex : - ls *.xml will return files which have time stamps abc-<time-stamp>.xml xyz-<time-stamp>.xml diff abc-<time-stamp>.xml xyz-<time-stamp>.xml >> newfile.txt we need to... (9 Replies)
Discussion started by: techie_09
9 Replies

3. Shell Programming and Scripting

Pass Arguments to Command from Shell Script

Hi all, I am working on a project, in which I have to connect to Bluetooth low energy device. I am able to connect and do data transfer from command line. But I want to do from script Here is my script #!/bin/bash #sudo hcitool -i hci0 lescan sleep 1 sudo hcitool -i hci0 lecc --random... (8 Replies)
Discussion started by: nithin@embdes
8 Replies

4. Shell Programming and Scripting

Cannot pass rsh and awk command into a variable

Hello, I'm having some issues getting a home dir from a remote server passed to a variable. Here is what I have so far: rsh server "(ls -ld /home*/user | awk '{print \$9}')" /home3/userThat works fine and brings back what I need. But when I try to add it to a variable it goes all... (3 Replies)
Discussion started by: elcounto
3 Replies

5. Shell Programming and Scripting

Pass Parameters to awk command

I need to pass values at runtime for the below awk command where l is the length and partial.txt is the file name. awk -v l=285 '{s="%-"l"s\n";printf(s,$0);}' partial.txt > temp1.txt; (5 Replies)
Discussion started by: Amrutha24
5 Replies

6. Shell Programming and Scripting

Need to pass value in sed command

Hi, I have a file a.xml containing the below <customerId>000</customerId> and a variable CUSTOMER_ID which is set to '333' Now I want to replace <customerId>000</customerId> with <customerId>333</customerId> by the below sed command and save the output in a file b.xml: sed... (3 Replies)
Discussion started by: RomitaaChawla@1
3 Replies

7. Shell Programming and Scripting

How to pass value to next command

I want to send value obtained from one command(left of |) to another command that is on right of the first one (right of |) for the following two commands: raw=`ls <directory> | grep <files_name part>` raw=${raw:0:4} (4 Replies)
Discussion started by: ezee
4 Replies

8. UNIX for Dummies Questions & Answers

How to pass file text into find command

Hi all, I have a large text file and also a smaller list of program names. I want to find out how many of those programs exist in the large text file. Can someone help me with the command/script please. The program list is along the lines of tranwe2 tranwe3 tranye5 etc so basically I... (5 Replies)
Discussion started by: Grueben
5 Replies

9. UNIX for Dummies Questions & Answers

How to pass variables in Expect command?

Hi All, I need to frame a unix script to logon to a unix box. The credentials needs to be obtained from a property file on the same location. I am trying to use 'expect' and 'spawn' command to meet this req. When I am passing values, these commands are working fine. but when I am trying to... (3 Replies)
Discussion started by: mailkarthik
3 Replies

10. Shell Programming and Scripting

Pass command as a function parameter

Hi guys, can someome help with this question, I have defined a function that takes a command as a parameter, but when the command is executed from the function it will throw errors because what I believe is a special character escaping issue. I tried using the backslash to escape the pipe | and >... (2 Replies)
Discussion started by: marouanix
2 Replies
Login or Register to Ask a Question