linux 怎么运行shell文件输入密码
这问题太广泛了。
想到其中一种可能,下面答案来自Linux命令大全 网站终端输入密码时候,不让密码显示出来的例子。
方法1:#!/bin/bashread -p "输入密码:" -s pwdechoecho password read, is "$pwd"方法2:#!/bin/bashstty -echoread -p "输入密码:" pwdstty echoechoecho 输入完毕。
shell脚本内,如何隐藏掉密码输入
#/bin/bashlet i=0let j=0while truedoread -p '请输入用户名:' namername=`cat /autorun/script/passwd.conf |grep '\'`rname=${rname:=0}if [ "$rname" = "0" ];thenecho "输入的账号不存在!"let i=i+1if [ "$i" = "3" ];thenecho "账号已输入三次!"breakfielselet i=0while truedoread -p '请输入密码:' pass rpass=`cat /autorun/script/passwd.conf |grep '\'|awk '{print $2}'`if [ "$pass" = "$rpass" ];thenecho "登陆成功!"let i=0breakelseecho "密码输入错误"let j=j+1if [ "$j" = "3" ];thenecho "密码已输入三次!"breakfifidonebreakfidone
shell 脚本中 怎么自动填写数据
自动交互方法一:利用命令的自带参数,将标准输入作为手动输入的内容 自动交互最关键的就是交互信息的自动输入,首先联想到文件重定向,在shell编程中有这样一种用法(参考Linux与UNIX SHELL编程指南 chapt 5.7):"command 重定向操作符command 对于需求1 要求的自动登陆ftp,并作系列操作,则可以用这种方法进行自动交互。
代码如下:[yjwan@test ~]$ ftp -i -n 192.168.21.46 user dbftp dbftp101 ls EOF 下面是得到的结果:Connected to 192.168.21.46.220 developerjail FTP server (Version 6.00LS) ready.331 Password required for dbftp.230 User dbftp logged in.Remote system type is UNIX.Using binary mode to transfer files.229 Entering Extended Passive Mode (|||54281|)150 Opening ASCII mode data connection for '/bin/ls'.total 8847424-rw-r--r-- 1 dbftp www 9055318991 Aug 28 14:28 ewiz90.sql_2010-08-29226 Transfer complete.221 Goodbye.测试可以发现,如上代码使用帐号名dbftp,密码dbftp101成功登陆了ftp服务器,并进入目录,ls出当前目录的文件。
注意事项:1 这里一定要加-i ,否则必定失败!!这里ftp用的-I 参数 结束了交互式输入,因此可以用文本的方式自动地输入用户密码以及操作方式 如果不用-I 参数,那么必定要求你手动输入密码的!!那么就达不到自动登陆的要求了 你可以man ftp找到这个参数-i 关闭多文件传送中的交互式提示。
请参考 prompt、mget、mput 和 mdelete 子命令,以取得多文件传送中的提示的描述。
-n 防止在起始连接中的自动登录。
否则, ftp 命令会搜索 $HOME/.netrc 登录项,该登录项描述了远程主机的登录和初始化过程。
请参考 user 子命令。
2 举一反三:只要是要求输入密码的命令,一般都带有一个参数,允许你从标准输入,输入用户密码,以及操作。
其他常用的自动登陆命令的参数1) Passwd命令 Linux下 Passwd有参数--stdin This option is used to indicate that passwd should read the new password from standard input, which can be a pipe.所以linux下自动改变用户密码的办法就是 Echo 密码 |passwd –stdin 用户名 Freebsd没有以上参数 注意 他的方法是echo passwd |pw mod user username -h 02)smbpasswd-s This option causes smbpasswd to be silent (i.e. not issue prompts) and to read its old and new passwords from standard input, rather than from /dev/tty (like the passwd(1) program does). This option is to aid people writing scripts to drive smbpasswd3)sudo 在shell脚本中需要用root用的来执行指令:sudo 自动输入密码 echo "password" | sudo -S netstat -tlnp-S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.3 标准输入还可以用以下两种写法:可以将下面的内容写入到一个文本 然后ftp -I –n ip 或者echo “..” |ftp –I –n ip 都是可以的!因为他们都满足“有一个标准的输入”这个条件4 ssh的自动登陆没有这样的自动输入密码的参数 一般都是使用公钥/私钥的方式自动登录 这种文章满街都是,网上google一下ssh自动登陆就可以找到答案。
或者用下面的办法。
自动交互方法2:利用expect脚本自动登陆 这个 expect基本属于一种编程了 基本任何需要交互式登陆的场合,他都可以解决,是相当的牛逼。
只要是第一种办法解决不了的,基本都可以用这种办法。
转载请注明出处51数据库 » shell read password