01-24-2008
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
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
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
2. Shell Programming and Scripting
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
3. AIX
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
4. Shell Programming and Scripting
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 default...so 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
5. Linux
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
6. UNIX for Dummies Questions & Answers
How to give an ordinary user the superuser (root) ID which is 0 (9 Replies)
Discussion started by: sharaola
9 Replies
7. Shell Programming and Scripting
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. UNIX for Dummies Questions & Answers
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
9. Shell Programming and Scripting
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
10. UNIX for Dummies Questions & Answers
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
MFI(4) BSD Kernel Interfaces Manual MFI(4)
NAME
mfi -- LSI Logic & Dell MegaRAID SAS RAID controller
SYNOPSIS
mfi* at pci? dev ? function ?
DESCRIPTION
The mfi driver provides support for the MegaRAID SAS family of RAID controllers, including:
- Dell PERC 5/e, PERC 5/i, PERC 6/e, PERC 6/i
- Intel RAID Controller SRCSAS18E, SRCSAS144E
- LSI Logic MegaRAID SAS 8208ELP, MegaRAID SAS 8208XLP, MegaRAID SAS 8300XLP, MegaRAID SAS 8308ELP, MegaRAID SAS 8344ELP, MegaRAID
SAS 8408E, MegaRAID SAS 8480E, MegaRAID SAS 8708ELP, MegaRAID SAS 8888ELP, MegaRAID SAS 8880EM2, MegaRAID SAS 9260-8i
- IBM ServeRAID M1015, ServeRAID M5014
These controllers support RAID 0, RAID 1, RAID 5, RAID 6, RAID 10, RAID 50 and RAID 60 using either SAS or SATA II drives.
Although the controllers are actual RAID controllers, the driver makes them look just like SCSI controllers. All RAID configuration is done
through the controllers' BIOSes.
mfi supports monitoring of the logical disks in the controller through the bioctl(8) and envstat(8) commands.
EVENTS
The mfi driver is able to send events to powerd(8) if a logical drive in the controller is not online. The state-changed event will be sent
to the /etc/powerd/scripts/sensor_drive script when such condition happens.
SEE ALSO
intro(4), pci(4), scsi(4), sd(4), bioctl(8), envstat(8), powerd(8)
HISTORY
The mfi driver first appeared in NetBSD 4.0.
BSD
March 22, 2012 BSD