[comp.unix.wizards] Cron jobs running as something other than root

gmartin@polyslo.CalPoly.EDU (Hackman) (08/27/90)

Excuse this if this has been discussed before, but I am trying to automate
a script that is run from our system (library.calpoly.edu).  However, this
script requires that it be run while logged in as 'libs'.  This script was
originally written by someone in Tech Support for the company that supports
the software for our online catalog, so I have no idea why the job has to
be run as libs, but: 

	Is there any way to make a job that runs from cron run under a 
        different login id???

(BTW - I have thought of setuid, and tried it, but to no avail)

Any suggestions or hints would be most appreciated. Thanks in advance.

	-Guy Martin
         Kennedy Library Computer Services
	 Cal Poly, San Luis Obispo, CA

-- 
Guy Martin (Hackman)             //      Internet: gmartin@polyslo.calpoly.edu
---------------------           //       Fubarnet: guy@fubarsys.slo.ca.us
Amiga, the tool for the     \\ //        Work: guy@library.calpoly.edu     
creative mind--------->      \X/         UUCP: ucbvax!voder!polyslo!gmartin

mvadh@cbnews.att.com (andrew.d.hay) (08/29/90)

In article <26d9499b.2715@petunia.CalPoly.EDU> gmartin@polyslo.CalPoly.EDU (Hackman) writes:
[]
"	Is there any way to make a job that runs from cron run under a 
"        different login id???

* * * * * su UID -c "command -args"

-- 
Andrew Hay		+------------------------------------------------------+
Ragged Individualist	| 	You just have _N_O idea!  It's the difference    |
AT&T-BL Ward Hill MA	|	between _S_H_O_O_T_I_N_G a bullet and _T_H_R_O_W_I_N_G it!     |
a.d.hay@att.com		+------------------------------------------------------+

les@chinet.chi.il.us (Leslie Mikesell) (08/30/90)

In article <1990Aug29.110345.19301@cbnews.att.com> mvadh@cbnews.att.com (andrew.d.hay) writes:
>In article <26d9499b.2715@petunia.CalPoly.EDU> gmartin@polyslo.CalPoly.EDU (Hackman) writes:
>[]
>"	Is there any way to make a job that runs from cron run under a 
>"        different login id???
>
>* * * * * su UID -c "command -args"

A potential problem with this is that if the user name mentioned happens
to have ksh as his login shell, his .profile will be executed. A workaround
is to use /bin/sh as the login shell but exec /bin/ksh in the user's
 .profile after exporting any necessary variables.  This is even more of
a problem if the "su -c user" appears in the /etc/rc files because these
commands run connected to the console causing any interactive prompts
to hang waiting for input.

Les Mikesell
  les@chinet.chi.il.us

brister@decwrl.dec.com (James Brister) (09/01/90)

You can also do this:

echo "commands and stuff here" | su $USER

Seems to be little more portable.

James
--
James Brister                                           brister@decwrl.dec.com
DEC Western Software Lab., Palo Alto, California.         .....!decwrl!brister

louie@sayshell.umd.edu (Louis A. Mamakos) (09/02/90)

Why don't you just get the 4.3BSD cron, which adds an additional field which
specified the user you want the process to run as.  None of this silly
piping stuff to 'su'.

louie

example:

0,15,30,45 * * * * root 	/usr/lib/atrun

5  5 * * *	root	find /usr/spool/lpd -mtime +7  -a -exec rm -f {} \;
9  5 * * *	root	find /usr/spool/at/past -atime +2  -a -exec rm -f {} \;
15 5 * * *	root	find /usr/man/cat? -atime +14 -exec rm -f {} >/dev/console \;

30 5 * * *	root	/usr/adm/saveacct
50 23 * * *	root	/bin/sh /usr/local/adm/daily.sh 2>&1 | mail sys-staff
0  3 * * *	root	/etc/setcl -s umd1.umd.edu
15 3 * * 1	root	/usr/adm/weekly
#
# Archive things in /usr/adm on the first day of the month
#
5 0 1 * * 	root 	/usr/local/adm/acct.monthly
#
# Check the various dialup modems on week nights.
#
0 3 * * 1,2,3,4,5 	root	/usr/local/etc/dialup/dialup.sh
#
#
# Ultrix Field Test QAR submitter
#
0 11,20 * * * 	qar	/usr/local/lib/qar/nightly.sh
#
# %UUCPSTART%  - uucp related entries, put here by uucpsetup
30 * * * * 	uucp	/usr/lib/uucp/uucp.hour
0 6 * * * 	uucp	/usr/lib/uucp/uucp.day
0 12 * * *	uucp	/usr/lib/uucp/uucp.noon
0 3 * * 1	uucp	/usr/lib/uucp/uucp.week
0 2 * * * 	uucp	/usr/lib/uucp/uucp.night
#30 2 1 * *	uucp	/usr/lib/uucp/uucp.longhall
# %UUCPEND%
#
# News stuff
#
5,20,35,50 * * * *    	news	/usr/local/lib/news/nntpsend
15 * * * *	news /usr/local/lib/newsbin/input/newsrun
40 * * * *	news /usr/local/lib/newsbin/batch/sendbatches
59 0 * * *	news /usr/local/lib/newsbin/expire/doexpire
45 3 * * *	news /usr/local/lib/newsbin/expire/superkludge comp.mail.maps
10 8 * * *	news /usr/local/lib/newsbin/maint/newsdaily
00 5,13,21 * * * news /usr/local/lib/newsbin/maint/newswatch

dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) (09/03/90)

