Solved

Crontab job to run every hour

Posted on 2013-01-31
10
605 Views
Last Modified: 2013-02-04
Hello,

I have a script that I want to run every hour of the day, 7 days a week.

I tried this:

0 * * * * /home/user/script-to-run

Any help would be appreciated.

Thank you.
0
Comment
Question by:cbones
  • 4
  • 3
  • 3
10 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 38841444
your crontab syntax look ok, what's the problem with it?
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 38843221
Try this, to see whether your script is generating any output or error messages:
0 * * * * /home/user/script-to-run 2>&1 >> /home/user/script_to_run.log

Open in new window

This will create (and add) output and error messages of your 'script-to-run to a log file in your home directory.

Is the cron daemon running btw? Try to find out:
ps -ef | grep cron

Open in new window

what do you get?
0
 

Author Comment

by:cbones
ID: 38843446
I receive the error message:

Set environment variable USER
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 150 total points
ID: 38843535
>> Set environment variable USER

Where do you get the error? In the logfile?

When running scripts from cron - assume no variables are set. You should set variables in the script yourself or include some script that does it for you.
0
 

Author Comment

by:cbones
ID: 38843551
I received that message from the log file created.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 38843590
the script started by cron has a minimal environment, you need to ensure that every variable you use there is properly defined, also keep in mind that the PATH variable is set very restrictive, best you use a full absolute path to all progarm calls (even system ones like ls, etc.)
0
 

Author Comment

by:cbones
ID: 38844949
Where would you set the environment variable for the user?  In the script file?

When I type 'env' to view the environment variables, I see the USER variable set.

Thank you.
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 150 total points
ID: 38845157
why would you need this environment variable, if the cronjob is started by that user?
I recommend that you install that cronjob for the user you want to do the work
however, some cron export the LOGNAME envoronment variable
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 38845434
Can you post (part) of the script that has the USER variable reference? You can either set the variable or replace with the correct path.
0
 

Author Closing Comment

by:cbones
ID: 38851576
I ended up running it out of the inittab and in the script checking for a specific time.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question