Solved

Crontab job to run every hour

Posted on 2013-01-31
10
607 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

717 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