0

I am trying to LDAP directory via ForgeRock's OpenDJ, I am sending most of the commands via ssh and it works, however I am stuck at one command which requires input in different line. Here is how it works, if I type it in shell:

ldapmodify -h server.example.com -p 1389 -w '1234' -D "cn=Directory\ Manager" -a 
dn:ou=test1,dc=example,dc=com 
objectclass:top 
objectclass:organizationalUnit
ou:test1

Note that there are four lines of input and the command concludes after getting one extra line of blank input (carriage-return). The command's input are dynamic and based on the variables. How can I send this multi-line command via ssh?

Here is how I am sending other commands:

SEND_REMOTE_CMD='opendj/bin/dsconfig create-backend 
--backend-name eg1 
--set base-dn:dc=eg1,dc=com
--set enabled:true
--type local-db
--hostname server.example.com
--port 5444
--trustAll
--bindPassword '1234'
--no-prompt
--bindDN "cn=Directory\ Manager"'

ssh [email protected] $SEND_REMOTE_CMD
0

1 Answer 1

1

To script a command and send it multiple lines of input you can use a here document.

ldapmodify -h server.example.com -p 1389 -w '1234' -D "cn=Directory\ Manager" -a <<INPUT
dn:ou=test1,dc=example,dc=com 
objectclass:top 
objectclass:organizationalUnit
ou:test1
INPUT

To do it over SSH, do the same thing, but add the ssh command in front.

ssh [email protected] ldapmodify -h server.example.com -p 1389 -w '1234' -D "cn=Directory\ Manager" -a <<INPUT
dn:ou=test1,dc=example,dc=com 
objectclass:top 
objectclass:organizationalUnit
ou:test1
INPUT
Sign up to request clarification or add additional context in comments.

2 Comments

Is there any way to pass variables in Here Documents? Or if I can pre-compose a string and pass it into here documents?
Yes, you can use variables in here documents. Try it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.