The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do i change to super user then revert back to ordinary user ,using shell script? wrapster Shell Programming and Scripting 3 06-04-2008 04:11 AM
su (switching to other user) bjagadeesh Shell Programming and Scripting 1 05-20-2008 07:27 AM
[Help] Give privilege to an ordinary user ibmer414 AIX 1 04-08-2008 11:56 AM
switching between root and a normal user melanie_pfefer Shell Programming and Scripting 3 04-21-2007 04:02 AM
Other than root user .Normal user is unable to create files mallesh UNIX for Advanced & Expert Users 1 06-22-2005 09:18 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 4
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


#!/bin/sh
function logrc
{
if [ -f $drv/$batchname".err" ]
then
cat $drv/$batchname".err"|grep 0
rcode=$?
fi

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

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


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

echo date
rcode=$?
logrc
}


function step01
{
step=step01
if [ "$rrstep" != "" ] && [ "$rrstep" != "$step" ]
then
echo $step skipped
return 0
fi
desc="Call SAS job"
Quoteme() {
if [ $# -gt 1 ]; then
quoteme="\"$*\""
else
quoteme=$1
fi
}
cd `cat /sasconfig/BPICRMS/jobpath/prereq`
cmd="/sas9/SAS913/sas"
for arg in "SET_RUN_CONTROL_TABLE_FOR_ALAS.sas"
do
Quoteme $arg
tmp="$quoteme"
cmd="$cmd $tmp"
done
$cmd
rcode=$?
logrc
}





#main script

drv=/sasprog/joblog
rdrv=/sasprog/Lev1/rdrv
batchname=SET_RUN_CONTROL_TABLE_FOR_ALAS
dtx=`date +'%y%m%d'`" "`date +'%H%M%S'`
rrstep=""
bpsw=0
ut=U_SET_RUN_CONTROL_TABLE_FOR_ALAS.txt
st=S_SET_RUN_CONTROL_TABLE_FOR_ALAS.txt
if [ "$1" != "" ] && [ "$1" != "step00" ]
then
echo Job Restarted at $1 $dtx >> $drv/$batchname".log"
rrstep=$1
else
echo Job Started $dtx > $drv/$batchname".log"
rrstep=""
fi

step00
step01
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-25-2008
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
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.
Reply With Quote
  #3 (permalink)  
Old 01-25-2008
Registered User
 

Join Date: Jan 2008
Posts: 4
tnx for the reply,
Reply With Quote
  #4 (permalink)  
Old 01-25-2008
Registered User
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 232
Code:
 su - root and I hope you can deal with your model.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0