I'm currently trying to run my script on startup, being an Oracle 19C script for starting the database and the listener at system boot , I will paste it here (script.sh) . The way I'm trying to work is as manually as possible, I don't want to include it in oratab or anything else. I'm currently working on a Virtual Machine with Oracle Linux 7.9 installed :
#!/bin/bash
# /etc/init.d/script.sh
# chkconfig: 2345 85 60
ORACLE_SID=mysid
ORAENV_ASK=NO
source oraenv
startdatabase(){
sqlplus << EOF
connect / as sysdba
startup
EOF
echo "Database opened"
}
checkingdatabase()
{
pmon=`ps -ef | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep`
if [ "$pmon" != "" ] ; then
echo "${ORACLE_SID} already opeened."
else startdatabase
fi
}
checkingdatabase
listener()
{
status=`lsnrctl status | grep "Connection refused"`
if [ "$status" != "" ]; then
lsnrctl start
echo "Listener opened"
else echo "Listener off"
fi
}
listener
The script is located in /etc/init.d with script.sh being its name. I tried to run it on startup using crontab :
@reboot sh /etc/init.d/script.sh
or @reboot /etc/init.d/script.sh
I tried also with with article : https://unix.stackexchange.com/questions/188042/running-a-script-during-booting-startup-init-d-vs-cron-reboot but nothing seems to work, also if I do chkconfig --list it will show me this, as it should be running :
script.sh 0:off 1:off 2:on 3:on 4:on 5:on 6:off
The script is also executable, I've tried with rc.local file and also doesn't work :
-rwxrwxr-x. 1 oracle oracle 900 Dec 29 15:16 script.sh
How can I make this work and run at startup ? It's really frustrating, I've tried all the methods and it will not just load at boot and do its job. Any help would be much appreciated ! I've checked also for a lot of articles and none of them help. I want to mention also that the script works just fine when running normally. Thank you !