shell脚本

检测是否为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 ] && ...
posted @ 2019-10-09 18:06  kylingx  阅读(129)  评论(0编辑  收藏  举报