Su to another user from root doesn't work within shell script


 
Thread Tools Search this Thread
Operating Systems HP-UX Su to another user from root doesn't work within shell script
# 1  
Old 06-28-2015
Su to another user from root doesn't work within shell script

Hello

I have a shell script that is run as root. Script rins ok until the point where it have to switch to user "mqm" to run other commands. It just hangs at the point of this line in the script

Code:
su - mqm -c "dspmq"

I ran the same commands at the terminal and they run fine.

Any thoughts.

Last edited by Don Cragun; 06-28-2015 at 08:44 PM.. Reason: Add CODE tags.
# 2  
Old 06-28-2015
Quote:
Originally Posted by mo12
Hello

I have a shell script that is run as root. Script rins ok until the point where it have to switch to user "mqm" to run other commands. It just hangs at the point of this line in the script

Code:
su - mqm -c "dspmq"

I ran the same commands at the terminal and they run fine.

Any thoughts.
Please show us the entire script (in CODE tags). And, show us (in CODE tags) how you invoke the script.

What operating system and shell are you using?

The behavior you are describing is frequently caused by mismatched quotes within a script or something else that we can't determine by seeing the line in the script where it becomes obvious that something has gone wrong.
# 3  
Old 06-29-2015
Try
Code:
su mqm -c "dspmq"

instead.
This User Gave Thanks to vincent72 For This Post:
# 4  
Old 06-29-2015
Thank you Vincent72. That worked.
# 5  
Old 06-29-2015
Quote:
Originally Posted by mo12
Thank you Vincent72. That worked.
Maybe mark this topic as solved ? Smilie
# 6  
Old 06-29-2015
I tagged it as solved. Is that all its required??
This User Gave Thanks to mo12 For This Post:
# 7  
Old 06-30-2015
Quote:
Originally Posted by mo12
I tagged it as solved. Is that all its required??
I guess so. Additionally there's a possibility to click on the "thanks" button but I'm not sure what purpose it serves.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Switch from Local user to root user from a shell script?

Hi, I need to switch from local user to root user in a shell script. I need to make it automated so that it doesn't prompt for the root password. I heard the su command will do that work but it prompt for the password. and also can someone tell me whether su command spawns a new shell or... (1 Reply)
Discussion started by: Little
1 Replies

2. Shell Programming and Scripting

Switching user inside a shell script doesn't seem to work

Linux version : Oracle Linux 6.4 Shell : Bash The following script will be run as root. During the execution, it should switch to oracle user and execute few commands. After googling and searching within unix.com , I came up with the following syntax ## Enclosing all commands in double... (7 Replies)
Discussion started by: John K
7 Replies

3. Red Hat

Usermod doesn't work on root

Hi, I am root user. I need to add more groups to the account. I usse the below command but no apparent result # id uid=0(root) gid=0(root) groups=0(root) # usermod -a -G 302,301,303 root # id uid=0(root) gid=0(root) groups=0(root) # What can be the reason? (6 Replies)
Discussion started by: BearCheese
6 Replies

4. Red Hat

sendmail doesn't work for root

I've created a Perl daemon that needs to send an email when an error/shutdown occurs. I use the Perl Email::Valid module and that uses sendmail. When I run the script as a regular user, the email is sent with no issues. When I run the script as the root user, I get the following message in... (1 Reply)
Discussion started by: OldManEd
1 Replies

5. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

6. UNIX for Dummies Questions & Answers

find command in shell script doesn't work

Hello all, Something strange going on with a shell script I'm writing. It's trying to write a list of files that it finds in a given directory to another file. But I also have a skip list so matching files that are in that skip list should be, well uhm, skipped :) Here's the code of my... (2 Replies)
Discussion started by: StijnV
2 Replies

7. Shell Programming and Scripting

root user command in shell script execute as normal user

Hi All I have written one shell script for GPRS route add is given below named GPRSRouteSet.sh URL="www.google.com" VBURL="10.5.2.211" echo "Setting route for $URL for GPRS" URL_Address=`nslookup $URL|grep Address:|grep -v "#"|awk -F " " '{print $2}'|head -1` echo "Executing ... (3 Replies)
Discussion started by: mnmonu
3 Replies

8. Shell Programming and Scripting

shell script, echo doesn't work

#!/bin/sh something(){ echo "Inside something" echo $1 $2 } val=$(something "Hello " "world") Output expected: Inside somethingHello world But it's not echoing. (4 Replies)
Discussion started by: cola
4 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

10. Shell Programming and Scripting

grep doesn't work within shell script?

I am trying to run the following code from a script file but it complains that syntax of (both instances of) grep is wrong. When I copy and paste it to the terminal, it is OK. Any idea what the problem might be? set i = `grep -c #define flags.h` while ($i>20) @ i-- my func (`cat... (4 Replies)
Discussion started by: barisgultekin
4 Replies
Login or Register to Ask a Question