parlepoint
asked on
for loop don't pick file after ssh
hi guys,
below script is working without ssh but won't work if i use ssh.
do any body know what's reason.
ssh -v build2@server20
hostname
pwd
cd /home/build2/projectl
for pvtfile in *.txt
do
print "deciphering '$pvtfile'"
done
output:
deciphering ''
deciphering ''
not pick value from pvtfile...
below script is working without ssh but won't work if i use ssh.
do any body know what's reason.
ssh -v build2@server20
hostname
pwd
cd /home/build2/projectl
for pvtfile in *.txt
do
print "deciphering '$pvtfile'"
done
output:
deciphering ''
deciphering ''
not pick value from pvtfile...
ASKER
run on sun os in unix
omarfarid's solution will work, but the usual way is to invoke the script on the remote server.
ASKER
some how everything is working but not picking up *.txt files
also one more thing i want to pass private variable to remote app server ..
like $x=123 and same thing should work for remote application...
also one more thing i want to pass private variable to remote app server ..
like $x=123 and same thing should work for remote application...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your reply...
it works...but only problem is variable...it's not taking...
can you tell me how variable works in remote application...after ssh..
it works...but only problem is variable...it's not taking...
can you tell me how variable works in remote application...after ssh..
You'll need to show how you're trying to use it.
Simplistically
$ x=123
$ ssh remote-server "echo x is $x"
x is 123
Simplistically
$ x=123
$ ssh remote-server "echo x is $x"
x is 123
Hi,
| agree with Tintin recommendation to copy the script to remote server, then execute it.
| agree with Tintin recommendation to copy the script to remote server, then execute it.
ASKER
i want to use like this and want to use abc value in hello.ksh script.
give me suggestion.
abc=server1
ssh -v build2@server20 -C "echo var is $abc" && "/home/cmbuild2/abc/hello. ksh"
give me suggestion.
abc=server1
ssh -v build2@server20 -C "echo var is $abc" && "/home/cmbuild2/abc/hello.
Hi,
I do not see any problem with your example.
I tried the following:
a=a.txt
ssh omar@remoteserver -C "echo $a" && "ls"
works fine and echo a.txt and list remote dir
ssh omar@remoteserver "echo $a ; ls-l $a"
works fine and echo a.txt and do long listing of remote file a.txt
But, it return error with
ssh omar@remoteserver -C "echo $a" && "ls -l $a"
bash: ls -l a.txt: command not found
I do not see any problem with your example.
I tried the following:
a=a.txt
ssh omar@remoteserver -C "echo $a" && "ls"
works fine and echo a.txt and list remote dir
ssh omar@remoteserver "echo $a ; ls-l $a"
works fine and echo a.txt and do long listing of remote file a.txt
But, it return error with
ssh omar@remoteserver -C "echo $a" && "ls -l $a"
bash: ls -l a.txt: command not found
ASKER
thanks for your reply but problem is $a value is not work ...i tried with your example..but didn't work..
this is output i am getting.
also variable value is going to use in script..
$>ls -l $a
total 4
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 a.doc
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 b.doc
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 bb.txt
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 c.doc
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 cc.txt
-rwxrwxrwx 1 cmbuild2 cmbuild 117 Oct 17 08:50 hello.ksh
-rwxrwxrwx 1 cmbuild2 cmbuild 141 Oct 17 08:51 test.ksh
BUILD:cmbuild2@pitt30:/hom e/cmbuild2
$>ssh build2@server20 "echo $a ; ls-l $a"
cmbuild2@pittwls20's password:
/home/cmbuild2
ksh: ls-l: not found.
BUILD:cmbuild2@pitt30:/hom e/cmbuild2
this is output i am getting.
also variable value is going to use in script..
$>ls -l $a
total 4
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 a.doc
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 b.doc
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 bb.txt
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 c.doc
-rwxrwsrwx 1 cmbuild2 cmbuild 0 Oct 16 09:09 cc.txt
-rwxrwxrwx 1 cmbuild2 cmbuild 117 Oct 17 08:50 hello.ksh
-rwxrwxrwx 1 cmbuild2 cmbuild 141 Oct 17 08:51 test.ksh
BUILD:cmbuild2@pitt30:/hom
$>ssh build2@server20 "echo $a ; ls-l $a"
cmbuild2@pittwls20's password:
/home/cmbuild2
ksh: ls-l: not found.
BUILD:cmbuild2@pitt30:/hom
Hi,
there is space in ls-l
change ls-l to ls -l
there is space in ls-l
change ls-l to ls -l
ASKER
yes..ls -l is working..but if variable calling in different script it want work
$>ssh build2@server20 "echo $a ; /home/build2//hello.ksh"
build2@server20's password:
THIS IS HELLO.KSH SCRIPT
i am remote '$a'
+ print i am remote ''
BUILD:cmbuild2@pitt30:/hom e/build2
$>ssh build2@server20 "echo $a ; /home/build2//hello.ksh"
build2@server20's password:
THIS IS HELLO.KSH SCRIPT
i am remote '$a'
+ print i am remote ''
BUILD:cmbuild2@pitt30:/hom
Hi,
try
a=a.txt
eval ssh user@remoteserver -C "echo a=$a ; export a ; a.sh"
on the remote server, a.sh is executable and does the following
ls -l $a
try
a=a.txt
eval ssh user@remoteserver -C "echo a=$a ; export a ; a.sh"
on the remote server, a.sh is executable and does the following
ls -l $a
ASKER
i try...but didn't work..
if you trying then first unset variable from remote machine...
then check....won't work ..
if you trying then first unset variable from remote machine...
then check....won't work ..
parlepoint.
How about you try to explain what you are trying to achieve. This all seems pretty messy the way you want to do it.
How about you try to explain what you are trying to achieve. This all seems pretty messy the way you want to do it.
ASKER
I was trying this way:
a=qas
eval ssh user@remoteserver -C "echo a=$a ; export $a ; a.sh"
in a.sh
#! /usr/bin/ksh
print " this is '$a'"
output
this is ' '
a=qas
eval ssh user@remoteserver -C "echo a=$a ; export $a ; a.sh"
in a.sh
#! /usr/bin/ksh
print " this is '$a'"
output
this is ' '
Hi,
I think
print " this is '$a'"
should be
print " this is $a"
I think
print " this is '$a'"
should be
print " this is $a"
export $a
should be
export a
However, I still go back to my previous comment that this is all very messy.
Please tell us what problem you are trying to achieve. I'm sure there will be a much better way of doing it.
should be
export a
However, I still go back to my previous comment that this is all very messy.
Please tell us what problem you are trying to achieve. I'm sure there will be a much better way of doing it.
ASKER
Okey..sorry for late reply
This is script which i want it..
i have to create hello2.ksh only because want to pick up= for PVT_FILE in *ssm_*.ksh after ssh..
eval ssh $PVT_SUNAME@$PVT_CONNECTHO ST "echo a=$PVT_LOC_CONFIG ; echo b=$SSM_DECIPHERCODE ; export a ; export b ; /home/mms/hello2.ksh"
================In hello2.ksh==========
cd "$PVT_LOC_CONFIG/javaserve r"
for PVT_FILE in *ssm_*.ksh
do
echo $PVT_FILE
chmod 600 "$PVT_FILE" ; PVT_RETURN0="$?"
done
========================== ========== ====
Still don't get it then let m know i give bit more description..
This is script which i want it..
i have to create hello2.ksh only because want to pick up= for PVT_FILE in *ssm_*.ksh after ssh..
eval ssh $PVT_SUNAME@$PVT_CONNECTHO
================In hello2.ksh==========
cd "$PVT_LOC_CONFIG/javaserve
for PVT_FILE in *ssm_*.ksh
do
echo $PVT_FILE
chmod 600 "$PVT_FILE" ; PVT_RETURN0="$?"
done
==========================
Still don't get it then let m know i give bit more description..
Hi,
Notes:
eval ssh $PVT_SUNAME@$PVT_CONNECTHO ST "echo a=$PVT_LOC_CONFIG ; echo b=$SSM_DECIPHERCODE ; export a ; export b ; /home/mms/hello2.ksh"
- variables PVT_SUNAME PVT_CONNECTHOST PVT_LOC_CONFIG SSM_DECIPHERCODE
are known to your connecting and get replaced by their actual values before executing the ssh command
- variables a & b get set on the remote server and take their values from the evaluated variables. They are not used on the remote node by the script hello2.ksh
- in hello2.ksh script which will run on the remote node, variable PVT_LOC_CONFIG is used (which the remote server knows nothing about it) and instead variable a can be used.
So, change
cd "$PVT_LOC_CONFIG/javaserve r"
to
cd "$a/javaserver"
and see if you get what you want.
Notes:
eval ssh $PVT_SUNAME@$PVT_CONNECTHO
- variables PVT_SUNAME PVT_CONNECTHOST PVT_LOC_CONFIG SSM_DECIPHERCODE
are known to your connecting and get replaced by their actual values before executing the ssh command
- variables a & b get set on the remote server and take their values from the evaluated variables. They are not used on the remote node by the script hello2.ksh
- in hello2.ksh script which will run on the remote node, variable PVT_LOC_CONFIG is used (which the remote server knows nothing about it) and instead variable a can be used.
So, change
cd "$PVT_LOC_CONFIG/javaserve
to
cd "$a/javaserver"
and see if you get what you want.
Hi,
correction:
.
.
.
are known to your connecting server and get replaced ...
.
.
.
correction:
.
.
.
are known to your connecting server and get replaced ...
.
.
.
ASKER
i was given $a instead of..$PVT_LOC_CONFIG ---- but still didn't work..
i make sample script.
=================in hello1.ksh================ =
a=hello
b=chear
c=tiger
d=elephant
echo $a $b $c $d
eval ssh cmbuild2@pittwls20 -C " echo aa=$a ; echo dd=$c ; export aa ; export dd ; a.ksh"
===============in a.ksh===================== ===
for pvtfile in 1 2 3
do
print "=============== '$aa'====== '$dd'========== "
done
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
OUTPUT: with debug mode ON
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------
$>hello1.ksh
+ a=hello
+ b=chear
+ c=tiger
+ d=elephant
+ echo hello chear tiger elephant
hello chear tiger elephant
+ eval ssh cmbuild2@pittwls20 -C echo aa=hello ; echo dd=tiger ; export aa ; export dd ; a.ksh
+ ssh cmbuild2@pittwls20 -C echo aa=hello
cmbuild2@pittwls20's password:
aa=hello
+ echo dd=tiger
dd=tiger
+ export aa
+ export dd
+ a.ksh
=============== ''====== ''==========
=============== ''====== ''==========
=============== ''====== ''==========
BUILD:cmbuild2@pitt30:/hom e/cmbuild2 /
i make sample script.
=================in hello1.ksh================
a=hello
b=chear
c=tiger
d=elephant
echo $a $b $c $d
eval ssh cmbuild2@pittwls20 -C " echo aa=$a ; echo dd=$c ; export aa ; export dd ; a.ksh"
===============in a.ksh=====================
for pvtfile in 1 2 3
do
print "=============== '$aa'====== '$dd'========== "
done
--------------------------
OUTPUT: with debug mode ON
--------------------------
$>hello1.ksh
+ a=hello
+ b=chear
+ c=tiger
+ d=elephant
+ echo hello chear tiger elephant
hello chear tiger elephant
+ eval ssh cmbuild2@pittwls20 -C echo aa=hello ; echo dd=tiger ; export aa ; export dd ; a.ksh
+ ssh cmbuild2@pittwls20 -C echo aa=hello
cmbuild2@pittwls20's password:
aa=hello
+ echo dd=tiger
dd=tiger
+ export aa
+ export dd
+ a.ksh
=============== ''====== ''==========
=============== ''====== ''==========
=============== ''====== ''==========
BUILD:cmbuild2@pitt30:/hom
Hi,
Why do you need single quot around $aa ?
I have done the following and as you can see, it works!!
[omar@p4 omar]$ a=omar
[omar@p4 omar]$ eval ssh omar@0 "a=$a ; export a ; ./a.sh"
omar@0's password:
omar
omar.yyy
[omar@p4 omar]$ cat a.sh
echo $a
echo $a.yyy
If you still not able to get it done, we might think of some alternative way
Why do you need single quot around $aa ?
I have done the following and as you can see, it works!!
[omar@p4 omar]$ a=omar
[omar@p4 omar]$ eval ssh omar@0 "a=$a ; export a ; ./a.sh"
omar@0's password:
omar
omar.yyy
[omar@p4 omar]$ cat a.sh
echo $a
echo $a.yyy
If you still not able to get it done, we might think of some alternative way
ASKER
i try without quote...but still not working..
is there problem with AIX unix machine..or ksh script...
still not taking variable...
is there problem with AIX unix machine..or ksh script...
still not taking variable...
Hi,
try:
eval ssh cmbuild2@pittwls20 -C "echo aa=$a > /tmp/myfile ; echo dd=$c >> /tmp/myfile ; cat a.ksh >> /tmp/myfile ; mv /tmp/myfile a.ksh ; a.ksh"
try:
eval ssh cmbuild2@pittwls20 -C "echo aa=$a > /tmp/myfile ; echo dd=$c >> /tmp/myfile ; cat a.ksh >> /tmp/myfile ; mv /tmp/myfile a.ksh ; a.ksh"
ASKER
it's not overwriting stuff...if i change a & c value..keep giving me old value..because old value still existing in script...
rest is fine...!!!
rest is fine...!!!
Hi,
I don't understand. You could resolve the issue or not?
I don't understand. You could resolve the issue or not?
ASKER
keep adding variable value in a.ksh script...& existing value are still there....
that' problem..varibal still picking up old values....
==========a.ksh=========== ========== ======
aa=me
dd=you
aa=disco
dd=done
#! /usr/bin/ksh
cd /home/cmbuild2
echo $aa
echo $dd
for pvtfile in *.txt
do
print "=============== $aa====== $dd========== "
done
for pvtfile in *.txt
do
print "my name is === $aa====== $dd========== "
done
that' problem..varibal still picking up old values....
==========a.ksh===========
aa=me
dd=you
aa=disco
dd=done
#! /usr/bin/ksh
cd /home/cmbuild2
echo $aa
echo $dd
for pvtfile in *.txt
do
print "=============== $aa====== $dd========== "
done
for pvtfile in *.txt
do
print "my name is === $aa====== $dd========== "
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks man...it works..
but i have some problem in same script.....
==============main script===========
ssh ssmqas@pitt34 <<EOT
cd /qual/ssm/stat/current/con fig
test1.ksh
EOT
================test1.ksh= ========== =
#!/usr/bin/ksh
cd /qual/ssm/stat/1.0/config/ javaserver /com/fedex /common/se curity_fra mework
/qual/ssm/stat/current/con fig/decyph erenv.pl -l:QAS card.props >card.props.decyphered
---------------instead of previous line i use for loop then getting error(see the output)-------------------
for PVT_FILE in *.props
do
$PVT_LOC_CONFIG/decypheren v.pl "-l:$SSM_DECIPHERCODE" "$PVT_FILE" >"$PVT_FILE.decyphered" ; PVT_RETURN1="$?"
done
========================== ========== =
decyper.pl is only select file from txt file...if QAS than he selct qas file and project name...
output:
card.props
project=card
DECYPHER:QAS:encrypted_fil e=card_qas _encrypted _file
DECYPHER:QAS:unencrypted_f ile=card_q as_unencry pted_file
DECYPHER:PRD:encrypted_fil e=card_prd _encrypted _file
DECYPHER:PRD:unencrypted_f ile=card_p rd_unencry pted_file
DECYPHER:DEV:encrypted_fil e=card_dev _encrypted _file
DECYPHER:DEV:unencrypted_f ile=card_d ev_unencry pted_file
card.props.decypherd
project=card
DECYPHER:QAS:encrypted_fil e=card_qas _encrypted _file
DECYPHER:QAS:unencrypted_f ile=card_q as_unencry pted_file
AFTER FOR LOOP GIVING.-----------------
project=card
what will be problem....i couldn't figure out....can you know...
but i have some problem in same script.....
==============main script===========
ssh ssmqas@pitt34 <<EOT
cd /qual/ssm/stat/current/con
test1.ksh
EOT
================test1.ksh=
#!/usr/bin/ksh
cd /qual/ssm/stat/1.0/config/
/qual/ssm/stat/current/con
---------------instead of previous line i use for loop then getting error(see the output)-------------------
for PVT_FILE in *.props
do
$PVT_LOC_CONFIG/decypheren
done
==========================
decyper.pl is only select file from txt file...if QAS than he selct qas file and project name...
output:
card.props
project=card
DECYPHER:QAS:encrypted_fil
DECYPHER:QAS:unencrypted_f
DECYPHER:PRD:encrypted_fil
DECYPHER:PRD:unencrypted_f
DECYPHER:DEV:encrypted_fil
DECYPHER:DEV:unencrypted_f
card.props.decypherd
project=card
DECYPHER:QAS:encrypted_fil
DECYPHER:QAS:unencrypted_f
AFTER FOR LOOP GIVING.-----------------
project=card
what will be problem....i couldn't figure out....can you know...
ASKER
I managed it....
systex error....
Succesfully done.
systex error....
Succesfully done.
Do you mean that you want to run the subsequent commands on the remote node?
Is this a shell script to run on unix / linux?
try:
ssh -v build2@server20 << END
hostname
pwd
cd /home/build2/projectl
for pvtfile in *.txt
do
print "deciphering '$pvtfile'"
done
END