Home Man
Today's Posts

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

problem, script, shell scripts, sudo

Login to Reply

Thread Tools Search this Thread
# 1  
Old 01-14-2008
problem with sudo su and .sh script

here is my script:


cd /Users/a

echo "what is the name of the file u want?"
read 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

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

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

if test "$var1$var2" = "$var3.java"
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

if test "$var1$var2" = "$var3.c"
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

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

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.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem using sudo with NOPASSWD aigini82 HP-UX 3 04-12-2016 04:17 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 02:51 AM
ssh foo.com sudo command - Prompts for sudo password as visible text. Help? fluoborate Shell Programming and Scripting 9 11-02-2011 02:18 PM
sudo wildcards problem: for every argument a *-wildcard? Better solution? slashdotweenie UNIX for Advanced & Expert Users 2 09-20-2011 10:12 AM
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
HOw can i use sudo in a script rajesh212512 Shell Programming and Scripting 5 04-03-2008 02:53 AM

All times are GMT -4. The time now is 11:35 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
Show Password