Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to pass input from my bash script to the commands I run inside the script. I have no idea how to do it. I've searched all day for something like this in bash.

#!/bin/env bash

# This script is used for generating ssl cert's for websites
# ==========================================================
# Version 1.0
# ==========================================================

# Working dir
# ===========
cd "$(dirname "$0")"

# Debugging
# =========
set -x

# Imput options
# =============
read -p "Domain name: " domain_name;
read -p "Enter password: " pass;


# Verify if there is imput "conditional expressions"
# man test; help [[
# ==================================================
if [[ $domain_name ]]; then
  openssl genrsa -aes256 -out root/ca/intermediate/private/${domain_name}.key.pem 2048
  chmod 400 root/ca/intermediate/private/${domain_name}.key.pem
  openssl req -config root/ca/intermediate/openssl.cnf -key root/ca/intermediate/private/${domain_name}.key.pem -new -sha256 -out root/ca/intermediate/csr/${domain_name}.csr.pem
  openssl ca -config root/ca/intermediate/openssl.cnf -extensions server_cert -days 475 -notext -md sha256 -in root/ca/intermediate/csr/${domain_name}.csr.pem -out root/ca/intermediate/certs/${domain_name}.cert.pem
  chmod 444 root/ca/intermediate/certs/${domain_name}.cert.pem
else
  echo "Insert a domain name."
fi
if openssl x509 -noout -text -in intermediate/certs/${domain_name}.cert.pem; then
  openssl verify -CAfile root/ca/intermediate/certs/ca-chain.cert.pem intermediate/certs/${domain_name}.cert.pem
fi

Practically i need the script not fail and automate the creation of ssl self signed certificates.

The input that i need to pass is: password, domain name.

share|improve this question
    
What is the error that are you getting? – Kira Dec 15 '15 at 16:10

You can do that in bash with something like that:

#!/bin/bash
domain="domain.com"
pass="somethingCompleX"
your_script.sh <<EOF
$domain
$password
EOF

with 'your_script.sh', the script given in your question.

This syntax permits to pass some strings in input of a script. The first <<EOF gives the 'End Of File' tag that represent the end of the strings you want to pass to your script. All the characters after will be passed to your script, so the

your_script.sh <<EOF
foo
bar
EOF

equals to

$ your_script.sh
Domain name: foo
password: bar

you can also refer to this answer on stackoverflow

share|improve this answer
    
Thanks for the answer but i don't kind of understand it. – EmbargoLacuna Dec 15 '15 at 16:21
    
I edited my answer, is it more understandable for you ? – Drag Dec 15 '15 at 16:33
    
thanks, i understand now! – EmbargoLacuna Dec 16 '15 at 16:03
    
You're welcome, please accept my answer if it answers your question. – Drag Dec 16 '15 at 17:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.