Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site munnari.OZ Path: utzoo!watmath!clyde!cbosgd!gatech!seismo!munnari!kre From: kre@munnari.OZ (Robert Elz) Newsgroups: net.bugs.4bsd,net.unix-wizards Subject: Re: su in crontab Message-ID: <1031@munnari.OZ> Date: Mon, 13-Jan-86 13:21:55 EST Article-I.D.: munnari.1031 Posted: Mon Jan 13 13:21:55 1986 Date-Received: Wed, 15-Jan-86 00:26:10 EST References: <706@astrovax.UUCP> Organization: Comp Sci, Melbourne Uni, Australia Lines: 33 Xref: watmath net.bugs.4bsd:1927 net.unix-wizards:16379 Summary: '%' in crontab hasn't done much useful since 6th edition... 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... % in a crontab line is replaced by a newline. Cron executes the resulting line with "sh -c " In 6th edition, the shell would run commands, and hand them its standard input as their standard input, so the \n in cron lines could (sometimes) be useful for passsing data to commands. Since then, the standard input of the commands run by sh has been the standard input of the shell. For commands run by cron, standard input is "/" (as is standard output, and standard error), so your "su" would have been handed the contents of "/" as its input. I doubt if it executed many useful commands... (But try making a file in / with a name like "\nrm /etc/passwd\n" ...:-). Then the "exec..." command would have been executed by the shell after the su finally gave up (as root). What this all means is that the only way to pass data to commands run by cron, is to put the data in a file, and redirect stdin, or use your "echo" trick for simple input. I doubt that there's any remaining use for the '%' construct really, it could probably vanish without anyone realizing it had gone. 4.3 has added a user name field to crontab, so you can run commands from there as any user you like, and won't need "su". Not as general purpose as the SysV user crontabs, but better than it was. Robert Elz seismo!munnari!kre kre%munnari.oz@seismo.css.gov