Date: Fri, 8 May 2009 17:47:26 -0400 (EDT) From: vogelke+unix@pobox.com (Karl Vogel) To: freebsd-questions@freebsd.org Subject: Re: Run script on boot, as ordinary user Message-ID: <20090508214726.948D0BEAA@kev.msw.wpafb.af.mil> In-Reply-To: <560f92640905071722t79978104v1401f99b5cedabb0@mail.gmail.com> (message from Nerius Landys on Thu, 7 May 2009 17:22:01 -0700)
next in thread | previous in thread | raw e-mail | index | archive | help
>> On Thu, 7 May 2009 17:22:01 -0700, >> Nerius Landys <nlandys@gmail.com> 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090508214726.948D0BEAA>