码迷,mamicode.com
首页 > 其他好文 > 详细

shell之脚本实例

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

标签:get   os   line   for   file   ui   

一 检查用户是否是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之脚本实例

标签:get   os   line   for   file   ui   

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

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