SHELL脚本编程-expect
SHELL脚本编程-expect
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.expect概述
1>.expect介绍
expect 是由Don Libes基于Tcl( Tool Command Language )语言开发的,主要应用于自动化交互式操作的场景,借助Expect处理交互的命令,可以将交互过程如:ssh登录,ftp登录等写在一个脚本上,使之自动化完成。尤其适用于需要对多台服务器执行相同操作的环境中,可以大大提高系统管理人员的工作效率。
2>.expect命令
expect 语法:
expect [选项] [ -c cmds ] [ [ -[f|b] ] cmdfile ] [ args ]
常用选项
-c:从命令行执行expect脚本,默认expect是交互地执行的
示例:expect -c 'expect "\n" {send "pressed enter\n"}
-d:可以输出输出调试信息
示例:expect -d ssh.exp
expect中相关命令
spawn:
启动新的进程
send:
用于向进程发送字符串
expect:
从进程接收字符串
interact:
允许用户交互
exp_continue
匹配多个字符串在执行动作后加此命令
3>.安装expect软件包
[root@node101.yinzhengjie.org.cn ~]# yum info expect
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* epel: mirrors.aliyun.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.aliyun.com
Available Packages
Name : expect
Arch : x86_64
Version : 5.45
Release : .el7_1
Size : k
Repo : base//x86_64
Summary : A program-script interaction and testing utility
URL : http://expect.nist.gov/
License : Public Domain
Description : Expect is a tcl application for automating and testing
: interactive applications such as telnet, ftp, passwd, fsck,
: rlogin, tip, etc. Expect makes it easy for a script to
: control another program and interact with it.
:
: This package contains expect and some scripts that use it. [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# yum info expect #查看expect软件包相关信息
[root@node101.yinzhengjie.org.cn ~]# yum -y install expect
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.6 kB ::
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: ap.stykers.moe
* updates: mirrors.aliyun.com
base | 3.6 kB ::
epel | 5.3 kB ::
extras | 2.9 kB ::
updates | 2.9 kB ::
(/): epel/x86_64/updateinfo | 1.0 MB ::
(/): epel/x86_64/primary_db | 6.9 MB ::
Resolving Dependencies
--> Running transaction check
---> Package expect.x86_64 :5.45-.el7_1 will be installed
--> Processing Dependency: libtcl8..so()(64bit) for package: expect-5.45-.el7_1.x86_64
--> Running transaction check
---> Package tcl.x86_64 :8.5.-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================
Installing:
expect x86_64 5.45-.el7_1 base k
Installing for dependencies:
tcl x86_64 :8.5.-.el7 base 1.9 M Transaction Summary
============================================================================================================================================================================
Install Package (+ Dependent package) Total download size: 2.1 M
Installed size: 4.9 M
Downloading packages:
(/): expect-5.45-.el7_1.x86_64.rpm | kB ::
(/): tcl-8.5.-.el7.x86_64.rpm | 1.9 MB ::
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total kB/s | 2.1 MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : :tcl-8.5.-.el7.x86_64 /
Installing : expect-5.45-.el7_1.x86_64 /
Verifying : :tcl-8.5.-.el7.x86_64 /
Verifying : expect-5.45-.el7_1.x86_64 / Installed:
expect.x86_64 :5.45-.el7_1 Dependency Installed:
tcl.x86_64 :8.5.-.el7 Complete!
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# yum -y install expect #安装expect工具
二.expect最常用的语法(tcl语言:模式-动作)
1>.expect的单分支语法
[root@node101.yinzhengjie.org.cn ~]# expect
expect1.> expect "hi" {send "say hi\n"} #捕捉用户输入的"hi",然后给用户发送"say hi\n"
hi #这一行是我输入的,由于被我上面定义的语句捕捉到了,下面一行的输出信息就是我之前自定义的字符串信息。
say hi
expect1.> exit #如果不想使用该程序了可以输入"exit"来正常退出交互式界面
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
2>.expect的多分支语法
[root@node101.yinzhengjie.org.cn ~]# expect
expect1.> expect "hi" {send "say hi\n"}\
+> "bye" {send "byebye\n"}
bye
byebye
expect1.> exit
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# expect #匹配hi,hello,bye任意字符串时,执行相应输出。上面的写法和下面的写法功能是相同的。
expect1.> expect {
+> "hi" {send "You said hi\n"}
+> "hehe" {send "hehe yourself\n"}
+> "bye" {send "Good bye\n"}
+> }
bye
Good bye
expect1.>
expect1.> exit
[root@node101.yinzhengjie.org.cn ~]#
三.expect脚本案例实战
1>.spawn(启动新的进程)案例
[root@node101.yinzhengjie.org.cn ~]# ll .ssh/
total
-rw-------. root root Jul : authorized_keys
-rw-------. root root Jul : id_rsa
-rw-r--r--. root root Jul : id_rsa.pub
-rw-r--r--. root root Jul : known_hosts
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# rm -rf .ssh
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll /etc/issue
-rw-r--r--. root root Nov /etc/issue
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll backup/
total
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat shell/scp_expect.sh
#!/usr/bin/expect #注意,这一行需要写expect命令的执行路径
#
#********************************************************************
#Author: yinzhengjie
#QQ:
#Date: --
#FileName: shell/scp_expect.sh
#URL: http://www.cnblogs.com/yinzhengjie
#Description: The test script
#Copyright notice: original works, no reprint! Otherwise, legal liability will be investigated.
#******************************************************************** spawn scp /etc/issue root@172.30.1.101:/root/backup expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "yinzhengjie\n" }
} expect eof
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# chmod +x shell/scp_expect.sh #添加执行权限
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ./shell/scp_expect.sh #执行脚本后,我们发现无需像之前那样手动输出"yes"和密码啦~取而代之的是脚本帮咱们干活了。
spawn scp /etc/issue root@172.30.1.101:/root/backup
The authenticity of host '172.30.1.101 (172.30.1.101)' can't be established.
ECDSA key fingerprint is SHA256:KEchoZnVBkijeoWfG2nvx2ptthsXv7IjkxIJYule57g.
ECDSA key fingerprint is MD5::c8:f5:6e:5f:cf::ec:c4:::d2:d0::3c:da.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.30.1.101' (ECDSA) to the list of known hosts.
root@172.30.1.101's password:
issue % .2KB/s :
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll backup
total
-rw-r--r-- root root Nov : issue
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat shell/scp_expect.sh
2>.interact(允许用户交互)案例
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect1.sh
#!/usr/bin/expect
#
#********************************************************************
#Author: yinzhengjie
#QQ:
#Date: --
#FileName: shell/scp_expect.sh
#URL: http://www.cnblogs.com/yinzhengjie
#Description: The test script
#Copyright notice: original works, no reprint! Otherwise, legal liability will be investigated.
#******************************************************************** spawn ssh yinzhengjie@172.30.1.101 expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "yinzhengjie\n" }
} interact
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ./shell/ssh_expect1.sh
spawn ssh yinzhengjie@172.30.1.101
yinzhengjie@172.30.1.101's password:
Last login: Sat Nov :: from 172.30.1.101
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ who
yinzhengjie pts/ -- : (172.30.1.101)
root pts/ -- : (172.30.1.254)
root pts/ -- : (172.30.1.254)
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ exit
logout
Connection to 172.30.1.101 closed.
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect1.sh
3>.变量使用案例
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect2.sh
#!/usr/bin/expect
#
#********************************************************************
#Author: yinzhengjie
#QQ:
#Date: --
#FileName: shell/scp_expect.sh
#URL: http://www.cnblogs.com/yinzhengjie
#Description: The test script
#Copyright notice: original works, no reprint! Otherwise, legal liability will be investigated.
#******************************************************************** set host 172.30.1.101
set user yinzhengjie
set password yinzhengjie spawn ssh ${user}@${host} expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "${password}\n" }
} interact
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ./shell/ssh_expect2.sh
spawn ssh yinzhengjie@172.30.1.101
yinzhengjie@172.30.1.101's password:
Last login: Sat Nov :: from 172.30.1.101
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ whoami
yinzhengjie
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ exit
logout
Connection to 172.30.1.101 closed.
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect2.sh
4>.位置参数案例
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect3.sh
#!/usr/bin/expect
#
#********************************************************************
#Author: yinzhengjie
#QQ:
#Date: --
#FileName: shell/scp_expect.sh
#URL: http://www.cnblogs.com/yinzhengjie
#Description: The test script
#Copyright notice: original works, no reprint! Otherwise, legal liability will be investigated.
#******************************************************************** set host [lindex $argv ]
set user [lindex $argv ]
set password [lindex $argv ] spawn ssh ${user}@${host} expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "${password}\n" }
} interact
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ./shell/ssh_expect3.sh 172.30.1.101 yinzhengjie yinzhengjie
spawn ssh yinzhengjie@172.30.1.101
yinzhengjie@172.30.1.101's password:
Last login: Sat Nov :: from 172.30.1.101
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ whoami
yinzhengjie
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ exit
logout
Connection to 172.30.1.101 closed.
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect3.sh
5>.登录后执行多个命令案例
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect4.sh
#!/usr/bin/expect
#
#********************************************************************
#Author: yinzhengjie
#QQ:
#Date: --
#FileName: shell/scp_expect.sh
#URL: http://www.cnblogs.com/yinzhengjie
#Description: The test script
#Copyright notice: original works, no reprint! Otherwise, legal liability will be investigated.
#******************************************************************** set host [lindex $argv ]
set user [lindex $argv ]
set password [lindex $argv ]
set createuser [lindex $argv ]
set createpasswd [lindex $argv ] spawn ssh ${user}@${host} expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "${password}\n" }
} expect "]#" { send "useradd ${createuser}\n" }
expect "]#" { send "echo ${createpasswd} |passwd --stdin ${createuser}\n" }
expect "]#" { send "who\n" }
send "exit\n"
expect eof
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# who
root pts/ -- : (172.30.1.254)
root pts/ -- : (172.30.1.254)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# id jason
id: jason: no such user
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ./shell/ssh_expect4.sh 172.30.1.101 root yinzhengjie jason
spawn ssh root@172.30.1.101
root@172.30.1.101's password:
Last login: Sat Nov :: from 172.30.1.101
[root@node101.yinzhengjie.org.cn ~]# useradd jason
[root@node101.yinzhengjie.org.cn ~]# echo |passwd --stdin jason
Changing password for user jason.
passwd: all authentication tokens updated successfully.
[root@node101.yinzhengjie.org.cn ~]# who
root pts/ -- : (172.30.1.101)
root pts/ -- : (172.30.1.254)
root pts/ -- : (172.30.1.254)
[root@node101.yinzhengjie.org.cn ~]# exit
logout
Connection to 172.30.1.101 closed.
[root@node101.yinzhengjie.org.cn ~]# who
root pts/ -- : (172.30.1.254)
root pts/ -- : (172.30.1.254)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# id jason
uid=(jason) gid=(jason) groups=(jason)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect4.sh
6>.shell脚本调用expect
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect5.sh
#!/bin/bash
#
#********************************************************************
#Author: yinzhengjie
#QQ:
#Date: --
#FileName: shell/ssh_expect5.sh
#URL: http://www.cnblogs.com/yinzhengjie
#Description: The test script
#Copyright notice: original works, no reprint! Otherwise, legal liability will be investigated.
#******************************************************************** ip=$
user=$
password=$ expect <<EOF
set timeout
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
} expect "]#" { send "useradd jason2019\n" }
expect "]#" { send "echo yinzhengjie |passwd --stdin jason2019\n" }
expect "]#" { send "who\n" }
expect "]#" { send "exit\n" }
expect eof
EOF
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# who
root pts/ -- : (172.30.1.254)
root pts/ -- : (172.30.1.254)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# id jason2019
id: jason2019: no such user
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# bash shell/ssh_expect5.sh 172.30.1.101 root yinzhengjie
spawn ssh root@172.30.1.101
root@172.30.1.101's password:
Last login: Sat Nov :: from 172.30.1.101
[root@node101.yinzhengjie.org.cn ~]# useradd jason2019
[root@node101.yinzhengjie.org.cn ~]# echo yinzhengjie |passwd --stdin jason2019
Changing password for user jason2019.
passwd: all authentication tokens updated successfully.
[root@node101.yinzhengjie.org.cn ~]# who
root pts/ -- : (172.30.1.101)
root pts/ -- : (172.30.1.254)
root pts/ -- : (172.30.1.254)
[root@node101.yinzhengjie.org.cn ~]# exit
logout
Connection to 172.30.1.101 closed.
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# id jason2019
uid=(jason2019) gid=(jason2019) groups=(jason2019)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# who
root pts/ -- : (172.30.1.254)
root pts/ -- : (172.30.1.254)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect5.sh
7>.模拟给集群批量创建用户的脚本
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect6.sh
#!/bin/bash
#
#********************************************************************
#Author: yinzhengjie
#QQ:
#Date: --
#FileName: shell/ssh_expect5.sh
#URL: http://www.cnblogs.com/yinzhengjie
#Description: The test script
#Copyright notice: original works, no reprint! Otherwise, legal liability will be investigated.
#******************************************************************** while read ip ;do
user=root
password=yinzhengjie expect <<EOF
set timeout
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
} expect "]#" { send "useradd hadoop\n" }
expect "]#" { send "echo yinzhengjie |passwd --stdin hadoop\n" }
expect "]#" { send "who\n" }
expect "]#" { send "exit\n" }
expect eof
EOF
done < /root/shell/iplist.txt
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat shell/iplist.txt #咱们这里定义了需要连接集群的主机IP
172.30.1.101
172.30.1.102
172.30.1.103
172.30.1.104
172.30.1.105
172.30.1.106
172.30.1.107
172.30.1.108
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# bash shell/ssh_expect6.sh #执行脚本后发现会有很多输出信息,由于我试验的时候之开机了172.30.1.101这台虚拟机,其它虚拟机全部关机了,结果脚本只在开机的虚拟机中执行成功啦,其它主机报错提示找不到主机路由。
spawn ssh root@172.30.1.101
root@172.30.1.101's password:
Last login: Sat Nov :: from 172.30.1.101
[root@node101.yinzhengjie.org.cn ~]# useradd hadoop
[root@node101.yinzhengjie.org.cn ~]# echo yinzhengjie |passwd --stdin hadoop
Changing password for user hadoop.
passwd: all authentication tokens updated successfully.
[root@node101.yinzhengjie.org.cn ~]# who
root pts/ -- : (172.30.1.101)
root pts/ -- : (172.30.1.254)
root pts/ -- : (172.30.1.254)
[root@node101.yinzhengjie.org.cn ~]# exit
logout
Connection to 172.30.1.101 closed.
spawn ssh root@172.30.1.102
ssh: connect to host 172.30.1.102 port : No route to host
expect: spawn id exp6 not open
while executing
"expect "]#" { send "useradd hadoop\n" }"
spawn ssh root@172.30.1.103
ssh: connect to host 172.30.1.103 port : No route to host
expect: spawn id exp6 not open
while executing
"expect "]#" { send "useradd hadoop\n" }"
spawn ssh root@172.30.1.104
ssh: connect to host 172.30.1.104 port : No route to host
expect: spawn id exp6 not open
while executing
"expect "]#" { send "useradd hadoop\n" }"
spawn ssh root@172.30.1.105
ssh: connect to host 172.30.1.105 port : No route to host
expect: spawn id exp6 not open
while executing
"expect "]#" { send "useradd hadoop\n" }"
spawn ssh root@172.30.1.106
ssh: connect to host 172.30.1.106 port : No route to host
expect: spawn id exp6 not open
while executing
"expect "]#" { send "useradd hadoop\n" }"
spawn ssh root@172.30.1.107
ssh: connect to host 172.30.1.107 port : No route to host
expect: spawn id exp6 not open
while executing
"expect "]#" { send "useradd hadoop\n" }"
spawn ssh root@172.30.1.108
ssh: connect to host 172.30.1.108 port : No route to host
expect: spawn id exp6 not open
while executing
"expect "]#" { send "useradd hadoop\n" }"
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# id hadoop #很显然,只有172.30.1.101主机命令执行成功了。
uid=(hadoop) gid=(hadoop) groups=(hadoop)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat shell/ssh_expect6.sh
SHELL脚本编程-expect的更多相关文章
- 【Shell脚本编程系列】知识储备以及建立规范的脚本
前言 学习shell脚本编程需要的知识储备: vi/vim编辑器命令 vimrc设置要熟练 基础命令,100多个要熟练 基础和常用的网络服务命令要会:nfs . rsync. inotify . la ...
- SHELL脚本编程基础知识
SHELL脚本编程基础知识 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. Linux之父Linus有一句话很经典:"Talk is cheap, show me the ...
- shell脚本编程基础介绍
Linux系统——shell脚本编程基础介绍 1.什么是shell 它是一个命令解释器,在linux/unix操作系统的最外层,负责直接与用户对话,把用户的输入解释给操作系统,并处理各种操作输出的结果 ...
- Shell脚本编程30分钟入门
Shell脚本编程30分钟入门 转载地址: Shell脚本编程30分钟入门 什么是Shell脚本 示例 看个例子吧: #!/bin/sh cd ~ mkdir shell_tut cd shell_t ...
- Linux shell脚本编程(三)
Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真” ...
- Linux shell脚本编程(二)
Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...
- Linux shell脚本编程(一)
Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...
- CentOS 下运维自动化 Shell 脚本之 expect
CentOS 下运维自动化 Shell脚本之expect 一.预备知识: 1.在 Terminal 中反斜杠,即 "" 代表转义符,或称逃脱符.("echo -e与pri ...
- Linux shell脚本编程基础之练习篇
shell脚本编程基础之练习篇. 1.编写一个脚本使我们在写一个脚本时自动生成”#!/bin/bash”这一行和注释信息. #!/bin/bash ] then echo "请输入一个参数& ...
随机推荐
- 【翻译】Flink Table Api & SQL — Hive —— 在 scala shell 中使用 Hive 连接器
本文翻译自官网:Use Hive connector in scala shell https://ci.apache.org/projects/flink/flink-docs-release-1 ...
- 数学黑洞:卡普雷卡尔常数的php算法实现
首先看一篇文章: 英国广播公司报道,6174乍看没什么奇特之处,但是,自从1949年以来,它一直令数学家.数字控抓狂.痴迷. 不管你挑的四位数是什么,早早晚晚你都会遇到6174:而且,遇到6174就只 ...
- windows mysql手动添加my.ini 服务启动不了
[mysqld] character-set-server=utf8 #绑定IPv4和3306端口 bind-address=0.0.0.0 port= default_storage_engine= ...
- mybatis批量新增或更新
mysql中在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE时,向数据库中插入一条记录: 若插入数据的主键值/ UNIQUE KEY 已经在表中存在,则执行更新操作(UPDA ...
- 各手机PC品牌投屏功能连接方法
一.iOS终端(iPhone/iPad)无线投屏: 1.将iPhone或iPad与必捷会议盒子连接至同一路由器: 2.滑动iPhone/iPad的屏幕,调出Airplay功能,选择需要投屏的主机,开始 ...
- 【springcloud】【idea】启动服务报错Command line is too long. Shorten command line for XXXApplication or also for Spring Boot default configuration.
在workspace.xml 在标签<component name="PropertiesComponent">里 添加<property name=" ...
- HMAC哈希消息认证码
收藏 137 14 hmac 编辑 HMAC是密钥相关的哈希运算消息认证码,HMAC运算利用哈希算法,以一个密钥和一个消息为输入,生成一个消息摘要作为输出. 中文名 哈希消息认证码 外文名 H ...
- 005 SpringCloud 学习笔记01-----系统架构的演变
1.系统架构的演变 随着互联网的发展,网站应用的规模不断扩大.需求的激增,带来的是技术上的压力.系统架构也因此不断的演进.升级.迭代.从单一应用,到垂直拆分,到分布式服务,到SOA,以及现在火热的微服 ...
- python 之 面向对象(元类、__call__、单例模式)
7.13 元类 元类:类的类就是元类,我们用class定义的类来产生我们自己的对象的,内置元类type是用来专门产生class定义的类 code=""" global x ...
- SQLite接口函数 - C核心api实践与总结
SQLite核心源代码由C语言写就,同时提供了很多的扩展包可应用于其他编程语言和类库,如Python.Ruby.Java.Perl..Net/C#.Qt和ODBC.在很多情况下,针对一种语言有很多扩展 ...