In article <26d9499b.2715@petunia.CalPoly.EDU> gmartin@polyslo.CalPoly.EDU (Hackman) writes:
>
>Excuse this if this has been discussed before, but I am trying to automate
>a script that is run from our system (library.calpoly.edu).  However, this
>script requires that it be run while logged in as 'libs'.  This script was
>originally written by someone in Tech Support for the company that supports
>the software for our online catalog, so I have no idea why the job has to
>be run as libs, but: 
>
>	Is there any way to make a job that runs from cron run under a 
>        different login id???


In SCO Xenix this is done by having separate crontab files in 
/usr/spool/cron/crontabs. The command would be put in
/usr/spool/cron/crontabs/libs.



--
Dave Eisen                      	    Home: (415) 323-9757
dkeisen@Gang-of-Four.Stanford.EDU           Office: (415) 967-5644
1447 N. Shoreline Blvd.
Mountain View, CA 94043

douglas@dekalb.UUCP (Douglas B. Jones) (09/05/90)

In article <26d9499b.2715@petunia.CalPoly.EDU> gmartin@polyslo.CalPoly.EDU (Hackman) writes:
>	Is there any way to make a job that runs from cron run under a 
>        different login id???
>	-Guy Martin
>         Kennedy Library Computer Services
>	 Cal Poly, San Luis Obispo, CA
>Guy Martin (Hackman)             //      Internet: gmartin@polyslo.calpoly.edu
>---------------------           //       Fubarnet: guy@fubarsys.slo.ca.us
>Amiga, the tool for the     \\ //        Work: guy@library.calpoly.edu     
>creative mind--------->      \X/         UUCP: ucbvax!voder!polyslo!gmartin



In our /etc/crontab there are entries that are run for uucp.

Here are some examples:

30 * * * * su uucpa < /usr/var/uucp/uucp.hour
0 6 * * * su uucpa < /usr/var/uucp/uucp.day
0 12 * * * su uucpa < /usr/var/uucp/uucp.noon
0 3 1 * * su uucpa < /usr/var/uucp/uucp.week
0 2 * * * su uucpa < /usr/var/uucp/uucp.night
#30 2 1 * * su uucp < /usr/var/uucp/uucp.longhall

"uucpa" is an admin. id for uucp.

hope this helps,
Douglas

-- 
Doulas B. Jones					douglas@dekalb
Academic Computer Center		or	gatech!dekalb!douglas
DeKalb College
555 N. Indian Creek Drive/Clarkston, Ga. 30021  (404) 299-4233

mjohn@king..citib (Michael Johnston) (09/06/90)

In article <1054@dekalb.UUCP> douglas@dekalb.UUCP (Douglas B. Jones) writes:
>In article <26d9499b.2715@petunia.CalPoly.EDU> gmartin@polyslo.CalPoly.EDU (Hackman) writes:
>>	Is there any way to make a job that runs from cron run under a 
>>        different login id???

>In our /etc/crontab there are entries that are run for uucp.
>
>Here are some examples:
>
>30 * * * * su uucpa < /usr/var/uucp/uucp.hour

If you are running BSD or flavors of System V you have available to you
the 'crontab' command. Just create a crontab file for the USER you wish
to run cron jobs for. Then su to the username you wish to install it for
and say "crontab < your_cron_file". That's all folks.



--
Michael R. Johnston, Mgr.           Internet: mjohn@citib.com
USCPG , Treasury Systems            UUCP: uunet!uupsi!bank!mjohn
Citicorp, NA                        (718) 248-5373

vixie@wrl.dec.com (Paul Vixie) (09/07/90)

In article <1990Sep5.200114.1711@rosewall.citib> mjohn@king.UUCP (Michael Johnston) writes:
# If you are running BSD or flavors of System V you have available to you
# the 'crontab' command. Just create a crontab file for the USER you wish
# to run cron jobs for. Then su to the username you wish to install it for
# and say "crontab < your_cron_file". That's all folks.

Not quite.  BSD through 4.3-reno doesn't have this.  4.4 will have it,
in the form of my free version of cron (which uses crontab -uUSER rather
than 'su USER;crontab' btw).  Grab it from gatekeeper.dec.com anon ftp
/pub/misc/vixie/cron2.tar.Z.  (Will appear in comp.sources.unix shortly.)
--
Paul Vixie
DEC Western Research Lab	<vixie@wrl.dec.com>
Palo Alto, California		...!decwrl!vixie

mjohn@king..citib (Michael Johnston) (09/07/90)

In article <1990Sep6.225446.28837@wrl.dec.com> vixie@wrl.dec.com (Paul Vixie) writes:
>In article <1990Sep5.200114.1711@rosewall.citib> mjohn@king.UUCP (Michael Johnston) writes:
># If you are running BSD or flavors of System V you have available to you
># the 'crontab' command. Just create a crontab file for the USER you wish
># to run cron jobs for. Then su to the username you wish to install it for
># and say "crontab < your_cron_file". That's all folks.
>
>Not quite.  BSD through 4.3-reno doesn't have this.  4.4 will have it,
>in the form of my free version of cron (which uses crontab -uUSER rather
>than 'su USER;crontab' btw).  Grab it from gatekeeper.dec.com anon ftp
>/pub/misc/vixie/cron2.tar.Z.  (Will appear in comp.sources.unix shortly.)

I stand corrected. The system I'm using is running SunOS 4.03 and it
DOES have the crontab utility. SunOS being derived from BSD but with
added SysV extensions often makes me forget it's origins.


--
Michael R. Johnston, Mgr.           Internet: mjohn@citib.com
USCPG , Treasury Systems            UUCP: uunet!uupsi!bank!mjohn
Citicorp, NA                        (718) 248-5373