免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1134 | 回复: 1

[系统管理] bash修改 [复制链接]

论坛徽章:
0
发表于 2015-08-11 17:13 |显示全部楼层
题目:

Write a script that upon invocation shows the time and date, lists all logged-in users, and gives the
system uptime. The script then saves this information to a logfile.


以下是我写的。
#!/bin/bash
#Program:
#         Program will show the date, time, current logged-in users and system uptime.
#+The save these information to a logfile.


cat /dev/null > /tmp/logit.log

echo -e "\nDate:`date +%F`" 2>> /tmp/logit.log

echo -e "Time: `date +%r`\n" 2>> /tmp/logit.log

echo -e "***********************Logged-in users************************************* \n" 2>> /tmp/logit.log
w 2>> /tmp/logit.log
echo -e "\n************************************************************************* \n" 2>> /tmp/logit.log


echo -e "How long the system has been running?\n" 2>> /tmp/logit.log

uptime 2>> /tmp/logit.log

echo -e "\n"

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
发表于 2015-08-11 18:45 |显示全部楼层
本帖最后由 MMMIX 于 2015-08-11 18:52 编辑

回复 1# cloudliu13


    可以参考如下脚本进行 I/O 重定向:

  1. #!/usr/bin/bash

  2. exec > >(tee /tmp/log.txt) 2>&1

  3. date
  4. w
  5. uptime
复制代码
来自 http://stackoverflow.com/questio ... -bash-script-itself
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP