The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-01-2006
Registered User
 

Join Date: Dec 2005
Posts: 13
when running my script below

as root on test files with
Code:
!#/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:

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
here is the complete code:
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-02-2006
Registered User
 

Join Date: Jan 2006
Location: india
Posts: 29
debugging mode

you are using the debugging mode to run the script.....

remove the -x option from the shell and then run the script....
Reply With Quote
  #3 (permalink)  
Old 01-02-2006
Registered User
 

Join Date: Dec 2005
Posts: 13
yes, But what I was wondering is,
why the debug out put was showing the env for root, But it doesnt when ran as any other user
Thanks for your reply
Reply With Quote
  #4 (permalink)  
Old 01-02-2006
Registered User
 

Join Date: Jan 2006
Location: india
Posts: 29
need clarification

i dont understand what u mean.....

"env" what u meant by that???? i dont understand that abbreviation. can u specify the line that u have a doubt with...
Reply With Quote
  #5 (permalink)  
Old 01-03-2006
Registered User
 

Join Date: Dec 2005
Posts: 13
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
++ '[' '' ']'
Reply With Quote
  #6 (permalink)  
Old 01-03-2006
Registered User
 

Join Date: Jan 2006
Location: india
Posts: 29
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0