使用密钥文件.       这里假设主机A(192.168.100.3)用来获到主机B(192.168.100.4)的文件.   在主机A上执行如下命令来生成配对密钥: ssh-keygen -t rsa   遇到提示回车默认即可,公钥被存到用户目录下.ssh目录,比如root存放在:   /root/.ssh/id_rsa.pub   将 .ssh 目录中的 id_rsa.pub 文件复制到 主机B 的 ~/.ssh/ 目录中,并改名为 authorized_keys, 到主机A中执行命令和主…
一个shell脚本文件中有一个source命令,使用bash a.sh命令执行后source命令进行验证没有生效. 这是因为在shell脚本中执行source会看到效果,但是shell脚本执行完后再次验证就没看到效果. 此时可以换这种方式执行shell脚本命令:source a.sh…
1.mysql 数据库表信息 2.shell脚本(a.sh)信息 #!/bin/sh mysql -u root << myInsert insert into test.t values(); myInsert 3.执行 ./a.sh 4. 执行结果…
先贴代码: DATE=`date -d -1hour +%T` fileName=erver_`date -d now +%Y-%m-%d-%H%M%S`.txt cp /home/BLload_bak/$fileName HOST='ipxxx.xxx.xxx.xxx' PORT=' USER='xx' PASSWD='xx' FILE=$fileName # 注意Here Document中引用的变量必须大写 /usr/bin/ftp -i -n $HOST $PORT <<EOF use…
最近遇到一个问题, 执行脚本,脚本调用 一个命令,命令(deamon)是一个守护进程,为了调试,取消了守护进程模式.导致命令后边的其他命令(echo "456")都无法执行. deamon -d 是以守护进程模式启动:deamon -x 是以非守护进程模式启动(监控进程,死循环),stdout和stderr 关联到 控制终端. 脚本是 a.sh #!/bin/sh echo “123“ /usr/local/bin/deamon -d & >/dev/null 2>…
在项目外面写入push.sh 内容为 if [  $1!='' ] then    msg=$1; else    msg='bug'; fi   git add .  git commit -m $msg git pull origin dev git push origin dev git checkout test git pull origin test git merge dev git push origin test git checkout prod git pull origi…
1.mysql -hhostname -uuser -ppsword -e "mysql_cmd" 2. mysql -hhostname -uuser -ppsword << EOF    mysql_cmdEOF 如下简单例子: #!/bin/bashmysql -hservicedb-online -uroot -proot123 -e "use test;select * from tests;"  #方法1实例mysql -hservicedb…
如何在Python脚本中调用外部命令(就像在linux shell或Windows命令提示符下输入一样) python标准库中的subprocess可以解决这个问题. from subprocess import call call(["ls", "-l"]) subprocess比system的优势在于它更灵活(您可以获得stdout,stderr,“真实”状态代码,更好的错误处理等). 在官方文档中也建议用subprocess替代使用os.system模块. 作…
1.安装expect expect用于shell脚本中自动交互,其是基于tcl编程语言的工具.所以安装expect首先安装tcl.本文中使用的是expect5.45和tcl8.6.6. 安装tcl [root@tseg0 /]$ mkdir /tools [root@tseg0 /]$ tar -zxvf tcl8.6.6-src.tar.gz [root@tseg0 /]$ cd tcl8.6.6/unix/ [root@tseg0 /]$ ./configure [root@tseg0 /]…
在脚本中使用sudo命令,将密码保存在脚本中,不需要手动输入密码. #!/bin/bash echo 'xxx密码xxx'|sudo -S service mysql start echo 'xxx密码xxx'|sudo -S reboot…