Solved

Crontab job to run every hour

Posted on 2013-01-31
10
599 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 37

Expert Comment

by:Gerwin Jansen
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
 
LVL 37

Accepted Solution

by:
Gerwin Jansen 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 37

Expert Comment

by:Gerwin Jansen
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
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…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now