Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax in perl script to run as unix user

Status
Not open for further replies.
Apr 30, 2003
56
US
I need to write a perl script that have to be run as a specific unix user. I know that in perl script you can use system to do any of the unix command. However, if I say "system 'su -username'; how should I type in the password. Does any one know the syntax to do this? I tried "system 'su -username/password';" But this did not work. Please help me! Thanks.
 
instead of coding in the user/password, why not schedule the job using at or cron? this way it will be executed with your user permissions (or the user permissions of the person setting the cron/at job).

if you need to do something for which you don't have the correct permissions, see your sysadmin for help or stop hacking :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
You need to set the setuid bit of the file permissions of the script. The script must be owned by the user
Code:
chown user1 myscript.pl
and then you set the bit using chmod
Code:
chmod u+s myscript.pl
A user other than the owner of the file must have permission to execute the script
Code:
chmod a+x myscript.pl
Or to accomplish setting the setuid bit and changing the execute permissions at the same time (but restricting write permissions)
Code:
chmod 4755 myscript.pl
jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top