Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

problem with sudo su and .sh script

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-14-2008   -   Original Discussion by cleansing_flame
cleansing_flame's Unix or Linux Image
cleansing_flame cleansing_flame is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 10 April 2008, 8:02 AM EDT
Location: NYC
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
problem with sudo su and .sh script

here is my script:

#!/bin/sh


cd /Users/a

echo "what is the name of the file u want?"
read var1
var1=$var1
var3=$var1

echo "is this $var1 okay?"
echo "enter the type of file u want"
echo "your choices are .java, .c, .sh, .ksh, .csh"
read var2
var2=$var2

var4=`find . -type f | grep "$var1$var2" | wc -l`
var5=0

if test $var4 -ne $var5
then
echo "next "$var2" prog"
exit 0
fi

if test "$var1$var2" = "$var3.java"
then
cd /Users/a/Javaprogs
mkdir ./$var1.java
emacs /Users/a/Javaprogs/$var1.java/$var1.java
cat ../defaults/javadefaultfile.txt >> ./Javaprogs/$var1.java/$var1.java
exit 0
fi

if test "$var1$var2" = "$var3.c"
then
cd /Users/a/cprogs
mkdir ./$var1.c
emacs /Users/a/cprogs/$var1.c/$var1.c
cat ../default/cprogdefaultfile.txt >> /Users/la/cprogs/$var1.c/$var1.c
exit 0
fi


if test "$var1$var2" = "$var3.sh"
then
`sudo su`
cd /bin
mkdir ./$var1
emacs ./$var1/$var1.sh
cat /Users/a/defaults/shdefaultfile.txt >> ./$var1/$var1.sh
exit 0
fi


the part in red contains the problem, the `sudo su` command does prompt me, but once I enter my passwd i change prompt as normal. I can type, but no commands are recognized and ctrl-c does nothing but enter a new blank line. Any help would be appreciated.
Sponsored Links
    #2  
Old Unix and Linux 01-14-2008   -   Original Discussion by cleansing_flame
shai.z's Unix or Linux Image
shai.z shai.z is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 14 January 2008, 3:03 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
what you are trying to do is run the commands in red with root permissions?
when you wrote "sudo su" what happens is that the "su" command runs with root permissions and opens you a new shell. if you quit this shell your script will finish it execution.
you should use the sudo command for each command you want to run with root permissions.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with Sudo inside a here document mnanavati UNIX for Dummies Questions & Answers 0 11-12-2010 03:23 PM
Problem with password expire and sudo. sparcman Solaris 2 04-14-2010 01:18 PM
Sudo Problem? datkan Linux 1 04-08-2010 07:58 AM
shell script problem , sudo mount command cola Shell Programming and Scripting 3 08-19-2009 02:09 PM
Sudo command problem mindtee_abhi UNIX for Advanced & Expert Users 4 03-17-2009 01:24 AM



All times are GMT -4. The time now is 07:33 AM.