LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-20-2019, 07:05 PM   #1
TBotNik
Member
 
Registered: May 2016
Posts: 333

Rep: Reputation: Disabled
New Bash Q


All,

Need to write a script for a server to check the current DB installs and install any missing. I have this code with the results and not sure the best/fastest way to determine from the results the actions I need to take:
Code:
mystr="mysql --version";
Quote:
mysql Ver 14.14 Distrib 5.5.62, for debian-linux-gnu (x86_64) using readline 6.3
Code:
instr="ingprenv";
Quote:
ingprenv: command not found
Code:
ifstr="onstat -# onstat -";
Quote:
No command 'onstat' found, did you mean:
Command 'bnstat' from package 'pvpgn' (universe)
Command 'nstat' from package 'iproute2' (main)
Command 'lnstat' from package 'iproute2' (main)
Command 'vnstat' from package 'vnstat' (universe)
onstat: command not found
Code:
pgstr="psql --version";
Quote:
The program 'psql' can be found in the following packages:
* postgresql-client-common
* postgres-xc-client
Try: apt-get install <selected package>
As you can see the existing cmd line commands to find the 4 needed DBs vary immensely in both cmd and also in response.

The DBs are:
Quote:
MySQL
Informix
Ingres
PostGres
The only installed DB by default is MySQL, the other three need installing and the install procedure for MySQL, must be skipped, especially since any tweaks at all on MySQL totally destroys not only the MySQL but also the entire X-Win environment.

Open to suggestions on this. Have to config 5 more servers from the BASH scripts I'm currently writing.

Cheers!

TBNK

Last edited by TBotNik; 02-20-2019 at 07:08 PM.
 
Old 02-20-2019, 07:15 PM   #2
TBotNik
Member
 
Registered: May 2016
Posts: 333

Original Poster
Rep: Reputation: Disabled
All,

It appears if I focus on the string "command not found" I can find/eliminate both the Informix and Ingres installs so code like:
Code:
case $i in "command not found"); esac
Should be adequate for these 2 DB connects and/or their installs.

Am I right?

Cheers!

TBNK
 
Old 02-20-2019, 07:23 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 18,322

Rep: Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596
Would that be the same as testing if the file exists? But you need to know the directory which may not be the same for different distribution.

Last edited by michaelk; 02-20-2019 at 07:27 PM.
 
Old 02-21-2019, 04:34 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 11,272
Blog Entries: 8

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
why aren't you showing us the script?
this makes very little sense to me...
 
Old 02-21-2019, 02:19 PM   #5
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 2,731

Rep: Reputation: 933Reputation: 933Reputation: 933Reputation: 933Reputation: 933Reputation: 933Reputation: 933Reputation: 933
Quote:
MySQL
Informix
Ingres
PostGres
  1. Identify the daemon that results from the installation of each database.
  2. use find (man find) to search for the existence of it
    and/or
  3. use ps to see if it is running.
 
Old 03-15-2019, 06:47 PM   #6
TBotNik
Member
 
Registered: May 2016
Posts: 333

Original Poster
Rep: Reputation: Disabled
All,

OK found this dpkg cmd:
Code:
dpkg --get-selections | grep mysql-server
Which produces this result:
Quote:
mysql-server install
mysql-server-5.5 install
mysql-server-core-5.5 install
and this cmd:
Code:
service mysql status
Which produces this result:
Quote:
mysql start/running, process 1186
So tried putting them into my script as follows:
Code:
# Check for MySQL
echo "Installing MySQL!";
my_str=$(dpkg -s mysql-server | grep status);
echo "Out=> $my_str";
case $my_str in 
	"mysql-server" & "install")
		echo "MySQL Intalled";;
	"not installed")
		echo "MySQL Not installed";;
		#continue;;
esac;

my_str=$(service mysql status);
echo "Out=> $my_str";
case $my_str in 
	'mysql')
		echo "MySQL Intalled";;
	*)
		echo "MySQL Not installed";;
		#continue;;
esac;
The first case the "my_str" var does not assign, but the second does.

However neither correctly render the correct outcome as though MySQL is installed, per the direct cmd line entry results, the script always shows "MySQL not installed".

I've tried "", '', and no quotes in the case statement and nothing changes.

What am I doing wrong here? I'm sure I'm not handling the string values right inside the "case" statements, but haven't been using "case" statement, until recently.

Cheers!

TBNK

Last edited by TBotNik; 03-15-2019 at 07:00 PM.
 
Old 03-15-2019, 08:02 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 18,322

Rep: Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596
Code:
 dpkg -s mysql-server | grep Status
The Status has a capitalized S.

and the output should be:
Status: install ok installed

In the second case pun intended you need to use pattern matching or include the exact output before the statement will evaluate to true.

Last edited by michaelk; 03-15-2019 at 08:07 PM.
 
Old 03-16-2019, 04:50 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 11,272
Blog Entries: 8

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Quote:
Originally Posted by TBotNik View Post
and this cmd:
Code:
service mysql status
are you sure your distro doesn't use systemd?
i'm pretty sure it should be
Code:
systemctl status mysql
 
Old 03-16-2019, 08:44 AM   #9
TBotNik
Member
 
Registered: May 2016
Posts: 333

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
are you sure your distro doesn't use systemd?
i'm pretty sure it should be
Code:
systemctl status mysql
ondoho,

systemctl not installed!

Cheers!

TBNK
 
Old 03-16-2019, 08:49 AM   #10
TBotNik
Member
 
Registered: May 2016
Posts: 333

Original Poster
Rep: Reputation: Disabled
All,

Since I couldn't get the "case" statement to work right went back to:
Code:
# Check for MySQL
my_str=$(service mysql status);
if echo $my_str | grep -q 'running'; then
	echo "MySQL Already Intalled";
else
        echo "Installing MySQL!";
	apt-get install mysql-server;
fi
Now working, so running the same tests for the other DBs, but like PostGres only uses "psql" as the running process, so having to look up all these actual items that would appear in "ps -A" to correctly check all the right processes.

If you know these please chime in with the ps -A name. Since it's my server and all DBS must be available for use on the network, I'm including Oracle and MS-SQL also.

Cheers!

TBNK

Last edited by TBotNik; 03-17-2019 at 04:00 PM.
 
Old 03-16-2019, 09:07 AM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 18,322

Rep: Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596Reputation: 2596
Technically a database can be installed but not running so your test to see if it is installed is not all inclusive.

This may work. If the string is blank mysql is installed.
dpkg -s mysql-server | grep not

Last edited by michaelk; 03-16-2019 at 09:15 AM.
 
Old 03-17-2019, 01:35 PM   #12
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 11,272
Blog Entries: 8

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Quote:
Originally Posted by TBotNik View Post
ondoho,

systemctl not installed!

Cheers!

TBNK
That would have been the perfect chance to tell us which distro you actually use for this.

Cheers!

o.
 
Old 03-17-2019, 04:01 PM   #13
TBotNik
Member
 
Registered: May 2016
Posts: 333

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Technically a database can be installed but not running so your test to see if it is installed is not all inclusive.

This may work. If the string is blank mysql is installed.
dpkg -s mysql-server | grep not
michaelk,

Yes I will have to put the "start" cmd in after the install, for this to be valid!

Thanks!

TBNK
 
Old 03-17-2019, 04:04 PM   #14
TBotNik
Member
 
Registered: May 2016
Posts: 333

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
That would have been the perfect chance to tell us which distro you actually use for this.

Cheers!

o.
ondoho,

Know I stated it in the beginning, but it's Kubuntu 14.04 LTS, and have stated in other posts my reasons for being this far behind on version, expressly that none of the newer LTS version will install. All crash 1/2 - 3/4 through the install process, so always have to revert to 14.04 to have a working server or desktop.

Won't install on new or used machines and have burnt the distros with 5 different .iso makers/burners and all fail. Just won't waste time on junk! We actually got 16.04 installed on one machine and with all the things stripped out, was a bust for development, but didn't matter as the OS crashed after only 23 days of operation.

Have had 0 install and operation issues with Ubuntu/Kubuntu since 8.04 LTS, until we got to 16.04. Obviously the testing required for an OS release is not only not understood, but also not done by the "Johnny Come Lately" developers.

Cheers!

TBNK

Last edited by TBotNik; 03-17-2019 at 06:07 PM.
 
Old 03-18-2019, 03:31 PM   #15
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 11,272
Blog Entries: 8

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Quote:
Originally Posted by TBotNik View Post
Know I stated it in the beginning
no you didn't.
but it's all good, at least we know now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Firms bash Bash bug with new round of Shellshock patches LXer Syndicated Linux News 0 09-28-2014 03:51 PM
[SOLVED] Is it possible to create a bash script to create multiple new bash scripts Batistuta_g_2000 Linux - Newbie 6 02-19-2013 11:42 AM
Bash problem : -bash: [: /bin/bash: unary operator expected J.A.X Linux - Software 1 09-22-2011 05:52 AM
passwd.new, shadow.new, group.new and gshadow.new after upgrade to slackware 12.1 rhermsen Slackware 6 11-08-2008 04:59 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration