[NTLUG:Discuss] crontab issue

Robert Citek robert.citek at gmail.com
Wed Mar 14 19:12:19 CDT 2007


Fred James wrote:
> All
> If I use a crontab entry such as
> 
> 42 * * * * su - username -c /home/username/program argument1 argument2 
> argument3 2> /tmp/errorfile
> 
> (1) errorfile will contain "stdin: is not a tty"
> (2) the arguments are ignored
> (3) the program attempts to run
> 
> This type/form of crontab entry works well on SGI IRIX, but I have not 
> been able to find the correct translation/syntax for Linux.  Thank you 
> in advance for any help you may be able to offer

What linux distro?  Is this a system crontab file (i.e. /etc/crontab),
user root, or a regular user?

Unless you are root, su is going to expect a password via stdin.  Also,
there is no "-c" option to su as there is with sudo or bash.  Simply
enclose any arguments in quotes.  For example:

su - username "echo hello"

If you put the redirect inside the quotes, the file will be owned by
username.  If you put it outside the quotes, the file will be owned by
root, assuming you are running the crontab as root.

Lastly, you may want to run some simple commands frequently until you
get the crontab syntax that you want.  I usually start with something
like this and then build it up:

* * * * * "date > /tmp/datefile"

I'm running Ubuntu 6.06 LTS, so YMMV.

Good luck and let us know what you discover.

Regards,
- Robert




More information about the Discuss mailing list