Develop a scheduled task today and add it to the cron list. However, a problem arises before & amp; 30524;. During script execution, enter the database password: mysql-uroot-p & lt; SQLusedb; setnamesutf8; 'tasksql' after running the above code
Develop a scheduled task today and add it to the cron list. However, there is a problem. you need to enter the database password during script execution:
Mysql-u root-p <SQLuse db; set names utf8; 'Cat task. SQL 'SQL
After running the above code, a message is displayed:
Enter password:
After searching, we found that Ct can help us complete this task:
Save the above code to a file: db. sh and write the following code:
#! /Usr/bin/login CT-fspawn db. shexpect "Enter password:" send -- "password \ n" interact
Then, we will enter the database interaction interface.
The first line indicates the program to run the script;
The second line focuses on starting a program we want to execute under objective Ct;
The third line is also the focus. we need to tell secondary CT to help us complete interaction when information appears;
The fourth line is the content to be sent when the password is prompted;
The fifth line means to maintain interaction and do not exit. If this statement is not provided, the script will exit immediately after successfully logging on to the database.