Hi, Getting some data from an older MySQL box. I had an event recently where the MySQL box went off-line for maintenance without a prior announcement of service disruption. I decided to add a line on my local version of MySQL as I considered how to handle this condition going forward. system("sudo systemctl status mysql", input = rstudioapi::askForPassword("sudo password")) system("sudo systemctl status mysql",input=readline("Enter Password: ")) Both fail for the same reason, saying I need a terminal. > system("sudo systemctl status mysql", input = rstudioapi::askForPassword("sudo password")) sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required > > system("sudo systemctl status mysql",input=readline("Enter Password: ")) Enter Password: ***REDACTED*** sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required > I can run the code segments for things like ls and pwd. So, there is something unique about systemctl and R that is beyond my understanding today. QUESTIONS What is so special about systemctl and R in a system syntax statement? What are some of the best practices to confirm a box I am hitting for data with R , either local or across the network, has MySQL up and running? Thanks, -- *Stephen Dawson, DSL* /Executive Strategy Consultant/ Business & Technology +1 (865) 804-3454 http://www.shdawson.com
Not really an R question, but some processes are connected to interactive terminals (where someone can type) and some are not (because they were created and managed by another process). The system call creates a process and controls all interactions with that process. You really should not be messing with sudo in the background like that. On October 7, 2023 8:09:25 AM PDT, "Stephen H. Dawson, DSL via R-help" <r-help at r-project.org> wrote:>Hi, > > >Getting some data from an older MySQL box. I had an event recently where the MySQL box went off-line for maintenance without a prior announcement of service disruption. > >I decided to add a line on my local version of MySQL as I considered how to handle this condition going forward. > >system("sudo systemctl status mysql", input = rstudioapi::askForPassword("sudo password")) > >system("sudo systemctl status mysql",input=readline("Enter Password: ")) > > >Both fail for the same reason, saying I need a terminal. > > >> system("sudo systemctl status mysql", input = rstudioapi::askForPassword("sudo password")) >sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper >sudo: a password is required >> > > > >> system("sudo systemctl status mysql",input=readline("Enter Password: ")) >Enter Password: ***REDACTED*** >sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper >sudo: a password is required >> > > > >I can run the code segments for things like ls and pwd. So, there is something unique about systemctl and R that is beyond my understanding today. > >QUESTIONS >What is so special about systemctl and R in a system syntax statement? > >What are some of the best practices to confirm a box I am hitting for data with R , either local or across the network, has MySQL up and running? > > >Thanks,-- Sent from my phone. Please excuse my brevity.
? Sat, 7 Oct 2023 11:09:25 -0400 "Stephen H. Dawson, DSL via R-help" <r-help at r-project.org> ?????:> sudo: a terminal is required to read the password; either use the -S > option to read from standard input or configure an askpass helper > sudo: a password is requiredsudo is giving you a hint here. Normally it requires an interactive terminal (that it can set up to disable character echo), but if you give it the -S flag, it will be happy to read the password from stdin.> What are some of the best practices to confirm a box I am hitting for > data with R , either local or across the network, has MySQL up and > running?Wrap (a copy of) the connection code in try() or tryCatch() and see if it fails. If the MySQL DBI driver doesn't have a timeout option and can hang indefinitely, you can try R.utils::withTimeout (implemented using setTimeLimit(), so requires the DBI code to be interruptible / check for interrupts). Alternatively, on a GNU/Linux box there's the timeout utility (see `man 1 timeout`) that you could use together with the `mysql` command-line client to try to establish the connection. Failing everything else, there's socketConnection() to check whether anything is listening on a given address and TCP port (but not for a UNIX domain socket you would normally use to connect to the local server). Beware of the time-of-check to time-of-use problem: a particularly unlucky program could see a working MySQL server and then have it fail later when it actually tries to work with it. -- Best regards, Ivan
You don't need sudo to run: systemctl status On Sat, Oct 7, 2023, 17:09 Stephen H. Dawson, DSL via R-help < r-help at r-project.org> wrote:> Hi, > > > Getting some data from an older MySQL box. I had an event recently where > the MySQL box went off-line for maintenance without a prior announcement > of service disruption. > > I decided to add a line on my local version of MySQL as I considered how > to handle this condition going forward. > > system("sudo systemctl status mysql", input > rstudioapi::askForPassword("sudo password")) > > system("sudo systemctl status mysql",input=readline("Enter Password: ")) > > > Both fail for the same reason, saying I need a terminal. > > > > system("sudo systemctl status mysql", input > rstudioapi::askForPassword("sudo password")) > sudo: a terminal is required to read the password; either use the -S > option to read from standard input or configure an askpass helper > sudo: a password is required > > > > > > > system("sudo systemctl status mysql",input=readline("Enter Password: ")) > Enter Password: ***REDACTED*** > sudo: a terminal is required to read the password; either use the -S > option to read from standard input or configure an askpass helper > sudo: a password is required > > > > > > I can run the code segments for things like ls and pwd. So, there is > something unique about systemctl and R that is beyond my understanding > today. > > QUESTIONS > What is so special about systemctl and R in a system syntax statement? > > What are some of the best practices to confirm a box I am hitting for > data with R , either local or across the network, has MySQL up and running? > > > Thanks, > -- > *Stephen Dawson, DSL* > /Executive Strategy Consultant/ > Business & Technology > +1 (865) 804-3454 > http://www.shdawson.com > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]