?
Solved

Crontab job to run every hour

Posted on 2013-01-31
10
Medium Priority
?
610 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 600 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 600 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

840 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