0

I added some shell scripts changing some contents of file in /etc/init.d directory.

#!/bin/bash

set -x

DBMS_ID='testuser'
DBMS_PW1='*****'

CONFIG_EXEC="./some_program"
${CONFIG_EXEC} config <<EOF
yes
127.0.0.1
${DBMS_ID}
${DBMS_PW1}


yes
EOF

cp -f A.txt B.txt

so I expected result below

DB configuration...

  HOST : 127.0.0.1
  USER : testuser
  PASS : ********
  PORT : 3306
  DB   : mysql
  UNIX_SOCKET : /tmp/mysql.sock

  TESTING CONFIGURATION ... 
  [ERROR] - Mysql connect error[1045] : Access denied for user 'testuser'@'127.0.0.1' (using password: YES)


Do you want to setup database. [yes/no] :   HOST :   USER :   PASS : 
  PORT (Default: 3306) :   DB (Default: mysql) :   UNIX_SOCKET (Default: /var/lib/mysql/mysql.sock) : 

  TESTING CONFIGURATION ... 
  [OK]

Done.

+ cp -f A.txt B.txt

but I got some error when reboot

DB configuration...

  HOST : 127.0.0.1
  USER : testuser
  PASS : ********
  PORT : 3306
  DB   : mysql
  UNIX_SOCKET : /var/lib/mysql/mysql.sock

  TESTING CONFIGURATION ... 
  [OK]


Do you want to setup database. [yes/no] :   HOST :   USER : + cp -f A.txt B.txt

some content in EOF block skipped. why this problem happened? and How can i fix it?

DannyPoet
  • 23
  • 7
  • Have you tested your script outside of the init process, such as simply running it to see if the connection is made successfully? Additionally, how do you ensure you script is only run after mysql (or MariaDB) is up and running? If you are using old init-scripts, then you have the number-ordering provided by the numbers that prefix you script name. If using systemd, you need to set a condition that the service you need is already running. – David C. Rankin Oct 17 '22 at 06:11
  • @DavidC.Rankin 1) I tested script outside of init process, and it runs successfully 2) script runs only after mysql up. specific init file exists in /etc/init.d, and I just added executing my script to that file. and that file is executed only after mysql up. do you think this problem related mysql running or not? – DannyPoet Oct 17 '22 at 06:14
  • Your init script will likely be limited to POSIX shell, not bash. That said, your script seems fine. I don't see any bashisms that would cause issues. The issue I see is the init script isn't run as user "you". So the environment will be different. Additionally if you are attempting to start a connection that leaves an interactive session open, that will likely fail for the user reason. Init scripts are for starting servers (daemons). If you need to open a user-connection, why not have that done on access or from the users `.bashrc`, etc.? – David C. Rankin Oct 17 '22 at 06:28
  • @DavidC.Rankin All operations executed on user 'root', so maybe any environmental issue will be not exist. I showed limited content of script on question, but this script executed some setup opeartion, and automatically input some contents when boot. All operations should be executed on boot, so I added script execution in init script. – DannyPoet Oct 17 '22 at 06:36
  • Just remember mysql user `root` and the system user `root` have nothing to do with each other. That's just an unfortunate choice of names for the admin user that mysql chose. So the environment issue is the same. Just as you can enter `mysql -u anyone -p` at the command line in your shell, that doesn't mean it will work in an init script. Have a look at [How to run a command as a specific user in an init script?](https://stackoverflow.com/q/17956151/3422102) – David C. Rankin Oct 17 '22 at 06:43
  • Here is another good general overview [Starting Linux services with init scripts](https://www.softprayog.in/tutorials/starting-linux-services-with-init-scripts) – David C. Rankin Oct 17 '22 at 06:43
  • @DavidC.Rankin Thanks for your help. I checked some erorr in `tcgetattr` function. It seems to be related I/O streams. – DannyPoet Oct 17 '22 at 07:58

1 Answers1

1

I found why this happened.

My program (some_program in question) is made with C++, and it uses the tcgetattr function to hide the input password.

On boot, this function leads to the error below, so it looks like skipping. Actually, the problem is caused by this program.

Inappropriate ioctl for device

So it is a different problem with shell.

If someone suffered this problem, or a similar situation, check if some program or script uses tcgetattr or stream-related functions.

buddemat
  • 4,552
  • 14
  • 29
  • 49
DannyPoet
  • 23
  • 7