Crontab job to run every hour

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.
cbonesAsked:
Who is Participating?
 
Gerwin Jansen, EE MVETopic Advisor Commented:
>> 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
 
ahoffmannCommented:
your crontab syntax look ok, what's the problem with it?
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
cbonesAuthor Commented:
I receive the error message:

Set environment variable USER
0
 
cbonesAuthor Commented:
I received that message from the log file created.
0
 
ahoffmannCommented:
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
 
cbonesAuthor Commented:
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
 
ahoffmannCommented:
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
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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
 
cbonesAuthor Commented:
I ended up running it out of the inittab and in the script checking for a specific time.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.