Use expect command to interact with mysql in linux system
2013-12-02 10:43
477 查看
The "expect" command is not install in some linux system default , in the ubuntu system , you can simplly tap "sudo apt-get install expect" to install this tool.
And then , if you want to use to in the shell script , the first line maybe like this:
It just like bash or sh . check the example below:
And then , if you want to use to in the shell script , the first line maybe like this:
#!/use/bin/expect
It just like bash or sh . check the example below:
$:~/test$ expect expect1.1> spawn mysql -h localhost -u db_runner -p spawn mysql -h localhost -u db_runner -p 27022 expect1.2> expect "password:" Enter password: expect1.3> send "mysqlpassword\r" expect1.4> expect "mysql>" Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 88 Server version: 5.5.34-0ubuntu0.13.04.1 (Ubuntu) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> expect1.5> send "show databases;\r" expect1.6> expect "mysql>" show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 9 rows in set (0.00 sec) mysql> expect1.7> send "exit;\r" expect1.8> expect "mysql>" exit; Bye
相关文章推荐
- use AT command to send a sms in linux system
- How To Use Ip Command In Linux with Examples
- How to create aligned partitions in Linux for use with NetApp LUNs, VMDKs, VHDs and other virtual di
- How to use a 32bit Oracle11_g client in 64 win system and not conflict with sqldeveloper 64 bit tool
- How to Use `strace` to Trace the System Call in Linux
- How to Use Linux Commands in Windows with Cygwin
- How to Mount and Unmount Filesystem / Partition in Linux (Mount/Umount Command Examples)
- [Yii Framework] How to run cron job (or use command) in the server with yii framework
- HowTo: Use grep Command In Linux / UNIX [ Examples ]
- Add a system call to the linux kernel in Ubuntu
- 错误 clang: error: linker command failed with exit code 1 (use -v to see invocation)
- Linux - fsck命令修复文件系统 | Using command fsck to repair file system
- iOS开发 ☞ linker command failed with exit code 1 (use -v to see invocation)
- clang: error: linker command failed with exit code 1 (use -v to see invocation) coreData
- linker command failed with exit code 1 (use -v to see invocation)
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
- IOS-59-解决错误:linker command failed with exit code 1 (use -v to see invocation)
- 模拟器运行正常,真机报错:clang: error: linker command failed with exit code 1 (use -v to see invocation)
- 添加第三方类库造成的linker command failed with exit code 1 (use -v to see invocation)的错误调试
- error: linker command failed with exit code 1 (use -v to see invocation) 报错的原因