![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| My script is not running | manna | UNIX for Dummies Questions & Answers | 8 | 01-05-2008 12:11 PM |
| Running KSH script In SFU | ilak1008 | Windows & DOS: Issues & Discussions | 2 | 05-23-2007 11:17 PM |
| running cd from a script | SkySmart | Shell Programming and Scripting | 5 | 03-08-2007 08:07 PM |
| running a script? | jtredway | UNIX for Dummies Questions & Answers | 2 | 09-11-2001 08:08 PM |
| Running a script from CDE... | kristy | UNIX for Dummies Questions & Answers | 4 | 09-05-2001 07:33 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
when running my script below
as root on test files with
Code:
!#/bin/bash -x is dangerous?? this dosen't show up if ran as non root user heres what I get back: Code:
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 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
|
| Forum Sponsor | ||
|
|
|
|||
|
sorry..
my shell environment gets echoed back at me.. Code:
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 ++ '[' '' ']' |
|
|||
|
some suggestion
in the first line of your script, use #!/bin/bash rather than #!/bin/bash -x and then in your second line of the script give "set -x"
also start the script using bash <script name> or by setting the execute permission of the script and typing the script name alone... 1) change #!/bin/bash to #!/bin/bash -x in the first line and then include "set -x" as the second line of the script 2) a) execute by using bash <script name> (or) b) by setting execute permission and typing the script name alone |
|||
| Google The UNIX and Linux Forums |