EzDevInfo.com

cron interview questions

Top cron frequently asked interview questions

How do you run a crontab in Cygwin on Windows?

Some cygwin commands are .exe files, so you can run them with the standard Windows Scheduler, but others don't have an .exe extension so can't be run from DOS (it seems like).

For example I want updatedb to run nightly.

How do I make cron work?


Source: (StackOverflow)

How to specify in crontab by what user to run script?

I have few crontab jobs that run under root, but that gives me some problems. For example all folders created in process of that cron job are under user root and group root. How can i make it to run under user www-data and group www-data so when i run scripts from my website i can manipulate those folders and files?

My server runs on Ubuntu.
Current crontab job is:

*/1 * * * * php5 /var/www/web/includes/crontab/queue_process.php >> /var/www/web/includes/crontab/queue.log 2>&1

Source: (StackOverflow)

Advertisements

cron that will run a ruby script every day at midnight

I heard crontab would be a good choice but how do i write this line and where do i put it on the server


Source: (StackOverflow)

How to get a unix script to run every 15 seconds?

I've seen a few solutions, including watch and simply running a looping (and sleeping) script in the background, but nothing has been ideal.

I have a script that needs to run every 15 seconds, and since cron won't support seconds, I'm left to figuring out something else.

What's the most robust and efficient way to run a script every 15 seconds on unix? The script needs to also run after a reboot.


Source: (StackOverflow)

Specifying "all odd values" in crontab?

In crontab, I can use an asterisk to mean every value, or "*/2" to mean every even value.

Is there a way to specify every odd value? (Would something like "1+*/2" work?)


Source: (StackOverflow)

Running cron job on linux every 6 hours

How can I run command every six hours every day? Tried this not working :

/6 * * * * *  mycommand

Source: (StackOverflow)

Run Cron job every N minutes plus offset

*/20 * * * *

Ensures it runs every 20 minutes, I'd like to run a task every 20 minutes, starting at 5 past the hour, is this possible with Cron? Would it be:

5/20 * * * * ?


Source: (StackOverflow)

How can I programmatically create a new cron job?

I want to be able to programatically add a new cron job, what is the best way to do this?

From my research, it seems I could dump the current crontab and then append a new one, piping that back into crontab:

(crontab -l ; echo "0 * * * * wget -O - -q http://www.example.com/cron.php") | crontab -

Is there a better way?


Source: (StackOverflow)

Python: how to set virtualenv for a crontab?

I want to set up a crontab to run a Python script.

Say the script is something like:

#!/usr/bin/python
print "hello world"

Is there a way I could specify a virtualenv for that Python script to run in? In shell I'd just do:

~$ workon myenv

Is there something equivalent I could do in crontab to activate a virtualenv?


Source: (StackOverflow)

Google App Engine - Task Queues vs Cron Jobs

The latest Google App Engine release supports a new Task Queue API in Python. I was comparing the capabilities of this API vs the already existing Cron service. For background jobs that are not user-initiated, such as grabbing an RSS feed and parsing it on a daily interval. Can and should the Task Queue API be used for non-user initiated requests such as this?


Source: (StackOverflow)

A cron job for rails: best practices?

What's the best way to run scheduled tasks in a Rails environment? Script/runner? Rake?


Source: (StackOverflow)

What is the Windows version of cron?

A Google search turned up software that performs the same functions as cron, but nothing built into Windows.

I'm running Windows XP Professional, but advice for any version of Windows would be potentially helpful to someone.

Is there also a way to invoke this feature (which based on answers is called the Task Scheduler) programatically or via the command line?


Source: (StackOverflow)

Restarting cron after changing crontab file?

Do I have to restart cron after changing the crontable file?


Source: (StackOverflow)

How to create cronjob using bash

Does crontab have an argument for creating cronjobs without using the editor (crontab -e). If so, What would be the code create a cronjob from a bash script?


Source: (StackOverflow)

How do I write a bash script to restart a process if it dies?

I have a python script that'll be checking a queue and performing an action on each item:

# checkqueue.py
while True:
  check_queue()
  do_something()

How do I write a bash script that will check if it's running, and if not, start it. Roughly the following pseudo code (or maybe it should do something like ps | grep?):

# keepalivescript.sh
if processidfile exists:
  if processid is running:
     exit, all ok

run checkqueue.py
write processid to processidfile

I'll call that from a crontab:

# crontab
*/5 * * * * /path/to/keepalivescript.sh

Thanks in advance.


Source: (StackOverflow)