EzDevInfo.com

crontab interview questions

Top crontab frequently asked interview questions

Can Ubuntu play a video via cron job?

I'm developing a display system for a paint shop.
I've set up a computer with Ubuntu to run the video and display it on a TV, running a PHP script that should update the video every hour via the internet.

The script is set to run via cron, executed once every hour (@hourly). Almost the entire script runs perfectly, but the last line where it executes VLC Media Player to display the video fails silently. If the script is run via command line (php /path/to/cron.php), VLC Media Player starts perfectly. But when it is run in cron, it does not.

The thought I get is, that jobs running via cron simply doesn't have the ability to run applications with a visible GUI, but I really hope that is not the answer.

Please help me crack this one!


Source: (StackOverflow)

cron can't read PYTHONPATH environment variables?

I have added to the PYTHONPATH on my server's .bash_profile file. However it appears that cron isn't reading from it because I am getting import errors. If I run the exact command cron calls on the command line it works, but if I send the error output of cron to a separate file, its failing on the imports.

how can I structure it so that cron is aware of my appended PYTHONPATH


Source: (StackOverflow)

Advertisements

Running program every 2 minutes with crontab

What does

2 * * * *

means in crontab context?

I want to run my program every 2 minutes; is that what 2 * * * * means?


Source: (StackOverflow)

Difference between /etc/crontab and "crontab -e"

What is the difference between the crontab located in /etc/crontab and the crontab that can be edited using crontab -e?


Source: (StackOverflow)

How to execute shell script via crontab?

I have a notify.sh script that looks like:

notify-send "hi welcome"

My crontab notification for 2 PM:

0 14 * * * home/hacks/notify.sh

However, this doesn't work. What is the problem?


Source: (StackOverflow)

Is it possible to use variables in crontab -e?

Can I say:

MYPATH=/root/scripts
MYSCRIPT=doit.sh

0 1 * * * $MYPATH/$MYSCRIPT

in crontab -e ?

Is it possible to use variables in crontab -e ?


Source: (StackOverflow)

how to run cron jobs on GMT not local time?

How can I make cron jobs run on GMT, not local time?

this is my crontab file:

#m  h           d   m   wday    command
TZ=GMT
5   0,6,12,18   *   *   *   ~/Documents/bash/transfer.sh

my jobs seem to be running at the local time (GMT+11) I am running os x snow leopard, but will move the code onto linux when development is complete.

The linux environment may be a shared environment where I may has less control over configuration.


Source: (StackOverflow)

Only email on cron errors for jobs in cron.daily, cron.hourly, etc

I have several cron jobs that run (in /etc/cron.daily, /etc/cron.hourly, /etc/cron.weekly, etc.) and email root@localhost with the results. I'd like to stop those emails if the jobs are succeeding, and only email on error (which I understand can be done by redirecting stdout to /dev/null). I understand how to do that for individual cron jobs, but the scripts in those special directories are run using run-parts. What is the best way to suppress success emails for those scripts?


Source: (StackOverflow)

How do I make crontab generate a unique log each time it runs a job?

Here is the crontab job

/usr/local/bin/python2.7 /home/scripts/script.py >> /home/scripts/logs/log.log 2>&1

How do I generate a new log every time the job is run?

I am cool with adding an increasing counter to the log file each time it is generated. Do not know how to do this.

Do I really have to run another cron job to do that?

Thanks!


Source: (StackOverflow)

Run a cron job on the first Monday of every month?

I'd like to run a job from cron at 8.30 on the first Monday of every month. The cron Wikipedia page says

While normally the job is executed when the time/date specification fields all match the current time and date, there is one exception: if both "day of month" and "day of week" are restricted (not "*"), then either the "day of month" field (3) or the "day of week" field (5) must match the current day.

(my emphasis)

Does that mean I can't do the first Monday of the month, I can only do the first (or whatever) day of the month? I can't think of a way round it.


Source: (StackOverflow)

If I schedule a cron job to run at midnight, will it run at the start or end of the day?

If I schedule a cron job to run at midnight on a specific day, will the job run at the beginning of the day, or at the end of the day? For example:

# Runs at midnight on 20th February:
0 0 20 2 *

Source: (StackOverflow)

Run a command every week with Cron?

Simple question- what would a crontab entry look like for a command I want to run every week on Saturday at 8:05 AM?


Source: (StackOverflow)

Multiple crontabs for one user

is there a way to use multiple crontab files for one user? Thinking something along the lines of crontab file per project instead of crontab per user...

Any help is appreciated...


Source: (StackOverflow)

Cronjob runs before the scheduled time, what could be wrong?

I have below crontab scheduled for Saturday that falls between days 19-23, I' m not sure why it ran on 20th (Friday). Any guesses?

00 21 19-23 * 6 <command>

Source: (StackOverflow)

Run a cron job every 5 minutes between two times

Is there a way to specify a job that runs every 5 minutes between some start time and some end time on business days in a crontab?

Update I think it's relevant that my start and end times are not at round hours. So, specifying 9-5 in the hour column isn't enough. I want 9:30-17:30.


Source: (StackOverflow)