as root on test files with
!#/bin/bash -x
I get my env echoed back to the screen, Have I wrote code that
is dangerous??
this dosen't show up if ran as non root user
heres what I get back:
test> ./rootf off
+ alias 'rm=rm -i'
+ alias 'cp=cp -i'
+ alias 'mv=mv -i'
+ '[' -f /etc/bashrc ']'
+ . /etc/bashrc
+++ id -gn
+++ id -un
+++ id -u
++ '[' root = root -a 0 -gt 99 ']'
++ umask 022
++ '[' '' ']'
+ wdir=/root/test
+ tmpd=/tmp
+ file=proftpd.conf
+ word=RootLogin off
+ word2=RootLogin on
+ tfile=temp.txt
+ msg1=Root Can Now FTP In
+ msg2=Root FTP Is Now Unavailable
+ msg3=You Must specifiy on or off
+ '[' off == on ']'
+ '[' off == off ']'
+ cd /root/test
+ cp -f proftpd.conf /tmp
+ sleep 1
+ sed -e 's/RootLogin on/RootLogin off/' proftpd.conf
+ sleep 1
+ mv -f /tmp/temp.txt /root/test/proftpd.conf
+ rm -f /tmp/proftpd.conf
+ echo 'Root FTP Is Now Unavailable'
Root FTP Is Now Unavailable
here is the complete code:
#!/bin/bash -x
#work directory
wdir="/root/test"
#temp directory
tmpd="/tmp"
#original file
file="proftpd.conf"
word="RootLogin off"
word2="RootLogin on"
#temp file
tfile="temp.txt"
#message-1
msg1="Root Can Now FTP In"
#message-2
msg2="Root FTP Is Now Unavailable"
#message-3
msg3="You Must specifiy on or off"
if [ "$1" == on ];
then
cd $wdir
cp -f $file $tmpd
sed -e "s/$word/$word2/" $file > $tmpd/$tfile
sleep 1
mv -f $tmpd/$tfile $wdir/$file
# rm -f $tmpd/$file
echo "$msg1"
elif [ "$1" == off ];
then
cd $wdir
cp -f $file $tmpd
sleep 1
sed -e "s/$word2/$word/" $file > $tmpd/$tfile
sleep 1
mv -f $tmpd/$tfile $wdir/$file
rm -f $tmpd/$file
echo "$msg2"
else
echo "$msg3"
fi