![]() |
LaunchDaemon to run at every logon?
Hello Everyone
Our marketing staff sometimes have to "hotdesk" between their Macs so they have been told to save everything in the /Users/Shared folder and I have got a simple script (chmod -R 777 /Users/Shared) that is run by Mike Bombich's login window manager so that when someone logs on, it ensures they can work on all the files in that folder. This is working fine but I have been experimenting with using a launchdaemon (written with lingon) but it only runs when the system is restarted. Does anyone know how to make it run when a user logs on? The option to run it when the folder is modified works, but I don't want it running all the time. thanks |
Not sure about running at login, but you could check out the WatchPaths key.
man launchd.plist See also this discussion. |
Lingon is a GUI to launchd it will help you out
get the right version for your OS.. oops ignore me.......you are using Lingon... Should be a User Agent (launched when anyone logs in) then Run it when loaded by System or Login should be checked. |
agentx
I use Lingon and the option to "runatload". The blurb on this option says to use this if you want it to run at system startup or login, but in practice it only runs on startup. |
Quote:
|
I believe launchagents is a log in hook, and runs when any user logs in (or specific if it is in the home folder) and LaunchDaemons is a system daemon and just plain runs at boot up. That is the minor difference.
|
Putting a copy in every user's folder is not practical and I have tried putting it the /Library/LaunchAgents folder where it does run at every logon, but not as root, as the following entries in the system.log show :-
Nov 6 11:15:12 macintosh-2 chmod_777[1747]: chmod: /Users/Shared//aaa.rtf: Operation not permitted Nov 6 11:15:12 macintosh-2 chmod_777[1747]: chmod: /Users/Shared//aab.rtf: Operation not permitted Nov 6 11:15:12 macintosh-2 chmod_777[1747]: chmod: /Users/Shared//aac.rtf: Operation not permitted Nov 6 11:15:12 macintosh-2 chmod_777[1747]: chmod: /Users/Shared//aad.rtf: Operation not permitted |
make sure it is owned by root:wheel
then once it is in place use launch control, launchctl list, to see current launch items running, and you can use launchctl to also manually start your daemon, via the launchctl launch command I believe. Also, it looks like you are trying to run a rich text file. If you are running a script you need to save it as plain text, with the sh extension. I am betting you created it in textedit which by default, always saves items in rich text format. Oh wait, not enough coffee yet, you are running to run the chmod command on those rtf files....and it doesn't have proper permisisons. Can I see your script please? |
The plist is owned by root. The rtf files are simply test files (chmod 755) in the shared folder. The system.log entries shows that plist is running correctly when a user logs on, but is unable to "chmod" the files to 777 which indicates it is not running as root.
|
Quote:
|
here is the plist :-
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>chmod_777</string> <key>ProgramArguments</key> <array> <string>chmod</string> <string>-R</string> <string>777</string> <string>/Users/Shared/</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> |
try putting the full path of chmod.../bin/chmod and see what happens
|
Still the same I'm afraid. Same entries in the system.log
|
I wonder why that is. Have you tried making an actual shell script and then putting that script on the machines locally, then having your launchd item just run the script?
|
maybe what you need is a different approach. rather than trying to check for when users log in, why not just make a watchfolders plist that will modify files as soon as they are dropped in the folder. like follows:
Code:
<?xml version="1.0" encoding="UTF-8"?> |
Quote:
Thanks TW, I had previously tried that option and it does work but I didn't really want something running all the time however it looks like I will have to go with that option and run it as a launchdaemon. Shame that Mike Bombich has stopped developing his loginwindowmanager because I found it a very useful piece of software. |
hmm, that is very strange. Last year in our 1:1 deployment I had a log in hook that ran at log in, and it would simply force a reconnect to our preferred network (airport) and make sure that the airport was turned on and active.
I tossed the script in /usr/sbin, made it executable and owned by root. Then I had a launchd item in /Library/LaunchAgents and every time a user would log in, it would simply trigger the script in the local path of /usr/sbin/airport.sh It worked. That was on a Tiger image too. Very strange. Another option would be to have the launchd item watch the shared folder, and every time it is modified apply the new permissions. |
But did it need take root authentication to carry out your task?
|
Quote:
|
If it needs to run as "root" at each login, why not go with an old fashioned (in OS X terms) login hook?
http://support.apple.com/kb/HT2420 |
| All times are GMT -5. The time now is 10:20 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.