码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本

时间:2019-10-09 19:42:23      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:star   shell   计算   val   comm   %s   script   second   The   

检测是否为root用户

# if test $UID -ne 0 ; then
if [ $UID -ne 0 ];then
echo "Non root user.Please run as root."
else
echo "Root user"
fi

计算命令花费时间

start=$(date +%s)
commands;
statements;
end=$(date +%s)
difference=$(( end - start ))
echo "Time taken to execute is $difference seconds."

time CommandOrScriptName 更好的方式

判断命令是否成功运行

eval $@
if [ $? -eq 0 ] ; then
echo "$CMD excuted successfully"
else
echo "$CMD excuted unsuccessfully"
fi
# [ $? -eq 0 ] && ...

shell脚本

标签:star   shell   计算   val   comm   %s   script   second   The   

原文地址:https://www.cnblogs.com/kylingx/p/11643423.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!