problem with sudo su and .sh script

Tags
problem, script, shell scripts, sudo

 
Thread Tools Search this Thread
# 1  
Old 01-14-2008
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.
# 2  
Old 01-14-2008
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.

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Sudo for full script hburnswell UNIX for Advanced & Expert Users 3 07-15-2016 09:45 AM
Problem using sudo with NOPASSWD aigini82 HP-UX 3 04-12-2016 05:17 AM
SUDO command in script venky.b5 Shell Programming and Scripting 5 10-07-2015 08:54 AM
Problem connect to a different server then do sudo login and finally run some scripts and get result Devesh5683 Shell Programming and Scripting 2 04-21-2014 03:51 AM
ssh foo.com sudo command - Prompts for sudo password as visible text. Help? fluoborate Shell Programming and Scripting 9 11-02-2011 03:18 PM
sudo wildcards problem: for every argument a *-wildcard? Better solution? slashdotweenie UNIX for Advanced & Expert Users 2 09-20-2011 11:12 AM
Help with Shell Script on sudo saket Shell Programming and Scripting 7 09-14-2011 03:02 AM
password in sudo script pua06 Shell Programming and Scripting 5 07-18-2011 01:30 AM
Problem with Sudo inside a here document mnanavati UNIX for Dummies Questions & Answers 0 11-12-2010 04:23 PM
sudo chmod not working through script sdosanjh Shell Programming and Scripting 2 07-29-2010 02:38 AM
Problem with password expire and sudo. sparcman Solaris 2 04-14-2010 02:18 PM
Sudo Problem? datkan Linux 1 04-08-2010 08:58 AM
shell script problem , sudo mount command cola Shell Programming and Scripting 3 08-19-2009 03:09 PM
Sudo command problem mindtee_abhi UNIX for Advanced & Expert Users 4 03-17-2009 02:24 AM
HOw can i use sudo in a script rajesh212512 Shell Programming and Scripting 5 04-03-2008 03:53 AM