Reputation: 1199
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
Upvotes: 0
Views: 1973
Reputation: 362147
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
Upvotes: 1