This is a script which to create an opvn user, I want which answer automatically to a certain part so, I try this, it works without the red part but I must type manually.. :
Code:
#!/bin/bash
## Environnement ##
LC_ALL=C
## Paths ##
rsa_dir="etc/openvpn/easy-rsa"
rsa_key_dir="etc/openvpn/easy-rsa/keys"
user_dir="etc/openvpn/users"
ccd_dir="etc/openvpn/ccd"
## Regex filter ##
regex_filter='[^a-zA-Z_0-9\s]'
## Position ##
cd /"$rsa_dir"/
## Loop ##
while
read -p "Please can you enter the vpn's username : " username
[[ -z "$username" ]] || [[ ${#username} -lt 2 ]] || [[ ${#username} -gt 15 ]] || [[ "$username" =~ $regex_filter ]]
do
echo "Your entry must not contain special characters and its length must do between 2-15 characters."
done
## Commands ##
. ./vars
./build-key "$username" << EOF
(14 empty lines feed)
y
y
EOF
cp -p /"$rsa_key_dir"/"$username".* /"$user_dir"/
cd /"$user_dir"/; cp template.ovpn "$username".ovpn
sed -i 's/name/'$username'/g' "$username".ovpn
tar -czvf "$username".tar.gz "$username".* ta.key ca.crt
touch ../ccd/"$username"
cp -a "$username".tar.gz /tmp/
scp "$username".* usersend@1.1.1.1:/tmp/.
Ouput :
Code:
$./user_ovpn.sh
Please can you enter the vpn's username : iki
NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys
Generating a 2048 bit RSA private key
........................................................................+++
....+++
writing new private key to 'iki.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [FR]:State or Province Name (full name) [FR]:Locality Name (eg, city) [hello]:
Organization Name (eg, company) [Hello]:Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [iki]:Name [HELLO_VPN]:Email Address [hello@machin.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:An optional company name []:Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'FR'
stateOrProvinceName :PRINTABLE:'FR'
localityName :PRINTABLE:'Hello'
organizationName :PRINTABLE:'Hello'
commonName :PRINTABLE:'Hello'
name :T61STRING:'Hello'
emailAddress :IA5STRING:'Hello@machin.com'
Certificate is to be certified until Oct 13 06:01:44 2026 GMT (3650 days)
Sign the certificate? [y/n]:CERTIFICATE WILL NOT BE CERTIFIED: I/O error
iki.crt
iki.csr
iki.key
iki.ovpn
ta.key
ca.crt
Example of output with manually entries :
Code:
$./vpn_user.sh
Please can you enter the vpn's username : testuser2
NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys
Generating a 2048 bit RSA private key
............................................+++
............+++
writing new private key to 'testuser2.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [FR]:
State or Province Name (full name) [FR]:
Locality Name (eg, city) [Hello]:
Organization Name (eg, company) [hello]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [testuser2]:
Name [HELLO_VPN]:
Email Address [hello@machin.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'FR'
stateOrProvinceName :PRINTABLE:'FR'
localityName :PRINTABLE:'Hello'
organizationName :PRINTABLE:'Hello'
commonName :PRINTABLE:'testuser2'
name :T61STRING:'HELLO_VPN'
emailAddress :IA5STRING:'hello@machin.com'
Certificate is to be certified until Oct 13 05:45:45 2026 GMT (3650 days)
Sign the certificate? [y/n]:y1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
testuser2.crt
testuser2.csr
testuser2.key
testuser2.ovpn
ta.key
ca.crt
In red that represent the manually entries that I want which works automatically
Thanks in advance..
Last edited by Arnaudh78; 10-26-2016 at 04:09 PM..
Hi
I have some trouble entering if-then condition in a single line on a command prompt in csh.
Could someone show how does one do that ?
eg:
source .cshrc;
cd $dir;
pwd;
test -d $backup_dir;
if
then
mkdir -p ${backup_dir};
echo inside loop;
fi;
echo outside loop;
mv -f... (3 Replies)
Hi Friends,
We need to create a script which will invoke a command with diffrent parameters.
The command invoked needs the password. So how automatically we can enter password in the script to the command?
example.:
#!/bin/ksh
for par in `cat parfile` do
# Here is the main command... (1 Reply)
In the script i am passing a command from script which is called from cron. When this command is called from cron the unix prompt asks for password. Can we automatically enter the password when promted(if the password is hardcoded in script)??
Please let me know how to enter the password... (4 Replies)
I need to retrieve thousands of lines of information from hundreds of nodes. Each node requires a passowrd in order to retrieve the information. Fortunately, the password is the same for each one of them. So I am trying to come up with a script that would allow me to include the password so I can... (0 Replies)
Hi
I am stucked in the below script .I want to input with yes/no from the user and then execute the code inside if but it is not working .I just need the logic as where I am wrong so that i can use the same in my work .
then
echo "Hi All"
fi
].
Please suugest . (4 Replies)
Hi
I have a file like so:
Code:
Frank Peter Tony Robert Mike 1 2 3 4 5 5 4 2 3 1 4 3 1 5 2
My out should look like this:
Peter
Tony
Mike
and so on....
I have the first part done to ask the user to... (8 Replies)
HI
i have written a script to ask input from the user.
this script should promote the user for y/n input. if user enters anyother input then y/n
the script promotes him again. this below code is working fine for all the cases.
except for space and enter " if i give space and enter it is... (2 Replies)
have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value
File 1
export SERVER_CONNECTION=//dvlna002:10001/SmartServer
File2
export SERVER_CONNECTION=///SmartServer
File3
export... (1 Reply)
Hi
I'm working with AIX 6.1
I would like to ssh to a server without entering password ( to monitor something) but there's no way to do that by authentication keys, so I need to write a script which can ssh to that server without entering password ( no need to hide passsword in the script, just an... (9 Replies)
Hey All,
I am writing one script using expect, that script which is used in spawn will accepts only 1. Enter 2. Ctrl+c
Press Control-C to exit, Enter to proceed.
Could some one share some thoughts to send the above user inputs in linux expect block ?
Thanks,
Sam (0 Replies)