Operating System - HP-UX
1834842 Members
2030 Online
110070 Solutions
New Discussion

"su" problem within a script

 
Krishnan Viswanathan
Frequent Advisor

"su" problem within a script

When I execute a particular script from the command line like : su bsp -c app.start
the script gets started as user bsp without any issue. (the script is owned by root but some users are authorised to start it up.)

How do I add the above "su "syntax within the script itself so that the users can just type in "app.start" and the binaries gets started always as user "bsp" ?

The extract of the script is as below (Can someone let me know where to place "su bsp -c" option in the script in the fifth line here?)

Thanks

#!/bin/sh
BSE=/app/bse
BSE_TMP=/app/bse/tmp
echo 'Initialize Printer Daemon\n'
if [ -x ${BSE}/bin/pdaemon${REL} ];then
if [ -f ${BSE_TMP}/pd_lock ]; then
echo "Printer Daemon already running"
else
if ${BSE}/bin/pdaemon${REL} ;then
echo 'Printer Daemon Initialized\n'
else
echo 'Cannot Initialize Printer Daemon\n'
fi
fi
else
echo 'Cannot Initialize Printer Daemon\n'
fi
exit 0
4 REPLIES 4
Scott Van Kalken
Esteemed Contributor

Re: "su" problem within a script

generally to su to another user you need the password of the user you are su-ing to.

However if you are root, you do not need to input a password.

if you want general users to run this, you can install a product called sudo. This will enable certain users to run certain commands as root. This is entirely configurable.

For HPUX I tend to go to the HPUX porting an archive centre.

http://hpux.connect.org.uk/
A. Clay Stephenson
Acclaimed Contributor

Re: "su" problem within a script

Hi:

You have basically two options:
1) Install sudo to allow a non-root user to
execute this script.
2) Write a small setuid c program which changes user and then executes your script in a system() call.

By the way, you can simply forget about the Baan Printer Daemon and do all your printing as 'Direct' devices sending everything through the UNIX lp system; that works quite well.

Clay
If it ain't broke, I can fix that.
Steven Sim Kok Leong
Honored Contributor

Re: "su" problem within a script

Hi,

I personally prefer restricted sam when it comes to tasks like this. Restricted sam sports a menu-like interface for users while allowing them to run setuid as root or another user. It is also highly configurable.

To add your script to restricted sam, execute

# sam -r

More information can be found in the man pages and HP-UX system administration guides.

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
Eugen Cocalea
Respected Contributor

Re: "su" problem within a script

Hi,

heh, seems I answered this one on the Linux forum as well.

isn't

chown bsp <script>
chmod +s <script>

working?

E.
To Live Is To Learn