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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a script as a different user.

Status
Not open for further replies.
Nov 11, 2005
2
US
What I want to do is find out the current screen saver settings the current user has set.

The way that I'm doing it now is, I split the tasks into two different scripts.

#!/bin/tcsh
set j=`users`
foreach k ($j)
echo $k
if ("$k" != 'root') then
sudo -u $k /usr/bin/forceScreenSaverSimple
exit
endif
end

And then it calls the script forceScreenSaverSimple which it runs as everyone except root.

#!/bin/tcsh
set currTime = `defaults -currentHost read com.apple.screensaver idleTime`
if ($currTime > 1800) defaults -currentHost write com.apple.screensaver idleTime 1800
defaults -currentHost write com.apple.screensaver askForPassword true
chsh -s /bin/bash

There must be an easier way to do this that's all in one script.
 
I did sudo because I couldn't figure out how to invoke su, and still run in tcsh. By default the users run bash and eventhough I put #!/bin/tcsh at the beginning of the script, it would still run in bash.
 
Then how about...
Code:
su - $u -c "/bin/tcsh /usr/bin/forceScreenSaverSimple"
Hope this helps.
 
Or try this...
Code:
su $u -c /usr/bin/forceScreenSaverSimple
Losing the dash should keep the shell and environment of the calling process. The script being called needs to define everything it needs since it won't have the environment of the user it's running it as.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top