'exec /bin/sh' breaks alias


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 'exec /bin/sh' breaks alias
# 1  
Old 05-29-2008
'exec /bin/sh' breaks alias

I have an application that requires su to root in order to run some commands. Unfortunately, my corporate policy only allows sudo so I created an alias in .profile as "alias su="su myaccount". My external application logs in with the first account no problem, it then runs 'exec /bin/sh' and then tries to su with the myaccount password but it comes back with 'incorrect password'. If I use an ssh account, login with my first account and then su with myaccount password it works fine. It looks like the 'exec /bin/sh' does not take the alias. /bin/sh points to bash. I have the alias in .bashrc, .profile, .shrc and .bash_profile but none of this works.

any ideas on how to get the alias to work with the /bin/sh shell?

Thanks

Stu
# 2  
Old 05-29-2008
when you run exec, you are destroying your session and replacing it outright with your new one (Replacing your current session's PID with a new process using the same PID). You can simply run sh without exec, source your .profile or create another environment map and source that right after you change to the bourne shell.

While /bin/sh may be bash, usually it is a mapped compatibility mode for straight bourne.

By the way, the application doing this can be dangerous. Could you simply ask for the commands it needs to run to be added to the sudo configs to be allowed? That way, you will not need to exec a new shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

2. UNIX for Dummies Questions & Answers

Page breaks and line breaks

Hi All, Need an urgent solution to an issue . We have created a ksh file or shell script which generates 1 DAT file. the DAT file contains extract of a select statement . Now the issue is , when we are executing the ksh file , the output is coimng with page breaks and line breaks . We have... (4 Replies)
Discussion started by: Ayaskant
4 Replies

3. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

4. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

5. Debian

exec: 193: ./firefox-bin not found

Hi, all. When I run iceweasel as normal user in squeeze, I got forrowing message. exec: 193: ./firefox-bin: not found I think this is readlink problem, because ... #cat /usr/bin/iceweasel line 40........... MOZ_APP_LAUNCHER=$(which $0) MOZ_DIST_BIN= $(dirname $(readlink -f... (3 Replies)
Discussion started by: miru
3 Replies

6. Red Hat

/usr/bin/find && -exec /bin/rm never work as expected

hi there, Would you able to advise that why the syntax or statement below couldn't work as expected ? /usr/bin/find /backup -name "*tar*" -mtime +2 -exec /bin/rm -f {} \; 1> /dev/null 2>&1 In fact, I was initially located it as in crontab job, but it doesn't work at all. So, I was... (9 Replies)
Discussion started by: rauphelhunter
9 Replies

7. UNIX for Dummies Questions & Answers

Alias /usr/bin to /bin in profile

Hi! All the basic linux commands, ie. echo, find, etc, are located in /bin. I have a couple of programs that have these commands pointed towards /usr/bin, ie, /usr/bin/echo (even though the actual 'echo' command is in /bin). How can I alias or redirect or link the /usr/bin to /bin just for this... (6 Replies)
Discussion started by: dancerat
6 Replies

8. UNIX for Dummies Questions & Answers

fuser: difference with bin/sh and bin/ksh shell script

Hi, I have a problem I don't understand with fuser. I launch a simple shell script mysleep.sh: I launch the command fuser -fu mysleep.sh but fuser doesn't return anything excepted: mysleep: Then I modify my script switching from #!/bin/sh to #!/bin/ksh I launch the command fuser -fu... (4 Replies)
Discussion started by: Peuj
4 Replies

9. UNIX for Dummies Questions & Answers

Problems with Alias, /bin/sh and sudo

'exec /bin/sh' breaks alias -------------------------------------------------------------------------------- I have an application that requires su to root in order to run some commands. Unfortunately, my corporate policy only allows sudo so I created an alias in .profile as "alias su="su... (0 Replies)
Discussion started by: stulincoln
0 Replies

10. UNIX for Dummies Questions & Answers

/bin/sh: /usr/bin/vi: No such file or directory when doing crontab

I just set up an ftp server with Red Hat 5.2. I am doing the work, I'm baby stepping, but it seems like every step I get stuck. Currently, I'm trying to set up a crontab job, but I'm getting the following message: /bin/sh: /usr/bin/vi: No such file or directory. I see that vi exists in /bin/vi,... (3 Replies)
Discussion started by: kwalter
3 Replies
Login or Register to Ask a Question