ksh - keep argument variables after ssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh - keep argument variables after ssh
# 1  
Old 10-21-2015
ksh - keep argument variables after ssh

i have a script that should ssh to different host/server. See below:
Code:
./script.ksh var1 var2 var3
case $ser in
   ser1)
         depo='appr1'
         set -A aprrA aprrB
         ssh ser2 "/home/dir/script.ksh $1 $2 $3"
         ssh ser3 "/home/dir/script.ksh $1 $2 $3"
         ssh ser4 "/home/dir/script.ksh $1 $2 $3"
         x=something
   ;;
   serA)
         depo='appr2'
         set -A aprrC aprrD
         ssh serB "/home/dir/script.ksh $1 $2 $3"
         ssh serC "/home/dir/script.ksh $1 $2 $3"
         ssh serD "/home/dir/script.ksh $1 $2 $3"
         x=another_thing
   ;;
esac

I was wondering if after the
Code:
ssh

command, will this
Code:
/home/dir/script.ksh $1 $2 $3

command still knows the values of variables
Code:
$1, $2, $3

.

Last edited by erin00; 10-21-2015 at 07:21 AM..
# 2  
Old 10-21-2015
Yes. $1, $2, $3 are only changed when you do set --.
# 3  
Old 10-22-2015
will the command
Code:
"/home/dir/script.ksh $1 $2 $3

still run properly in ser2? and will it still ssh to in ser3 and ser4?
# 4  
Old 10-22-2015
The positional parameters will stay intact inside the script unless actively modified by the script itself by e.g. set -- or shift
# 5  
Old 10-22-2015
Quote:
Originally Posted by erin00
i have a script that should ssh to different host/server. See below:
Code:
./script.ksh var1 var2 var3
case $ser in
   ser1)
         depo='appr1'
         set -A aprrA aprrB
         ssh ser2 "/home/dir/script.ksh $1 $2 $3"
         ssh ser3 "/home/dir/script.ksh $1 $2 $3"
         ssh ser4 "/home/dir/script.ksh $1 $2 $3"
         x=something
   ;;
   serA)
         depo='appr2'
         set -A aprrC aprrD
         ssh serB "/home/dir/script.ksh $1 $2 $3"
         ssh serC "/home/dir/script.ksh $1 $2 $3"
         ssh serD "/home/dir/script.ksh $1 $2 $3"
         x=another_thing
   ;;
esac

I was wondering if after the
Code:
ssh

command, will this
Code:
/home/dir/script.ksh $1 $2 $3

command still knows the values of variables
Code:
$1, $2, $3

.
If this isn't working, it isn't because the parameters aren't being passed to the remote machines by ssh. Is script.ksh located in /home/dir on the machines serB, serC, and serD; or is your script located in that directory on the local machine only? The pathname to the script you're running has to be valid on the machine on which you're trying to run it. And, of course, using unquoted $1, $2, and $3 won't work if any of those variables contain any IFS characters (usually <space>, <tab>, and <newline>) and might not work if they expand to strings that contain characters that are special in pathname pattern matching (such as ?, *, and [).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to have local shell variables in a ksh script seen on remove server in SSH block?

I have googled this and found many solutions, but none of them are working for me. I am in a korn shell, most others reference bsh, maybe that is the issue? Anyway, all I am trying to do is use a variable I have declared in my main script in a remote shell I am running through ssh. So I have a... (8 Replies)
Discussion started by: DJR
8 Replies

2. Shell Programming and Scripting

Ssh fails due to argument position.

I have a constraint to follow organization policy. So i do not have much liberty. ssh -i /opt/nonprod user1@hostone -t bash works while ssh -i /opt/nonprod -t bash user1@hostone fails How can I get this to work when I am enforced to put -t bash before the user@hostname ? Will share debug... (3 Replies)
Discussion started by: mohtashims
3 Replies

3. Shell Programming and Scripting

ksh - default value for getopts option's argument

Hello everyone, I need help in understanding the default value for getopts option's argument in ksh. I've written a short test script: #!/bin/ksh usage(){ printf "Usage: -v and -m are mandatory\n\n" } while getopts ":v#m:" opt; do case $opt in v) version="$OPTARG";; ... (1 Reply)
Discussion started by: da1
1 Replies

4. Shell Programming and Scripting

Help cannot concatenate Ksh variables ?

Cannot combine these two strings into one line, either as a 3rd variable or echo or printing ? Frustrating. for i in `cat /scripts/pathList.dat` do OldRepo= grep Oldhostname ${i}/.svn/entries | tail -1 NewRepo= grep Oldhostname ${i}/.svn/entries | tail -1 | sed '/Oldhostname/... (41 Replies)
Discussion started by: pcpinkerton
41 Replies

5. Shell Programming and Scripting

Read env variables from argument file

Hi, I have a generic shell script (runBatchJob.sh) to read files (batchJob) with commands in them and execute the commands by reading the batchJob file as below ./runBatchJob.sh batchJob batchJob file $BATCHDIR/execute_procedure.sh $DATADIR/collectData.sh $OTHER_ENV_VAR/doSomething.sh ... (10 Replies)
Discussion started by: bOngY
10 Replies

6. Shell Programming and Scripting

How to preserve NL in Ksh variables?

I'm trying to set a variable to the output of a command. This is what the comand output to the display looks like: />hciconndump -v TOsiu Dump of connection(s): TOsiu ---------------------------------------------------------------------- Process: A60Tsiu Connection: TOsiu... (2 Replies)
Discussion started by: troym72
2 Replies

7. Shell Programming and Scripting

Handling values with space while passing commandline argument from wrapper script in KSH

Hi there, I have a wapper script which passes the argument from command prompt to inner script.. It works fine as long as the argument containing single word. But when value contains multiple word with space, not working as expected. I tried my best, couldn't find the reason. Gurus, pls.... (2 Replies)
Discussion started by: kans
2 Replies

8. UNIX for Dummies Questions & Answers

Argument list too long - SSH

Hi I executed the code for file in `ls pdb*.ent` do new_name=`echo $file | sed 's/^pdb//;s/.ent/.txt/'` mv $file $new_name done Its giving error at ' ls pdb*.ent' argument list too long i have around 150000 entries please help Thank you (6 Replies)
Discussion started by: empyrean
6 Replies

9. Shell Programming and Scripting

Cannot read variables after ssh with rc file (KSH)

Greetings all, I'm currently making use of the $HOME/.ssh/rc file to launch an automated shell script immediately after the user has been verified through ssh. The current problem that I'm facing now is that I am unable to use the "read" command anymore... seems like the "read" statements are... (0 Replies)
Discussion started by: rockysfr
0 Replies

10. Shell Programming and Scripting

variables in ksh

I'm new to unix scripting. How would I go about pulling the first 3 characters from a variable in ksh and storing in another variable? Thanks. (9 Replies)
Discussion started by: steve6368
9 Replies
Login or Register to Ask a Question