Link to home
Start Free TrialLog in
Avatar of parlepoint
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...
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

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
Avatar of parlepoint
parlepoint

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.
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...
SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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..
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
Hi,

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

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"


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
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
Hi,

there is space in ls-l

change  ls-l to ls  -l
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
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


i try...but didn'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.
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 ' '
Hi,

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.
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..
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.

Hi,

correction:

.
.
.
are known to your connecting server and get replaced ...
.
.
.
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/
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
i try without quote...but still not working..
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"
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...!!!
Hi,

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

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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
I managed it....
systex error....


Succesfully done.