Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site tikal.UUCP Path: utzoo!utcsri!ubc-vision!uw-beaver!tikal!stan From: stan@tikal.UUCP (Stan Tazuma) Newsgroups: net.bugs.4bsd,net.unix-wizards Subject: Re: su in crontab Message-ID: <313@tikal.UUCP> Date: Tue, 14-Jan-86 11:27:38 EST Article-I.D.: tikal.313 Posted: Tue Jan 14 11:27:38 1986 Date-Received: Wed, 15-Jan-86 08:48:19 EST References: <706@astrovax.UUCP> Reply-To: stan@tikal.UUCP (Stan Tazuma) Organization: Teltone Corp., Kirkland, WA Lines: 39 Summary: In article <706@astrovax.UUCP> wls@astrovax.UUCP (William L. Sebok) writes: >I just tripped over a rather puzzling anomaly. If I insert > >08 * * * * su wls % exec /usr/ucb/whoami >>/mnt/wls/TST/Errors 2>&1 > >I get "root" in the file /mnt/wls/TST/Errors, while if instead I insert > >12 * * * * echo /usr/ucb/whoami | su wls >>/mnt/wls/TST/Errors 2>&1 > The problem is that the man page for Berkeley cron lies. The man page says that when the '%' is used, following 'line's are passed to the command as input. This is false. When cron starts up a shell for the entire command line, it first replaces all '%'s by new-lines. Basically, your first example above would be executed like: $ su wls $ exec /usr/ucb/whoami >> ..... The first command (su) would start up a setuid shell; the shell would see EOF, and promptly exit (uid then reverts back to cron's uid). Then, the exec line would be executed, and the user-id would be cron's user-id, namely root in your case. The second of your crontab lines would be executed as expected, and that's why it works. To properly use the '%' char. in a crontab command line, try: su wls <