Crontab job to run every hour


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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

your crontab syntax look ok, what's the problem with it?
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?
cbonesAuthor Commented:
I receive the error message:

Set environment variable USER
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cbonesAuthor Commented:
I received that message from the log file created.
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.)
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.
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
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.
cbonesAuthor Commented:
I ended up running it out of the inittab and in the script checking for a specific time.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.