From owner-freebsd-questions Thu Mar 7 18:28:19 2002 Delivered-To: freebsd-questions@freebsd.org Received: from star-one.liberator.dyndns.org (dsl-64-34-177-185.telocity.com [64.34.177.185]) by hub.freebsd.org (Postfix) with ESMTP id 4795F37B416 for ; Thu, 7 Mar 2002 18:27:58 -0800 (PST) Received: (from dholmes@localhost) by star-one.liberator.dyndns.org (8.9.3/8.9.2) id SAA99190; Thu, 7 Mar 2002 18:28:22 -0800 (PST) (envelope-from dholmes) From: Dennis Holmes Message-Id: <200203080228.SAA99190@star-one.liberator.dyndns.org> Subject: Re: Starting daemon only for user; gotta be simple? In-Reply-To: <20020307181919.A94491@Deadcell.ant> from Andreas Ntaflos at "Mar 7, 2002 6:19:19 pm" To: ntaflos.andreas@gmx.net (Andreas Ntaflos) Date: Thu, 7 Mar 2002 18:28:22 -0800 (PST) Cc: freebsd-questions@FreeBSD.ORG Reply-To: dholmes@rahul.net X-Mailer: ELM [version 2.4ME+ PL43 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Look what Andreas Ntaflos wrote: > Hi all, > This is about fetchmail, but also a general question on how to start a > process or daemon at login time or boot time only once. > > I want to have fetchmail running in daemon mode, so I put the according > entry into my .fetchmailrc: > set daemon 900 > for example. But the daemon gets started only when I run fetchmail once > manually on the command line. > > I am looking for a way to have this task automated. A script in > /usr/local/etc/rc.d comes into mind, but this would start polling for mail > only for root wouldn't it? Putting 'fetchmail' into .login would start it > anytime the .login script is executed, that's every time I log into a new > virtual terminal. A cron job for fetchmail is another workaround which in > fact I used for months before I discovered the set daemon option. > > Of course, I could write a script that checks which tty I log into and > execute fetchmail (or anything else) only when it's ttyv0 for example. > But is there a better way to do such things? An equivalent to > /usr/local/etc/rc.d only for regular users instead of root? I may have not > R enough of TFM but I did not stumble across anything that would answer my > question. > > I hope that was not too confusing, excuse my English, I am a quite exhausted > and tired after a long day in school :) > > Thanks and regards > -- > Andreas "ant" Ntaflos > ntaflos.andreas@gmx.net > Vienna, AUSTRIA When I was running on a modem I had a script that would trigger a connection, check for success, perform some Internet-related tasks and then kick off user-defined scripts which might download mail or do other things. You could use the same technique in an rc.d script to run user-defined jobs at boot time. This csh (don't shoot me) code checks for a file called ".netstuff" in each directory immediately under /home and executes it as the user whose name is the same as the directory in which the file appears. This is certainly not the best way to do it, but since I was the only user on the system and I haven't used the script in a long time it didn't seem to matter. :-) You'd really want to either specify a list of authorized users, or obtain a list of valid users (via pw?), then check their defined home directories for a (ahem, executable) file to execute as the, ahem, user who owns the file. set users = `ls /usr/home` foreach user ($users) if (-f "/home/$user/.netstuff") then cd "/home/$user" /usr/bin/su -l "$user" -c "/bin/sh -c '.netstuff >netstuff.log 2>&1 &'" < /dev/null >& /dev/null endif end +----------------+-------------------+------------------------------------+ | Dennis Holmes | dholmes@rahul.net | "We demand rigidly defined | | San Jose, CA +-------------------+ areas of doubt and uncertainty!" | +------=>{ Meanwhile, as Ford said: "Where are my potato chips?" }<=------+ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message