Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Mar 2002 18:28:22 -0800 (PST)
From:      Dennis Holmes <dholmes@liberator.dyndns.org>
To:        ntaflos.andreas@gmx.net (Andreas Ntaflos)
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Starting daemon only for user; gotta be simple?
Message-ID:  <200203080228.SAA99190@star-one.liberator.dyndns.org>
In-Reply-To: <20020307181919.A94491@Deadcell.ant> from Andreas Ntaflos at "Mar 7, 2002  6:19:19 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203080228.SAA99190>