From owner-freebsd-questions@FreeBSD.ORG Fri May 8 21:51:44 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 842CD106566C for ; Fri, 8 May 2009 21:51:44 +0000 (UTC) (envelope-from vogelke@hcst.com) Received: from beta.hcst.com (beta.hcst.com [192.52.183.241]) by mx1.freebsd.org (Postfix) with ESMTP id 45EE98FC13 for ; Fri, 8 May 2009 21:51:44 +0000 (UTC) (envelope-from vogelke@hcst.com) Received: from beta.hcst.com (localhost [127.0.0.1]) by beta.hcst.com (8.13.8/8.13.8/Debian-3) with ESMTP id n48Lphxc027067 for ; Fri, 8 May 2009 17:51:43 -0400 Received: (from vogelke@localhost) by beta.hcst.com (8.13.8/8.13.8/Submit) id n48Lphhw027066; Fri, 8 May 2009 17:51:43 -0400 Received: by kev.msw.wpafb.af.mil (Postfix, from userid 32768) id 948D0BEAA; Fri, 8 May 2009 17:47:26 -0400 (EDT) To: freebsd-questions@freebsd.org In-reply-to: <560f92640905071722t79978104v1401f99b5cedabb0@mail.gmail.com> (message from Nerius Landys on Thu, 7 May 2009 17:22:01 -0700) Organization: Oasis Systems Inc. X-Disclaimer: I don't speak for the USAF or Oasis. X-GPG-ID: 1024D/711752A0 2006-06-27 Karl Vogel X-GPG-Fingerprint: 56EB 6DBF 4224 C953 F417 CC99 4C7C 7D46 7117 52A0 Message-Id: <20090508214726.948D0BEAA@kev.msw.wpafb.af.mil> Date: Fri, 8 May 2009 17:47:26 -0400 (EDT) From: vogelke+unix@pobox.com (Karl Vogel) Subject: Re: Run script on boot, as ordinary user X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: vogelke+unix@pobox.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 May 2009 21:51:44 -0000 >> On Thu, 7 May 2009 17:22:01 -0700, >> Nerius Landys said: N> Seems that @reboot in cron is what I need. It's too bad that there's N> no straightforward shutdown hook. I use something like the script below to send me a popup message whenever one of my boxes shuts down, planned or otherwise. It assumes that if you can run cron jobs, you can be trusted to run something as yourself at system shutdown. For safety, nothing is run as root, and cron users can only run a script called called '/home/./$username/rc.d/shutdown'. Add this to /etc/rc.shutdown: run-rc-shutdown | sh If you don't have "setuidgid" installed, replace with "su -c ..." -- Karl Vogel I don't speak for the USAF or my company The little boat gently drifted across the pond exactly the way a bowling ball wouldn't. --bizarre expressions found in student English papers --------------------------------------------------------------------------- #!/usr/bin/perl -w # run-rc-shutdown: print commands to run any non-root shutdown scripts. use strict; my ($dir, $dh, $home, $script, $uid, $usr); $dir = '/var/cron/tabs'; # BSD. #$dir = '/var/spool/cron/crontabs'; # Solaris. opendir($dh, "$dir") || die "opendir $dir: $!\n"; my @users = sort (grep (!/^\./, readdir($dh))); closedir($dh); foreach (@users) { ($usr, $uid, $dir) = (getpwnam($_))[0,2,7]; next unless $dir =~ m!/home/./$usr!; next unless $uid > 0; $script = $dir . '/rc.d/shutdown'; print "/usr/local/bin/setuidgid $usr $script\n" if -x $script; } exit(0);