2

I'm being asked to automate a task which creates a backup. In order to do this one of the steps is to enter into the Amster tool, which itself enters its own shell where I then execute more commands until I exit out of it. In order to successfully enter Amster I need to provide credentials, once inside Amster I also need to execute a connect command providing credentials and then execute more commands.

Is there a way to accomplish all of this from a single sh script? Or is it not possible to drill down into shells within shells?

This would be the beginning of the sh script, although more commands would be added after, it illustrates what I'm trying to ask. So after the ./amster line it enters its own shell where the connect command should be executed and prompt for credentials (which is part of the problem I'm trying to solve, enter the credentials in a line of the script maybe?)

[Access-Manager]:/mnt/forgerock/amster> tail autoback.sh
cd /mnt/forgerock/amste
export JAVA_HOME=/usr/
./amster
connect -i http://xxxxxxxx.com:8080/auth

If I execute that script as is, it will take me into amster and get me into the amster prompt, but the connect command will not execute.

[Access-Manager]:/mnt/forgerock/amster> ./autoback.sh
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/mnt/forgerock/amster/amster-6.5.2.3.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Amster OpenAM Shell (6.5.2.3 build 4ed586d624, JVM: 11.0.7)
Type ':help' or ':h' for help.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
am>

So this just leaves me at the amster prompt, ready for the next command. This is where I don't know how to make it execute the following command.

Any ideas??

If you need more details please let me know.

Thanks.

1
  • Try searching for [expect] here on Stack Overflow's search box. Commented Jul 9, 2020 at 23:15

2 Answers 2

1

If by automate you mean completely without human intervention, ie. to enter credentials, You can go with [expect] as mentioned in comment or see if amster allows credentials to be passed at the command line. If second is an option, you could try a heredoc, something like:

./amster<<EOF
connect -i http://auth-sb.company.com:8080/auth
...
EOF

As an example that I use:

sqlplus -s /nolog<<SQL
connect user/passwd@db
select 'name'
from dual;
exit;
SQL

I have user and passwd sourced from another file into variables so these details are not required in the script

Hopefully that will give you some ideas :)

Sign up to request clarification or add additional context in comments.

Comments

0

A general advise while working with amster, use a shell script to generate amster files, and then lauche them from your sh script, it should looke like this:

echo -e "AM_URL_HTTPS=System.getProperty(\"AM_URL_HTTPS\")\nAM_CONFIG_DIR=System.getProperty(\"AM_CONFIG_DIR\")\nAMADMIN_PWD=System.getProperty(\"AMADMIN_PWD\")\nCOOKIE_DOMAIN=System.getProperty(\"COOKIE_DOMAIN\")\n\ninstall-openam --serverUrl AM_URL_HTTPS --adminPwd AMADMIN_PWD --acceptLicense --cookieDomain COOKIE_DOMAIN --cfgDir AM_CONFIG_DIR\n:exit " > /opt/am/asmter_scripts/install-am.amster

chmod +x /opt/openam/amster_scripts/install-am.amster 

/opt/openam/amster/amster -D javax.net.ssl.trustStore=$JAVA_TRUSTSTORE -D javax.net.ssl.trustStoreType=jks /opt/openam/amster_scripts/install-am.amster -D AM_URL_HTTPS=${AM_URL_HTTPS} -D AM_CONFIG_DIR=${AM_CONFIG_DIR} -D AMADMIN_PWD=${AMADMIN_PWD} -D COOKIE_DOMAIN=${COOKIE_DOMAIN} 

This script will generate install.amster file, then run it from your sh script.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.