在修改用户密码时,通常都需要输入两次密码以进行确认,这在编写自动化脚本时将成为一个非常致命的缺陷。通过把管道符和passwd命令的–stdin参数相结合,可以用一条命令来完成密码重置操作:
[root@linuxprobe ~]# echo “linuxprobe” | passwd --stdin root
Changing password for user root.
passwd: all authentication tokens updated successfully.
如果需要将管道符处理后的结果既输出到屏幕,又同时写入到文件中,则可以与tee命令结合使用。
下述命令将显示系统中所有与bash相关的进程信息,并同时将输出到屏幕和文件中:
[root@linuxprobe ~]# ps aux | grep bash | tee result.txt
root 1070 0.0 0.1 25384 2324 ? S Sep21 0:00 /bin/bash /usr/sbin/ksmtuned
root 3899 0.0 0.2 26540 5136 pts/0 Ss 00:27 0:00 bash
root 4320 0.0 0.0 12112 1112 pts/0 S+ 00:51 0:00 grep --color=auto bash
[root@linuxprobe ~]# cat result.txt
root 1070 0.0 0.1 25384 2324 ? S Sep21 0:00 /bin/bash /usr/sbin/ksmtuned
root 3899 0.0 0.2 26540 5136 pts/0 Ss 00:27 0:00 bash
root 4320 0.0 0.0 12112 1112 pts/0 S+ 00:51 0:00 grep --color=auto bash
评论区