LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-04-2011, 02:43 PM   #1
laredotornado
Member
 
Registered: Apr 2011
Posts: 68

Rep: Reputation: 0
Running a cron job as a user


Hi,

I'm using Ubuntu 11.04. I want to run a cron job as a user, "selenium", but adding this to my crontab fails ...

Code:
00 */6 * * * selenium /opt/scripts/selenium/run_nis_inf_tests.sh
with the error

Code:
/bin/sh: selenium: not found
What is the correct syntax I need to use on Ubuntu? Thanks, - Dave
 
Old 05-04-2011, 02:46 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Cron doesn't have a user field.
Just create the cronjob as the user selenium
login as selenium
type
Code:
crontab -e
add
Code:
00 */6 * * * /opt/scripts/selenium/run_nis_inf_tests.sh
save the file.

Kind regards
 
Old 05-04-2011, 04:05 PM   #3
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Did you put this in *your* crontab, or in /etc/crontab?

From the man page: The format of a cron command is very much the V7 standard, with a number of upward-compatible extensions. Each line has five time and date fields, followed by a user name if this is the system crontab file, followed by a command.

http://linux.die.net/man/5/crontab
 
Old 05-05-2011, 09:54 AM   #4
laredotornado
Member
 
Registered: Apr 2011
Posts: 68

Original Poster
Rep: Reputation: 0
Ah, I used "crontab -e" so that must be the user's cron. With the /etc/crontab option, is there a way I can get only the output of the cron I add emailed to me? In the "crontab -e" way, I specified a MAILTO variable, but I don't want the output of every script in /etc/crontab emailed to me.

- Dave
 
Old 05-05-2011, 10:11 AM   #5
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
As far as I know, MAILTO in /etc/crontab would have the outcome you've mentioned, that you'll get mail for every command it runs.

As repo stated previously, another way to do this is to use the crontab of the user you want to execute the command. So instead of "crontab -e", you could do "sudo -u selenium crontab -e" (assuming you've set yourself up with sudo rights as selenium, or just su to selenium, login as selenium with a new session, etc.). You could set MAILTO=youruid in selenium's crontab, and all is well.

Or, you could still run it out of /etc/crontab, but instead of using mail, write your output to a log file.

There are several ways to skin this cat.
 
Old 05-05-2011, 10:25 AM   #6
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
what are you trying to do with selenium?
 
Old 05-05-2011, 11:42 AM   #7
laredotornado
Member
 
Registered: Apr 2011
Posts: 68

Original Poster
Rep: Reputation: 0
We want to periodically run some Selenium regression tests against a Selenium remote control server.

So to the issue of "MAILTO", how would I set that up in /etc/crontab to only email me the results of that job and not others? Upon your response, I'll mark this as resolved and increase your rep . - Dave
 
Old 05-05-2011, 12:43 PM   #8
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
I would look for an alternative to MAILTO if you're going to put this in /etc/crontab, because you can't use MAILTO to apply to a single cron job. It's all or nothing.

So first, I'd figure out if I really need this thing mailed or not. Then, I'd dump the output of my cron job to a log file, like so:

Code:
00 */6 * * * selenium /opt/scripts/selenium/run_nis_inf_tests.sh > /path/logfilename.`/bin/date +\%Y-\%m-\%d-\%H.\%M.\%S` 2>&1
This gets you a log file with current time and date stamp, so if you're happy there, you're finished. Otherwise, I would make a second cron job that runs after this one, which checks the given path for a log file with the correct date stamp, and mails it to me.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job is not running dhirendrs Programming 1 08-25-2010 05:37 AM
Running a Cron Job landysaccount Linux - Newbie 6 02-04-2009 06:29 PM
running cron job as an ordinary user fahad26 Linux - General 1 06-30-2005 04:46 AM
cron job not running vincebs Linux - Software 34 10-30-2004 02:27 PM
Cron job not running? james_cwy Linux - Newbie 6 12-14-2003 09:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration