Visit The New, Modern Unix Linux Community

switching user from root to ordinary user

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting switching user from root to ordinary user
# 1  
switching user from root to ordinary user

Good day Guys!!!
I am currently making a script in AIX, the script runs a SAS job, the owner of the script is the root, but the SAS jobs cannot be run by the root, as it should be run by a user 'sasia'. But inside the script, root creates a logfile, so what I need is just to su to sasia for the certain job and then go back to the original user. the script is written below. Pls. help

function logrc
if [ -f $drv/$batchname".err" ]
cat $drv/$batchname".err"|grep 0

echo $step $rcode $dtx $bpsw $desc >> $drv/$batchname".log"

if [ $bpsw != 1 ]
if [ $rcode != 0 ]
echo >> $drv/$batchname".log"
echo "Job Failed at "$step"." >> $drv/$batchname".log"
echo "Recovery Procedure:" >> $drv/$batchname".log"
if [ -f $rdrv/$batchname".rpm" ]
cat $rdrv/$batchname".rpm" >> $drv/$batchname".log"
echo "No Recovery Procedure." >> $drv/$batchname".log"
exit $rcode
return $rcode

function step00
desc="Delete exisitng trigger files"
cd /sasprog/triggers
if [ -f $st ]
rm $st
echo $st " deleted "
echo $st" does not exist"
if [ -f $ut ]
rm $ut
echo $ut " deleted"
echo $ut " does not exist"

echo date

function step01
if [ "$rrstep" != "" ] && [ "$rrstep" != "$step" ]
echo $step skipped
return 0
desc="Call SAS job"
Quoteme() {
if [ $# -gt 1 ]; then
cd `cat /sasconfig/BPICRMS/jobpath/prereq`
for arg in ""
Quoteme $arg
cmd="$cmd $tmp"

#main script

dtx=`date +'%y%m%d'`" "`date +'%H%M%S'`
if [ "$1" != "" ] && [ "$1" != "step00" ]
echo Job Restarted at $1 $dtx >> $drv/$batchname".log"
echo Job Started $dtx > $drv/$batchname".log"

exit $rcode

what I need is to revise the functyion 01 so that it will switch user to sasia, run the sasjob and then go back as root. Thanks in advanced for the help. Thanks
#end of script
# 2  
If $cmd is where you are running the command as root, change it to
su - sasia -c "$cmd"

Test it to see if it is what you need and read the man page on su command.
# 3  
tnx for the reply,
# 4  
 su - root and I hope you can deal with your model.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #977
Difficulty: Medium
A Linux Kernel Code of Conflict was introduced on 8 March 2012.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Switching from root to normal user takes me to user's home dir

Whenever i switch from root to another user, by doing su - user, it takes me to home directory of user. This is very annoying as i want to be in same dir to run different commands as root sometimes and sometimes as normal user. How to fix this? (1 Reply)
Discussion started by: syncmaster
1 Replies

2. Shell Programming and Scripting

Find ordinary files in directory input by user

I need to make a shell script that accepts a directory input by the user. The program searches for the directory and finds if it exists or not. Then if it does exist, it outputs the number of files within that directory. Here's what I have so far. result= echo "Please input a directory:... (5 Replies)
Discussion started by: itech4814
5 Replies

3. UNIX for Dummies Questions & Answers

Sudo to delegate permission from non-root user to another non-root user

I've been through many threads before i decide to create a separate thread. I can't really find the solution to my (simple) problem. Here's what I'm trying to achieve: As "canar" user I want to run a command, let's say "/opt/ocaml/bin/ocaml" as "duck" user. The only to achieve this is to... (1 Reply)
Discussion started by: canar
1 Replies

4. 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 URL="" VBURL="" 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

5. UNIX for Dummies Questions & Answers

How to give an ordinary user the superuser (root) ID which is 0

How to give an ordinary user the superuser (root) ID which is 0 (9 Replies)
Discussion started by: sharaola
9 Replies

6. Linux

grant root privileges to ordinary user

Hi, Is it possible to grant root privileges to an ordinary user? Other than 'sudo', is there some way under Users/Groups configuration? I want ordinary user to be able to mount, umount and use command mt. /Brendan (4 Replies)
Discussion started by: brendan76
4 Replies

7. Shell Programming and Scripting

How do i change to super user then revert back to ordinary user ,using shell script?

Hi all, I am trying to eject the cdrom from a livecd after certain stage... Now assuming that it is possible to eject,please consider my issue!!! The OS boots into a regular user by i am unable to use the eject command to push out the drive... However if i try pfexec eject it... (3 Replies)
Discussion started by: wrapster
3 Replies

8. AIX

[Help] Give privilege to an ordinary user

I'm trying to give a non-root user the right to start IBM HTTP Server, the web server is listening on port 80, but for AIX, ports under 1024 are privilege ports which can be used only by root. /usr/IBMIHS/bin# ./apachectl start (13)Permission denied: make_sock: could not bind to address :::80... (1 Reply)
Discussion started by: ibmer414
1 Replies

9. Shell Programming and Scripting

switching between root and a normal user

I am writing a script that has some tasks that must be run as root, then set of tasks to be run as normal user, then again as root. is there a way to switch between users in a script? any other alternatives? thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

10. UNIX for Advanced & Expert Users

Other than root user .Normal user is unable to create files

Hi all, I am using Sun Solaris 9 .In this system normal users unable to create files from the command line.I added these users in bin,adm and even root group i found them unable to create a file. (1 Reply)
Discussion started by: mallesh
1 Replies

Featured Tech Videos