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...
parlepointAsked:
Who is Participating?
 
omarfaridConnect With a Mentor Commented:
Hi,

I got you.

Try

eval ssh cmbuild2@pittwls20 -C "echo aa=$a > /tmp/myfile ; echo dd=$c >> /tmp/myfile ; cat a.ksh >> /tmp/myfile ; mv a.ksh a.ksh.orig ; mv /tmp/myfile a.ksh ; a.ksh ; mv a.ksh.orig a.ksh"

Here I move a.ksh to a.ksh.orig then when I finish executing the new a.ksh, I move back a.ksh.orig to a.ksh

0
 
omarfaridCommented:
Hi,

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
0
 
parlepointAuthor Commented:
run on sun os in unix

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
TintinCommented:
omarfarid's solution will work, but the usual way is to invoke the script on the remote server.
0
 
parlepointAuthor Commented:
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...
0
 
TintinConnect With a Mentor Commented:
You'd be better of scp'ing the script to the server and then invoking it, eg:

#!/bin/sh

cat >/tmp/$$ <EOF
hostname
pwd
cd /home/build2/projectl
for pvtfile in *.txt
do
print "deciphering '$pvtfile'"
done
EOF

scp /tmp/$$ build2@server20:script
ssh build2@server20 "sh script"
0
 
parlepointAuthor Commented:
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..
0
 
TintinCommented:
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
0
 
omarfaridCommented:
Hi,

| agree with Tintin recommendation to copy the script to remote server, then execute it.

0
 
parlepointAuthor Commented:
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"


0
 
omarfaridCommented:
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
0
 
parlepointAuthor Commented:
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:/home/cmbuild2
$>ssh build2@server20  "echo $a ; ls-l $a"
cmbuild2@pittwls20's password:
/home/cmbuild2
ksh: ls-l:  not found.
BUILD:cmbuild2@pitt30:/home/cmbuild2
0
 
omarfaridCommented:
Hi,

there is space in ls-l

change  ls-l to ls  -l
0
 
parlepointAuthor Commented:
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:/home/build2
0
 
omarfaridCommented:
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


0
 
parlepointAuthor Commented:
i try...but didn't work..

if you trying then first unset variable from remote machine...
then check....won't work ..

0
 
TintinCommented:
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.
0
 
parlepointAuthor Commented:
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 ' '
0
 
omarfaridCommented:
Hi,

I think

print " this is '$a'"

should be

print " this is $a"
0
 
TintinCommented:
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.
0
 
parlepointAuthor Commented:
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_CONNECTHOST "echo a=$PVT_LOC_CONFIG ; echo b=$SSM_DECIPHERCODE ; export a ; export b ; /home/mms/hello2.ksh"

================In hello2.ksh==========

cd "$PVT_LOC_CONFIG/javaserver"
 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..
0
 
omarfaridCommented:
Hi,

Notes:

eval ssh $PVT_SUNAME@$PVT_CONNECTHOST "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/javaserver"

to

cd "$a/javaserver"

and see if you get what you want.

0
 
omarfaridCommented:
Hi,

correction:

.
.
.
are known to your connecting server and get replaced ...
.
.
.
0
 
parlepointAuthor Commented:
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:/home/cmbuild2/
0
 
omarfaridCommented:
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
0
 
parlepointAuthor Commented:
i try without quote...but still not working..
is there problem with AIX unix machine..or ksh script...

still not taking variable...
0
 
omarfaridCommented:
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"
0
 
parlepointAuthor Commented:
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...!!!
0
 
omarfaridCommented:
Hi,

I don't understand. You could resolve the issue or not?

0
 
parlepointAuthor Commented:
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
0
 
parlepointAuthor Commented:
Thanks man...it works..
but i have some problem in same script.....

==============main script===========
ssh ssmqas@pitt34 <<EOT
cd /qual/ssm/stat/current/config
test1.ksh
EOT
================test1.ksh============
#!/usr/bin/ksh
cd /qual/ssm/stat/1.0/config/javaserver/com/fedex/common/security_framework

/qual/ssm/stat/current/config/decypherenv.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/decypherenv.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_file=card_qas_encrypted_file
DECYPHER:QAS:unencrypted_file=card_qas_unencrypted_file
DECYPHER:PRD:encrypted_file=card_prd_encrypted_file
DECYPHER:PRD:unencrypted_file=card_prd_unencrypted_file
DECYPHER:DEV:encrypted_file=card_dev_encrypted_file
DECYPHER:DEV:unencrypted_file=card_dev_unencrypted_file

card.props.decypherd
project=card
DECYPHER:QAS:encrypted_file=card_qas_encrypted_file
DECYPHER:QAS:unencrypted_file=card_qas_unencrypted_file

AFTER FOR LOOP GIVING.-----------------
project=card

what will be problem....i couldn't figure out....can you know...
0
 
parlepointAuthor Commented:
I managed it....
systex error....


Succesfully done.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.