VMware Cloud Community
zdingelit
Contributor
Contributor

copied ksh script from resource element to a Linux VM is truncated

dear community,

 

 

I am trying to copy a ksh script file from a resource element to a linux VM

The file is copied successfully but the resource element file already contains "EOF" inside and the file is truncated at the fisrt EOF.

Here is the scriptable task I used :

 

fileName = resourceScript.name;
scriptContent = resourceScript.getContentAsMimeAttachment().content;

script = 'touch'+' '+vmRemoteFolder+fileName+' '+'|'+'cat'+' '+ "<<"+"\\"+'EOF'+' '+ '>'+
          ' '+vmRemoteFolder+fileName+ ' '+scriptContent+'EOF';

 

 

copied script :

 

#!/bin/bash
#---------------------------------------------------------------------------
#  create ssh keys
#---------------------------------------------------------------------------
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "ssh-rsa MYKEY-MYKEY-MYKEY business@test" > /root/.ssh/id_rsa_test.pub
chmod 600 /root/.ssh/id_rsa_test.pub
#
cat <<EOF >  /root/.ssh/id_rsa_test
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAsexA0IL1aRnPl0gaUk3vHAD8prbhF9IeNT84jnREyNIBLad2
DXa461sisOSAsZgsjjsgdZADc
-----END RSA PRIVATE KEY-----
EOF

 

 

 

original script from resource element:

 

#!/bin/bash
#---------------------------------------------------------------------------
#  create ssh keys
#---------------------------------------------------------------------------
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "ssh-rsa MYKEY-MYKEY-MYKEY business@test" > /root/.ssh/id_rsa_test.pub
chmod 600 /root/.ssh/id_rsa_test.pub
#
cat <<EOF >  /root/.ssh/id_rsa_test
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAsexA0IL1aRnPl0gaUk3vHAD8prbhF9IeNT84jnREyNIBLad2
DXa461sisOSAsZgsjjsgdZADc
-----END RSA PRIVATE KEY-----
EOF

chmod 600 /root/.ssh/id_rsa_test

#---------------------------------------------------------------------------
#  Create launcher
#---------------------------------------------------------------------------
cat > /root/install.ksh <<EOF
mkdir -p /img/application
scp -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa_pli baba@haha.test.pfff:/repo/application.ksh /img/application > /dev/null 2>&1
if [ -f /rep1/test/application.ksh ] ; then
  chmod 755 /rep1/test/application.ksh
  /rep1/test/application.ksh
else
  echo "Error access to test"
fi
EOF
chmod 755 /root/install.ksh

 

 

Any help would be appreciated.

Thanks to all!

0 Kudos
3 Replies
zdingelit
Contributor
Contributor

Sorry, the file is trucnated here :

 

copied script :

 

#!/bin/bash
#---------------------------------------------------------------------------
#  create ssh keys
#---------------------------------------------------------------------------
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "ssh-rsa MYKEY-MYKEY-MYKEY business@test" > /root/.ssh/id_rsa_test.pub
chmod 600 /root/.ssh/id_rsa_test.pub
#
cat <<EOF >  /root/.ssh/id_rsa_test
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAsexA0IL1aRnPl0gaUk3vHAD8prbhF9IeNT84jnREyNIBLad2
DXa461sisOSAsZgsjjsgdZADc
-----END RSA PRIVATE KEY-----
 

0 Kudos
zdingelit
Contributor
Contributor

Hi,

as a newbie, I didn't know that i can use another tag than EOF, I used FDF for example and my file was copied successfully !!

Thanks !

0 Kudos
zdingelit
Contributor
Contributor

fileName = resourceScript.name;
scriptContent = resourceScript.getContentAsMimeAttachment().content;

script = 'touch'+' '+vmRemoteFolder+fileName+' '+'|'+'cat'+' '+ "<<"+"\\"+'FDF'+' '+ '>'+
          ' '+vmRemoteFolder+fileName+ ' '+scriptContent+'FDF';

0 Kudos