Linux Shell脚本实现自动交互

来源:互联网 发布:买车软件哪个好 编辑:程序博客网 时间:2024/05/22 17:34

方法一:(以OpenSSH编译完成之后的 拷贝和生成key 为例)

#!/bin/bashDIR_PATH=$HOME/sshdfilecp sshd $DIR_PATH/sbincp scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan $DIR_PATH/bincp sftp-server ssh-keysign $DIR_PATH/libexeccp sshd_config ssh_config $DIR_PATH/etcchmod 755 $DIR_PATH/var/emptyssh-keygen -t rsa1 -f ssh_host_key -N "" << EOFyEOFssh-keygen -t rsa -f ssh_host_rsa_key -N "" << EOFyEOFssh-keygen -t dsa -f ssh_host_dsa_key -N "" << EOFyEOFcp ssh_host_* $DIR_PATH/etc

方法二:(以FTP用户自动登录为例)

#!/usr/bin/expectset file [lindex $argv 0];set timeout -1;  spawn ftp 192.168.1.***  expect "Name"  send "username***\r"  expect "Password"  send "passwd***\r"expect "ftp>"send "hash\r"expect "*ftp>*"send "put $file\n"expect "*ftp>*"send "bye\r"expect "*Goodbye*"expect eofexit
【测试】:./autoftp.sh filename
【效果】:自动登陆FTP用户”username***“, 将”filename“ 文件上传至服务器。



原创粉丝点击