这次摘录一个Mac大侠编写的脚本,这个脚本在7pm后,在没有用户使用时试图关机,如果有用户登陆则试图进入休眠模式. 管理员可以在StartupItem中加入,使之运行. 使网络环境更绿色
.
如下:
#!/bin/sh
# Sleep or shutdown script
# tryin' to be 'green'.....
# look for exception file
if [ -f "/var/db/.dontSleep" ]; then
exit 0
fi
# if we're a laptop, exit.
# No shutting down laptops (or waking them up unbidden!)
IS_LAPTOP=`/usr/sbin/system_profiler SPHardwareDataType | grep "Model" | grep "Book"`
if [ "$IS_LAPTOP" != "" ]; then
exit 0
fi
# check the time; exit if it's between 5 am and 7 pm
current_hour=`/bin/date +%H`
if [ $current_hour -gt 5 -a $current_hour -lt 19 ]; then
exit 0
fi
# now check idle time;
# exit if we've been idle less than 20 minutes
idleTime=`ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=int((pop @F)/1000000000); print $idle,"/n"; last}'`
if [ $idleTime -lt 1200 ]; then
exit 0
fi
# tell Power Manager to wake us up or turn us on at 6am M-F
pmset repeat wakeorpoweron MTWRF 06:00:00
# check to see if a user's logged into the console
login_status=`/usr/bin/who | /usr/bin/awk '{ print $2 }'`
for i in $login_status; do
if [ $i = "console" ]; then
# someone's logged in, sleep
osascript -e 'tell application "System Events" to sleep'
exit 0
fi
done
# if we got this far, it's OK to shut down.
/sbin/shutdown -h now
exit 0
分享到:
相关推荐
bash-scripts-Carlos-Martinez1552:bash-scripts-Carlos-Martinez1552由GitHub Classroom创建
NULL 博文链接:https://myeyeofjava.iteye.com/blog/1898291
GotGet Common-Bash-实用程序 Install: mkdir -pv ~/ggcom/ git clone https://github.com/LTGIV/ggcom-bash-library.git ~/ggcom/ggcom-bash-library/ git clone https://github.com/LTGIV/ggcom-bash-utils.git ...
signal-cli.bash:两个Bash脚本使signal-cli便于交互使用
检测方法 执行如下命令查看设备是否存在bash安全漏洞。 #env -i X='() { (a)=>\\' bash -c '/dev/stdout echo vulnerable' 2>/dev/null 判定依据 如果以上命令的输出为以下内容则不合规: vulnerable
简单的Bash脚本到Windows批处理文件转换器将bash脚本( *.sh )转换为Windows批处理文件( *.bat )。 这不应该是一个完全完整/正确的工具,而是转换脚本时的起点。 对于简单的脚本,这可能会创建正确的结果。 在线...
主要介绍了Shell脚本bash: ./t.sh:/bin/bash^M:损坏的解释器: 没有那个文件或目录,需要的朋友可以参考下
每个相应版本对应bash rpm两个一个64位一个32位 官网下载 可以对照MD5 软件列表: bash-3.0-27.el4.i386.rpm bash-3.0-27.el4.x86_64.rpm bash-3.2-33.el5_11.4.i386.rpm bash-3.2-33.el5_11.4.x86_64.rpm bash-...
简单的Bash脚本的集合。 入门 :获取简单的输出 :在脚本中执行多个命令 :一个简单但非常互动的脚本 :用点(。)绘制菱形图案 :使用while循环从文件读取行 :显示系统信息菜单 :系统信息的重复菜单 :...
我们一定会写一个shell脚本去每一个节点上去jps,查看每个节点的进程情况。 原先以为shell很简单: #!/bin/bash #查看每个节点运行情况 for((host=101;host<108;host++));do echo -----------hadoop$host--------...
高级Bash脚本编程指南 操作系统 - Linux - 高级Bash脚本编程指南.zip
node bash2pwsh.js .\You - can - test-with - this - bash - script\.bash_profile bash_profile.ps1 .bash_profile [之前] # # Util function pipe() { local outfile= ~ /pipe.md $@ >& $outfile code $...
aws身份验证secgroup脚本 使用(支持 ) -method :“ http_method” -credentials :“ aws_account_id:aws_access_key” -url :使用模块 Api网关上部署的“ /连接” URL 样品用法 bash invoke_it.sh \ -...
适用于OS X 10.9和10.10的bash-3.2 注意:该软件不适用于10.11,除非禁用。 适用于OS X的 。 当前版本:3.2.57 ...1-OCT-2015:OS X 10.11 El Capitan的/bin/bash是bash-3.2.57(1)。 2014年10月18日:
对于所有脚本,在运行它们之前,请确保已通过运行以下sudo chmod +x script_name添加了执行权限: sudo chmod +x script_name 列出监听端口的udp和tcp协议脚本的进程 获取端口号,然后过滤所有tcp和udp侦听进程并列...
Bash脚本实用程序 一些在日常工作中使用的有用的bash脚本。 这些脚本遵循《 ,在某些情况下略有不同。 在所有情况下,您都可以设置-h或--help选项以查看简要说明和用法 简短的介绍 ifacelogs:获取文件并返回与配置...
用于可读性CLI的Bash Shell脚本模板 特征 bash-cli-template允许您编写可读性CLI脚本 bash-cli-template为必需和可选命令参数提供内置验证 bash-cli-template通过内置的可读性CLI流程简化了脚本用户可以理解命令用法...
介绍该存储库提供了一个简单的 Bash 命令行程序 ( zamzar.sh ),用于使用基于 REST 的 。 它已经在 OSX 上进行了测试,但也应该与 cygwin(在 Windows 上)和 Linux 一起使用,因为它使用标准的 Bash 约定。 您需要...
通过bash/shell生成jwt的脚本
2、rhel 4.x 64位 bash-3.0-27.el4.x86_64.rpm bash-debuginfo-3.0-27.el4.4.x86_64.rpm 3、centos5.x_32 bash-3.2-33.el5.1.i386.rpm bash-3.2-33.el5_11.4.i386.rpm 4、centos5.x_64 bash-3.2-33.el5.1.x86_64.rpm...