New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Comments
mysqld
+1 to @ricardo
It would probably be a good idea to use the full path to mysqld too.
I've used
Can you please post a code snippet? Don't get it to work.
which
is not recommended because of OS dependent exit status (it may not always work).type
is prefered in Bash.For example:
It should exist here, at least on Debian: /usr/sbin/mysqld
Silvenga has a good idea too.
I'm now trying to check the MySQL connection, it works fine, but how do I stop the command from outputting "MySQL root password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)" when a wrong password is entered.
http://pastebin.com/Ggu1GgSh
Got it, thanks for helping everyone!
I just use
fsockopen
to check port 3306 (or custom MySQL port if used) not sure what the Bash alternative isCan you explain what you exactly want to achieve? How do you define installed? Relying on the path, like some mentioned, might help in many cases but not in all. There could be a MySQL instance sitting somewhere quietly in a directory and you'd never find it via the path.
This works if you are in a familiar environment. It wouldnt work as generic way though. Something else could be listening on 3306, it could be on some random port or on no port at all.
Maybe check if the Unix socket file exists?
Although this is probably overkill, we could check what process is using that port using something like
netstat
.I think on high-load, netstat will be worser than try to connect to port.
Checking for the port would be still a problem if it uses the domain socket. However using netstat might be actually the most promising approach, given the script executes under root, nobody had the funny idea of renaming the executable and you check for the listeners and domain sockets.
Why? Netstat is basically a data parser and it would only be used to ensure that the socket is owned by a mysql binary.
It's part of a script that has a config file for the user to set the services to be monitored and which ports they're running on
So an automatic pre-selection of services which the user can change and modify? In this case it probably doesnt need to be foolproof and they easiest way might be the which/type path.