文件归档
exec < $config_file #重定向输入
read FILE_NAME
while [ $? -eq 0 ]
do
xxx
read FILE_NAME
done
tar -czf test.tar $file_list 2 > dev/null
管理用户账户
ps -u $USER_NAME > /dev/null
command1="ps -u $user_name --no-heading"
command3="xargs -d \\n /usr/bin/sudo /bin/kill -9"
$command1 |gawk '{print $1}' | $command3
检测磁盘空间
du -S $DIR 2>/dev/null |
sort -rn|
sed '{11,$D; =}' | # 前十个
sed 'N; s/\n/ /' | # 与行号行合并
gawk '{printf $1 ":" "\t" $2}'
数据库中使用脚本
MYSQL=$(which mysql)
$MYSQL mytest -u test << EOF
show tables;
select * from table where salary > 4000;
EOF
发送消息
mesg # 显示消息是否可用
who
who -T # + 可用 - 不可用
write tra2 pst/0 # 向虚拟终端发送消息
hello world