No /etc/init. d, mount it as follows
#!/bin/bash ou #!/bin/sh como achar melhor
### BEGIN INIT INFO
# Provides: (nome que vc deseja dar ao script)
# Required-Start: $exemplo1 $exemplo3 $exemplo3 (aqui vc coloca quais serviços devem estar em execução antes do seu script ser rodado ou pode colocar $all para todos)
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: breve descrição
# Description: Descrição completa
### END INIT INFO
#comando a ser executado
mysql -u usuario -psenha -Bse "USE intranet;set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';"
Be careful when using double quotes, if you have any special character, it will be interpreted, before any special character put (backslash) to escape.
Make the file executable
chmod +x /etc/init. d/seu_script
Put on startup
update-rc. d seu_script defaults
update-rc. d seu_script enable
if you are interested in taking a look at http://www.debian.org/doc/debian-policy/#Contents
Using rc.local as follows
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#Comando a ser executado
mysql -u usuario -psenha -Bse "USE intranet;set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';"
exit 0
Make sure he has permission to execute,
checks whether rc.local is on system startup if it is not using the following command
update-rc.d rc.local defaults
update-rc.d rc.local enable
Using the cron
Create a file in /etc/cron. d/meu_cron and edit it as follows
*/1 * * * * root mysql -u usuario -psenha -Bse "USE intranet;set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';"
Make sure that cron is running on system boot if you are not running it with the command
update-rc.d <serviço> <ação>
see more in https://linux.die.net/man/5/crontab
-rwxr-Xr-x 1 root root 305 Sep 22 17:28 /etc/rc.local e #! /bin/sh -e
– Julyano Felipe
Placing the command inside a sh (with execution permission) and placing this sh in rc.local works?
– raphaelsalomao3
I created the sh file with execution permission (chmod +x) and ran it, it worked correctly (with Warning, just like when running from the command line)
– Julyano Felipe
If I create that same file in the /etc/init. d/ folder with these permissions, it doesn’t seem to run.. but if I run it manually, it works
– Julyano Felipe
Did you try to put on rc.local?
bash /caminho/script.sh
– raphaelsalomao3
Yes, I put in the rc.local also as said in the question and continued not executing..
– Julyano Felipe