案例一:显示所有存储信息
# df -a
案例二:以方便人类阅读的方式显示存储信息
# df -h
案例三:显示存储的 inode 信息
# df -i
案例三:显示存储的格式
# df -T
# df -a
# df -h
# df -i
# df -T
-bash: /dev/null: Permission denied
# rm -f /dev/null;mknod /dev/null c 1 3;chmod 666 /dev/null
作者:朱明宇
名称:批量修改多个远程服务器某一个用户的密码
作用:批量修改多个远程服务器某一个用户的密码
使用方法:
1. 将此脚本和清单 $list 文件放在同一目录下
2. 清单 $list 里每服务器名占用一行
3. 给脚本分割线里的变量赋值
4. 给此脚本添加执行权限
5. 执行此脚本
脚本分割线里的变量:
1. list=”list.txt” #指定清单的目录和名称
2. user=eternalcenter #指定要修改密码的用户
3. password=eternalcenter #指定要修改的密码
注意:
此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器,并且可以通过 sudo 获得 su 的 root 权限
#!/bin/bash
####################### Separator ########################
list="list.txt"
user=eternalcenter
password=eternalcenter
####################### Separator ########################
num=1
cat $list
for i in `cat $list`
do
echo $num
echo $i
ssh -t $i "type lsb_release" &> /dev/null
if [ $? -ne 0 ]; then
distribution=`ssh -t $i "cat /etc/*release | grep '^NAME'"`
if [ $? -ne 0 ];then
distribution=`ssh -t $i "cat /etc/*release"`
fi
else
distribution=`ssh -t $i "lsb_release -i | grep 'ID' | grep -v 'n/a'"`
fi;
echo $distribution
case $distribution in
*"RedHat"* | *"Red Hat"*)
ssh -t $i "sudo -u root su - root -c \"echo $password | passwd --stdin $user\""
if [ $? -eq 0 ];then
echo -e "\033[32m$i is success\033[0m"
else
echo -e "\033[31m$i is fail\033[0m"
fi
;;
*"CentOS"*)
ssh -t $i "sudo -u root su - root -c \"echo $password | passwd --stdin $user\""
if [ $? -eq 0 ];then
echo -e "\033[32m$i is success\033[0m"
else
echo -e "\033[31m$i is fail\033[0m"
fi
;;
*"SUSE"* | *"SLES"*)
ssh -t $i "sudo -u root su - root -c \"echo $user:$password | chpasswd\""
if [ $? -eq 0 ];then
echo -e "\033[32m$i is success\033[0m"
else
echo -e "\033[31m$i is fail\033[0m"
fi
;;
*"openSUSE"*)
ssh -t $i "sudo -u root su - root -c \"echo $user:$password | chpasswd\""
if [ $? -eq 0 ];then
echo -e "\033[32m$i is success\033[0m"
else
echo -e "\033[31m$i is fail\033[0m"
fi
;;
*)
echo -e "\033[31m$i is fail \033[0m"
;;
esac
let num++
echo
done
1) -b 排序时忽略每行前面的空格
2) -c 检查是否已排序
3) -f 排序时忽略大小写字母
4) -n 按照数值到大小进行排序
5) -o 将排序结果导入到指定文件
6) -r 以相反的顺序进行排序
7) -t 指定排序的分隔符
8) -k 以指定的列进行排序
# cat test.txt
3
5
4
2
1
# sort -c test.txt
sort: test.txt:3: disorder: 4
(补充:这里以检查 test.txt 文件里的排列为例)
# cat test.txt
3
5
4
2
20
1
# sort -n test.txt
1
2
3
4
5
20
(补充:这里以排列 test.txt 文件里的列为例)
# cat test.txt
c
e
d
b
a
# sort test.txt
a
b
c
d
e
(补充:这里以排列 test.txt 文件里的列为例)
# cat test.txt
c
e
d
b
a
# sort -r test.txt
e
d
c
b
a
(补充:这里以排列 test.txt 文件里的列为例)
# cat test.txt
3 d
5 c
4 a
2 e
1 b
# sort test.txt
1 b
2 e
3 d
4 a
5 c
(补充:这里以排列 test.txt 文件里的列为例)
# cat test.txt
3 d
5 c
4 a
2 e
1 b
# sort -k2 test.txt
4 a
1 b
5 c
3 d
2 e
(补充:这里以排列 test.txt 文件里的列为例)
# cat test.txt
10.0.200.10
172.16.50.10
192.168.100.1
192.168.100.10
172.16.50.1
10.0.200.1
# sort test.txt
10.0.200.1
10.0.200.10
172.16.50.1
172.16.50.10
192.168.100.1
192.168.100.10
(补充:这里以排列 test.txt 文件里的列为例)
# cat test.txt
10.0.200.10
172.16.50.10
192.168.100.1
192.168.100.10
172.16.50.1
10.0.200.1
# sort -t'.' -k3n test.txt
172.16.50.1
172.16.50.10
192.168.100.1
192.168.100.10
10.0.200.1
10.0.200.10
(补充:这里以排列 test.txt 文件里的列为例)
<command> &> <file>
或者:
<command> >& <file>
<command> 1> <file>
或者:
<command> > <file>
<command> 2> <file>
<command> &>> <file>
或者:
<command> >>& <file>
<command> 1>> <file>
或者:
<command> >> <file>
<command> 2>> <file>
<command> 2&>1
或者:
<command> 2>&1
<command> 1&>2
或者:
<command> 1>&2
<command> &> /dev/null
或者:
<command> &>> /dev/null
或者:
<command> >& /dev/null
或者:
<command> >>& /dev/null
或者:
<command> 1> /dev/null 2>&1
或者:
<command> 1>> /dev/null 2>&1
或者:
<command> 1> /dev/null 2>>&1
或者:
<command> 1>> /dev/null 2>>&1
或者:
<command> 2> /dev/null 1>&2
或者:
<command> 2>> /dev/null 1>&2
或者:
<command> 2> /dev/null 1>>&2
或者:
<command> 2>> /dev/null 1>>&2
(补充:通过此种方法输出信息就既不会显示出来也不会被重定向到一个文件里)