显示linux开机时间的脚本-创新互联

最初的讨论是linux吧吧友@九十钩圈凯_ 发布的主题贴《加到自启动可以看开机时间的玩意》 并给出显示开机秒数的shell语句 [shell] [ $_UTED = 0 ] || notify-send -i clock "$(cat /proc/uptime|sed 's/ .*//'|xargs echo -e '本次开机时间:n')秒" && export _UTED=0 [/shell] 而后由@realasking改进,修改为显示分钟和秒数,更贴心,不过很少见到开机时间大于60s的说 (咳咳...我只是为了截个图...请忽视上面的数字吧) [shell] [ $_UTED = 0 ] ||ttime=`cat /proc/uptime|cut -f1 -d"."|xargs`&&let min=ttime/60&&let sec=ttime%60&&if [ $min -gt 0 ]; then outpara=" $min 分 $sec 秒";else outpara=" $sec 秒";fi&¬ify-send -i clock "本次开机时间:$(echo "$outpara")"&& export _UTED=0 [/shell]
而后大狮兄(@realasking)写了个KDE环境下的脚本,有更多的显示功能 主题贴地址:《我也发个开机看时间的脚本》 (由于博主正在EOS单奔,暂未测试) [shell] #!/bin/bash #systemd 开机时间测试和显示脚本 #编写:realasking #根据百度贴吧 九十钩圈凯_ 的看开机时间的脚本改进扩展得到 #他的原帖位置是:http://tieba.baidu.com/p/1959641775 outputtime(){ t_tmp=`echo $stmp`&&let tmin=t_tmp/60&&let tsec=t_tmp%60 if [ $tmin -gt 0 ] then outpara="$tmin 分 $tsec 秒" else outpara="$t_tmp 秒" fi } outDS(){ DSession=`echo ${DESKTOP_SESSION}` if [ $DSession == "kde-plasma" ] then dtmp=`kded4 -v|tail -n +2|head -n +1|cut -d":" -f2` DSession=$DSession" 运行版本:"$dtmp fi } if [ -z $_UTED ] then stall=`cat /proc/uptime|cut -f1 -d"."` stmp=`echo $stall` outputtime outtpara=$outpara stt_tmp=`systemd-analyze |cut -d" " -f13|cut -d"m" -f1` stt=`echo "$stt_tmp / 1000"|bc` stmp=`echo $stt` outputtime outspara=$outpara stdesk=`echo "$stall - ${stt}"|bc` stmp=`echo $stdesk` outputtime outdpara=$outpara outDS notify-send "欢迎${LOGNAME}登录" "开机时间: ${outspara} 进入桌面时间: ${outdpara} 启动总耗时: ${outtpara} 桌面: ${DSession}" fi export _UTED=0 [/shell] 而后,故事还没有结束,在L吧的重基佬异口同声的“不显示击败了多少人,太垃圾了”的大环境下 吧友@qpalz2 发主题贴《开机看时间 + 显示击败了多少人 的脚本》 实现了联网的功能,并把这个小项目放到了Github 并且为Archlinux制作了安装包,如感兴趣,自己去下载测试吧。 其实,我本想把这篇有趣的记录起名为《一个简单的脚本引发的血案》,我会乱说?
网站名称:显示linux开机时间的脚本-创新互联
地址分享:http://myzitong.com/article/djopjs.html