I'm trying automate DBCA to create a new database. I'm using the box bseller/oracle-standard with Vagrant.
provision.sh
#!/bin/bash
echo 'Import environment variables'
env=$( grep -ic "ORACLE_SID" /etc/profile )
if [ ! $env -eq 1 ] ; then
echo export ORACLE_SID=mydatabase >> /etc/profile
echo export ORACLE_BASE=/u01/app/oracle >> /etc/profile
echo export ORACLE_HOME=/u01/app/oracle/product/11.2/dbhome_1 >> /etc/profile
source /etc/profile
echo export PATH=$PATH:$ORACLE_HOME/bin >> /etc/profile
fi
echo "Connect with user ORACLE"
sudo su -l oracle
echo "Loading environment variables"
source /etc/profile
echo 'Create database mydatabase'
if [ ! -d /u01/app/oracle/oradata/mydatabase ] ; then
dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbName mydatabase -sysPassword mypassword -systemPassword mypassword -scriptDest /u01/app/oracle/oradata/mydatabase -characterSet WE8ISO8859P1
fi
But this script doesn't worked:
$ sh provision.sh
Import environment variables
Connect with user ORACLE
Loading environment variables
Create database mydatabase
DBCA cannot be run as root.
Running all lines from provision.sh in command line. worked!
I am wondering that the line below does not work to run the oracle command inside of a shell script:
sudo su -l oracle
You should wrap your command to get it work:
su -c "dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbName qualidade -sysPassword password -systemPassword password -scriptDest /u01/app/oracle/oradata/qualidade -characterSet WE8ISO8859P1" -s /bin/sh oracle
I got this solution here:
how to run script as another user without password
"Unable to check for available memory"
I fixed in this form:
I go to my other server with OLD installation Oracle (running fine Oracle 11g), then I find 3 files:
oracle_env.csh
oracle_env.sh
nls_lang.sh
becouse this files no exist in new server, I create with the content (path correct) the files
oracle_env.csh
oracle_env.sh
and put this lines into they:
touch /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.csh
echo 'setenv ORACLE_HOME /opt/oracle/product/18c/dbhomeXE
setenv ORACLE_SID XE
setenv NLS_LANG `$ORACLE_HOME/bin/nls_lang.sh`
setenv PATH $ORACLE_HOME/bin:$PATH' >> /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.csh
after second file:
touch /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.sh
echo 'export ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
export ORACLE_SID=XE
export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
export PATH=$ORACLE_HOME/bin:$PATH' >> /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.sh
becouse the file nls_lang.sh is very long and have many config about CHARSET, I copy from OLD server to NEW server.
after is necesary config owner/group of this files:
chown oracle:oinstall /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.csh
chown oracle:oinstall /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.sh
chown oracle:oinstall /opt/oracle/product/18c/dbhomeXE/bin/nls_lang.sh
also the file nls_lang.sh require 755:
chmod 0755 /opt/oracle/product/18c/dbhomeXE/bin/nls_lang.sh
is necesary login as user oracle:
su -l oracle
then I go to folder and load vars environment:
cd /opt/oracle/product/18c/dbhomeXE/bin
. ./oracle_env.sh
finally I can run the command dbca:
dbca -createDatabase -silent -gdbName ora18c -templateName XE_Database.dbc -sysPassword YourPWD1 -systemPassword YourPWD1 -dbsnmpPassword YourPWD1 -datafileDestination /opt/oracle/oradata -storageType FS -memoryPercentage 20 -emConfiguration NONE -sampleSchema false -J-Doracle.assistants.dbca.validate.ConfigurationParams=false
and I get the greath result:
[server#petro bin]$ dbca -createDatabase -silent -gdbName ora18c -templateName XE_Database.dbc -sysPassword YourPWD1 -systemPassword YourPWD1 -dbsnmpPassword YourPWD1 -datafileDestination /opt/oracle/oradata -storageType FS -memoryPercentage 20 -emConfiguration NONE -sampleSchema false -J-Doracle.assistants.dbca.validate.ConfigurationParams=false
Prepare for db operation
10% complete
Copying database files
40% complete
Creating and starting Oracle instance
42% complete
46% complete
50% complete
54% complete
60% complete
Completing Database Creation
66% complete
69% complete
70% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
/opt/oracle/cfgtoollogs/dbca/ora18c.
Database Information:
Global Database Name:ora18c
System Identifier(SID):ora18c
Look at the log file "/opt/oracle/cfgtoollogs/dbca/ora18c/ora18c.log" for further details.
[server#petro bin]$
becouse I need PHP in this servers, I require OCI8, then I run:
/usr/bin/ea-php72-pecl install oci8
/usr/bin/ea-php71-pecl install oci8
/usr/bin/ea-php70-pecl install oci8
when this request:
**Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :**
samplelly [ENTER] then this run fine for me...
Regards.
Related
I am trying to set up GOPATH GOROOT in my AWS EC2 Ubuntu 20.04 user data, but it never worked, every time I connect to the AWS EC2 and view the log in /var/log/cloud-init-output.log it always says
go: not found, but if I key in the echo part it will work.
I am trying to set up multiple EC2 with this basis, so I can't key in every instance myself.
The CloudFormation yaml user data part is below:
UserData:
Fn::Base64: |
#!/bin/bash
wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.14.4.linux-amd64.tar.gz
mkdir -p ~/go/{bin,pkg,src}
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin:$GOROOT/bin' >> ~/.bashrc
echo 'export GO111MODULE=auto' >> ~/.bashrc
source ~/.bashrc
apt -y update
apt -y install mongodb wget git
systemctl start mongodb
apt -y install git gcc cmake autoconf libtool pkg-config libmnl-dev libyaml-dev
go get -u github.com/sirupsen/logrus
cd ~
git clone --recursive https://github.com/williamlin0504/free5gcWithOCF.git
cd free5gcWithOCF
make
And here is the error inside /var/log/cloud-init-output.log
Error while user data runs
Is there anyone is familiar with this, please I need some help~
In your error message, in the Makefile at line 30 there is a program bin/amf being used
This program appears to be a shell script with a problem in line 1
The nature of the problem is "go: not found"
If you have the bare word "go" in line 1 of the shell script and the path cannot find it then this is what will happen
Probably you need to alter the last line of your userdata shell script to say
PATH=/usr/local/go/bin:$PATH make
I know you have a source command earlier in the script that is supposed to set this up but it doesn't do what you think it does
I provisioned a CentOS VM on ec2 and installed Minishift but it doesn't start and I realize this has something to do with nested virtualization.
What exactly should I do to use this existing CentOS VM on ec2 to run minishift ?
What is a proven way to install MiniShift on a cloud VM ?
I am going to deploy only projects for experimenting.
I am connecting using 'ssh' from my Windows laptop.
-- Starting profile 'minishift'
-- Check if deprecated options are used ... OK
-- Checking if https://github.com is reachable ... OK
-- Checking if requested OpenShift version 'v3.11.0' is valid ... OK
-- Checking if requested OpenShift version 'v3.11.0' is supported ... OK
-- Checking if requested hypervisor 'kvm' is supported on this platform ... OK
-- Checking if KVM driver is installed ...
Driver is available at /usr/local/bin/docker-machine-driver-kvm ...
Checking driver binary is executable ... OK
-- Checking if Libvirt is installed ... OK
-- Checking if Libvirt default network is present ... OK
-- Checking if Libvirt default network is active ... OK
-- Checking the ISO URL ... OK
-- Checking if provided oc flags are supported ... OK
-- Starting the OpenShift cluster using 'kvm' hypervisor ...
-- Starting Minishift VM .... FAIL E0812 12:08:28.036276 17936 start.go:494] Error starting the VM: Error getting the state for host: unexpected EOF. Retrying.
Error starting the VM: Error getting the state for host: unexpected EOF
What is a proven way to install MiniShift on a cloud VM ?
GCP supports nested virtualization which is required to install Minishift. I think this was the reason for the failure of my procedure. Not sure if this is supported by AWS ec2 instances.
There may be other ways to install Minishift.
I am posting instructions to install MiniShift on a GCP VM instance. Please note
this is a collection of guidelines I found by searching. So they are available else where but I am answering because this really worked for me and it was easy.
I have deployed a sample successfully.
gcloud compute disks create minishiftdisk \
--image-project ubuntu-os-cloud \
--image-family ubuntu-1804-lts --zone asia-south1-a
gcloud compute images create nested-vm-image \
--source-disk minishiftdisk --source-disk-zone asia-south1-a \
--licenses "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
gcloud compute instances create minishift-vm \
--zone asia-south1-a \
--machine-type=n1-standard-2 \
--boot-disk-size=50GB \
--min-cpu-platform "Intel Skylake" \
--image nested-vm-image
sudo apt-get update
sudo apt install qemu-kvm libvirt-daemon libvirt-daemon-system
curl -L https://github.com/minishift/minishift/releases/download/v1.34.1/minish
ift-1.34.1-linux-amd64.tgz -O
tar xvzf minishift-1.34.1-linux-amd64.tgz
sudo cp minishift-1.34.1-linux-amd64/minishift /usr/local/bin/
sudo curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v
0.10.0/docker-machine-driver-kvm-ubuntu16.04 -o /usr/local/bin/docker-machine-driver-kvm
sudo chmod +x /usr/local/bin/docker-machine-driver-kvm
minishift start
radhakrishnan_mohan#minishift-vm:~$ minishift oc-env
export PATH="/home/radhakrishnan_mohan/.minishift/cache/oc/v3.11.0/linux:$PATH"
# Run this command to configure your shell:
# eval $(minishift oc-env)
radhakrishnan_mohan#minishift-vm:~$ eval $(minishift oc-env)
radhakrishnan_mohan#minishift-vm:~$ oc get pods
No resources found.
sudo apt install -y xfce4 xfce4-goodies firefox
sudo apt install -y xrdp
radhakrishnan_mohan#minishift-vm:~$ echo xfce4-session > ~/.xsession
radhakrishnan_mohan#minishift-vm:~$ sudo nano /etc/xrdp/startwm.sh
My script looked like this. I added the last line and saved it.
#!/bin/sh
# xrdp X session start script (c) 2015, 2017 mirabilos
# published under The MirOS Licence
if test -r /etc/profile; then
. /etc/profile
fi
if test -r /etc/default/locale; then
. /etc/default/locale
test -z "${LANG+x}" || export LANG
test -z "${LANGUAGE+x}" || export LANGUAGE
test -z "${LC_ADDRESS+x}" || export LC_ADDRESS
test -z "${LC_ALL+x}" || export LC_ALL
test -z "${LC_COLLATE+x}" || export LC_COLLATE
test -z "${LC_CTYPE+x}" || export LC_CTYPE
test -z "${LC_IDENTIFICATION+x}" || export LC_IDENTIFICATION
test -z "${LC_MEASUREMENT+x}" || export LC_MEASUREMENT
test -z "${LC_MESSAGES+x}" || export LC_MESSAGES
test -z "${LC_MONETARY+x}" || export LC_MONETARY
test -z "${LC_NAME+x}" || export LC_NAME
test -z "${LC_NUMERIC+x}" || export LC_NUMERIC
test -z "${LC_PAPER+x}" || export LC_PAPER
test -z "${LC_TELEPHONE+x}" || export LC_TELEPHONE
test -z "${LC_TIME+x}" || export LC_TIME
test -z "${LOCPATH+x}" || export LOCPATH
fi
if test -r /etc/profile; then
. /etc/profile
fi
test -x /etc/X11/Xsession && exec /etc/X11/Xsession
exec /bin/sh /etc/X11/Xsession
startxfce4
Restart xrdp
radhakrishnan_mohan#minishift-vm:~$ sudo service xrdp restart
Change password for root
sudo su
passwd
Windows Remote Desktop connection
Once I connected to the GCP VM instance's public IP I was able to login using the credentials root/password
Start firefox from the linux desktop and login to OpenShift
I'm attempting to setup postgres 9.6 on ubuntu/vagrant through a provisioning script. Part of my script adds a line to pg_hba.conf with the following command:
sudo -u postgres echo "host all all all md5" >> /etc/postgresql/9.6/main/pg_hba.conf
However, this gives me the error -bash: /etc/postgresql/9.6/main/pg_hba.conf: Permission denied
Which is strange because I am allowed to edit the file with either sudo nano or sudo -u postgres nano.
Here are the permissions on the file:
-rw-r----- 1 postgres postgres 4641 Apr 6 16:11 pg_hba.conf
How can I add this line to my configuration file in a script?
The problem here is that redirection happens before command execution. So the redirection doesn't have the elevated privileges you expected it to.
There's more than one way around that problem. I generally use something like this.
echo "host..." | sudo tee -a /etc/postgresql/9.6/main/pg_hba.conf
Piping to sudo tee... avoids problems with quoting.
How bash executes commands
Redirections
I have installed Oracle 11gR2 and want to connect with SQL*Plus but I can't.
I login in as root and then switch user to oracle as
su oracle
I have added required Oracle environment variables in .bash_profile but it is not executed when i switch to oracle user from root. Even executing the bash file manually does not export the variables using following command
$ ./.bash_profile
These are the contents of my .bash_profile:
#!/bin/bash
#.bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programsotp
PATH=$PATH:$HOME/bin
export PATH
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_HOSTNAME=orcl.genie.com; export ORACLE_HOSTNAME
ORACLE_UNQNAME=orcl; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
umask 022
To check if you are running in a login shell, use the following command
shopt login_shell
if it displays
login_shell off
then you are not running in a login shell. You need to switch to oracle user with -l switch
su -l oracle
Hope, it solves your problem.
I have written below shell script for taking automatic backup . Now if i want to take hot backup how to write the script. I know we need to use db.fsyncLock(). But how to use it in the shell script. Please let me know as I'm new to shell scripting.
#bin!bash
DIR=`date +%m_%d_%y:%H:%M:%S`
cd /opt/mongo/bin
./mongodump --port 27020 --db db --out /data/mongo/backup/$DIR
Create a directory "auto_backup".
Create "autobackup.sh"
DIR=date +%d%m%y
DEST=auto_backup/$DIR
mkdir $DEST
mongodump -d -o $DEST
chmod +X autobackup.sh
Go to cron tab
in Ubuntu
sudo crontab -e
in centos
sudo vim /etc/crontab
m h dm M dw UserName Path of your .sh file
1 0 * * * username /home/username/auto_backup_script.sh
m: Minutes (0-59)
h: Hours (0-23)
dm: Day of Month (1-31)
M: Month(1-12)
dw: day of week (0 - 6) (Sunday=0 or 7)
username: System Username
Save it.
and Restart your cron service.
Below script helps me with it:
DIR=date +%m_%d_%y:%H:%M:%S
cd /opt/mongo/bin
./mongo admin --eval "printjson(db.fsyncLock())"
./mongodump --port 27020 --db db --out /data/mongo/backup/DIR
./mongo admin --eval "printjson(db.fsyncUnlock())"