- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: su to another user in a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2003 06:36 AM
05-01-2003 06:36 AM
I have a simple script
test.sh
whoami
I do the chown and the chmod
chown usera test.sh
chmod 4555 test.sh
ll
-rwsr-xr-x 1 usera users 33 May 1 10:17 test.sh
now when I run the script when logged in as another users say userb it says that I'm userb. :) I need this to say usera so that I can use this script to move files into a directory protected by usera without giving permission to userb. The completed version of this script will be used to log the transaction and keep a protected history of the files going into that directory. Hope this makes sense, and thanks for your help. ;)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2003 06:48 AM
05-01-2003 06:48 AM
Re: su to another user in a script
su - usera -c "
And that will run it properly as user usera.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2003 07:16 AM
05-01-2003 07:16 AM
Re: su to another user in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2003 07:28 AM
05-01-2003 07:28 AM
Re: su to another user in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2003 07:43 AM
05-01-2003 07:43 AM
Solutionhttp://hpux.cs.utah.edu/hppd/hpux/Sysadmin/sudo-1.6.6/
and configure userb in the sudoers file to only be able to run your script:
userb ALL=(usera) /path/to/test.sh
Then userb can do
sudo -u usera /path/to/test.sh
userb wil not need to know usera's password, the script will not need to be suid, and you will get a log of all actions in your syslog (depending on how you have /etc/syslog.conf configured).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2003 08:02 AM
05-01-2003 08:02 AM
Re: su to another user in a script
have the script execute as root... this will not require any password to execute the above script. this is the recommended way.
if you can't do this and you need to pass a password you could use expect. expect is downloadable from here http://expect.nist.gov/
and very easy to use. you just type what you want the script to do basically. I'm attaching a copy of one of my expect scripts
- my script is an example but it telnets into a server and executes things.... but you can use it to automate almost anything
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2003 09:28 AM
05-01-2003 09:28 AM
Re: su to another user in a script
but I'm sure they would both work from what I've read.
thanks