首页 > 其他 > 详细

shell之脚本实例

时间:2014-06-10 14:59:27      阅读:356      评论:0      收藏:0      [点我收藏+]

一 检查用户是否是root权限的方式:
#!/bin/bash
ROOT_UID=0 # Root has $UID 0.
E_WRONG_USER=65 # Not root?

E_NOSUCHUSER=70
SUCCESS=0

if [ "$UID" -ne "$ROOT_UID" ]
then
echo
echo "Only root can run this script."
echo
exit $E_WRONG_USER
else
echo
echo "You should know better than to run this script, root."
echo "Even root users get the blues... "
echo

#!/bin/bash
LOG_DIR=/var/log
ROOT_UID=0 # Only users with $UID 0 have root privileges.
LINES=50 # Default number of lines saved.
E_XCD=66 # Can‘t change directory?
E_NOTROOT=67 # Non-root exit error.

cd $LOG_DIR

if [ `pwd` != "$LOG_DIR" ] # or if [ "$PWD" != "$LOG_DIR" ]
# Not in /var/log?
then
echo "Can‘t change to $LOG_DIR."
exit $E_XCD
fi # Doublecheck if in right directory, before messing with log file.

shell之脚本实例,布布扣,bubuko.com

shell之脚本实例

原文:http://www.cnblogs.com/createyuan/p/3778241.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!