sudo su

时间:2015-06-30 15:16:42

标签: linux shell

我正在写一个脚本来修复一个失踪的' F'邮件日志文件中的字母。邮件日志文件不断更新。我得到了一个文件名,之后我正在做一个sudo su'获得超级用户访问权限。在sudo内部,我正在修复一个失踪的' F'。但是,我无法在sudo块中使用该文件名。请问任何人都可以帮助我如何在sudo中导出这些shell变量?我尝试使用导出,但它无法正常工作。我创建的代码块如下 -

    #Script to solve F issue
#----------------------------------------
#By Kapil Shirsath
#----------------------------------------

cd /var/spool/mail        #mail files reside in mail folder
echo "Entered in mail folder"

filename=`ls -lrt  99999*| sort -k 5 -rn | head -1 | tr -s " " "," | cut -d "," -f "8"`    # this will list the file with maximum size`

echo "File with maximum size is  $filename"
echo "----------------------------------------------------"
echo "Is it the file expected?(y/n)"
read choice
if test $choice == "n"
then
    echo "Exiting...."
    exit;
fi;

c=1
while [ $c -le 5 ]
do
    ls -lrt $filename
    echo $filename
    sleep 3
    c=`expr $c + 1`
done
echo "---------------------------------------------------"

sudo su<<'HERE'   #this will give you super user permissions
echo "Got root access"
echo "First line of the file is as below :"
head -1 $filename
echo "---------------------------------------"
firstline=`head -1 $filename`
echo "Repeat : $firstline"
echo $firstline | grep ^"rom" >/dev/null
if test $? -eq 0
then
ex -s $filename <<'EOF'
1s/^/F/
:wq
EOF
echo "F issue fixed!"
HERE


c=1
while [ $c -le 5 ]
do
    ls -lrt $filename
    sleep 3
    c=`expr $c + 1`
done
echo "---------------------------------------------------"  
else
    echo "Not finding the missing 'F' ! !! Kindly check with your system "
    exit;
fi;

0 个答案:

没有答案