running variable on command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting running variable on command line
# 1  
Old 09-15-2011
running variable on command line

Hi,

I have a unix script, and I have problem, where I work out the variable I need. But it will not excute the variable from the script ?

See my script below for details :
Code:
#!/bin/sh
 
ENVGRP=`hostname |cut -c1-3 |  tr '[a-z]' '[A-Z]'`
ENVINST=${ENVGRP}`hostname -i |cut -d\. -f 4`
 
echo $ENVINST
 
$ENVINST

Running the script :

Code:
[dev@dev08systemrel scripts] :$ ./ReleaseManagement.sh
++ hostname
++ cut -c1-3
++ tr '[a-z]' '[A-Z]'
+ ENVGRP=DEV
++ hostname -i
++ cut -d. -f 4
+ ENVINST=DEV6
+ echo DEV6
DEV6
+ DEV6
./ReleaseManagement.sh: line 9: : command not found
[dev@systemrel scripts] :$

Not sure what I doing wrong here, please could someone advise.
thank you

Moderator's Comments:
Mod Comment Please use code tags!
# 2  
Old 09-15-2011
what are you trying to do with that last line .. $ENVINST ..
# 3  
Old 09-15-2011
How do you usually call the DEV6 script?
# 4  
Old 09-15-2011
when I login into the environment, I just type DEV6 on the command line and this sources the environment variables.

Now I would like to excute DEV6 within a start of a script. SO if you logged into the environment first time round and you forgot to type DEV6 on the command line, the script would take care of this.
# 5  
Old 09-15-2011
You will have to set the environment in this script, not in a script called from this one.

Does your script have the expected environment (PATH, etc.) at all? If it is called from cron then the envronment is guaranteed to be radically different from your login environment.

Second: it seems that "DEV6" is starting all right, but *it* encounters an error, not the script you showed us. What the error in a script we do not know is is hard to guess, my crystal sphere is undergoing maintenance right now.

Post the script and we might find problems with it, otherwise you will have to search and debug for yourself.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Another one line command where I'd like to determine if Ubuntu or Red Hat when running command

Hello Forum, I'm making very good progress on my report thanks to the very helpful people on this forum. I've been able to successfully create my report for my Red Hat servers. But I do have a few ubuntu servers in the mix and I'd like to capture some data from them when an ssh connection is... (8 Replies)
Discussion started by: greavette
8 Replies

2. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

3. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

4. Shell Programming and Scripting

Running Two scripts in a single command line

Hi All, I have two scripts which i want to run in a single command line(or in a single script). And if both the scripts in the main script fail then i want to pass a value to a Application specific utility which will trigger some alert.The value can be anything. Somebody please help.It is... (1 Reply)
Discussion started by: shroh
1 Replies

5. Shell Programming and Scripting

running multiple command in a single line

Hi Can we run the linux command and per script in a single command $ cd /usr/local/adm/ ;ctsv scmtest_qabuild ;cspec.pl scmtest This is a combination of linux and clearcase command and last one is perl script with argument. I can see the first and 2nd coomand is executing but last... (6 Replies)
Discussion started by: anuragpgtgerman
6 Replies

6. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

7. Shell Programming and Scripting

running multiple command in same line

I have 5 hosts and each host as 3 java process .I have one machine which has ssh keys so it can login without any passwords etc to all the machines. How can I find out say jstack or some command so it goes to each machine and run the command . For example machine 1 has 3 java process and they... (2 Replies)
Discussion started by: gubbu
2 Replies

8. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

9. Shell Programming and Scripting

running if statement on command line

Hi, is it possible to run an if statement from the command line? I am doing this # service postgresql status; if ] ; then awk '{print ""$2""}' /root/file.txt > But it throws me into a different mode ie the > then I have to do a ctrl+c. I want to do it this way because I will be... (2 Replies)
Discussion started by: borderblaster
2 Replies

10. Shell Programming and Scripting

running command remotely to populate local variable

If I run this # ssh remote-server 'du -sk /usr/platform/`uname -i`/' 174 /usr/platform/SUNW,Sun-Fire-V245 I get my output just fine, However, if i try to do the same but populate a local variable within my script called for example 'result' #!/bin/ksh result=`ssh remote-server... (3 Replies)
Discussion started by: hcclnoodles
3 Replies
Login or Register to Ask a Question