Solved

UNIX (Solaris10) Cron job does not run

Posted on 2011-02-24
6
802 Views
Last Modified: 2012-06-22
I have a Cronjob (Created by root user) which does not run:
#Crontab -l:
30 * * * * /usr2/.../myDir/MyCron.cron >/dev/null 2>&1
#cd /usr2/.../myDir/
#ls -ltr
-rwxrwxrwx   1 root     root         315 Feb 24 02:01 MyCron.cron
# cat MyCron.cron
/usr2/cedat/bin/.../xc > /usr2/copytemp/mysql/staging/changes1.txt
/usr2/cedat/bin/.../yc > /usr2/copytemp/mysql/staging/changes2.txt

If I run the cronjob myself, it works:
#/usr2/.../myDir/MyCron.cron
THe above command works perfectly.

Why the cron is not running automatically?
0
Comment
Question by:toooki
  • 2
  • 2
  • 2
6 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 225 total points
ID: 34978125
Hi,

1) do you indeed have a directory "..."?

2) What is "xc" supposed to do? I only know xc as an X-based graphical editor, which will not run under cron, since there is no terminal available, let aside X11.

If it's something else I assume that this pogram needs some environmental settings (variables) not available under cron (the user's initialization files like $HOME/.profile are not executed!).
So I'd suggest setting the full environment in MyCron.cron, perhaps by sourcing an available configuration file.
Another option is running the script from root's crontab (seems that you're doing this already) with "su - -c ..." like

30 * * * * su -  >/dev/null 2>&1 -c "/usr2/.../myDir/MyCron.cron"

wmp
0
 
LVL 8

Expert Comment

by:JIEXA
ID: 34987563
Maybe, because of different environment variables (like PATH) in crond (which runs crontabs) and your login shell.
0
 

Author Comment

by:toooki
ID: 34989888
Thank you all for the help.
The owner of the files used in cronjob is root. And I created the cronjob as root.
Sorry there is no "xc" command ( I only tried to abbreviate)

I tried:
#/bin/sh
#

But the matter is -- this was working before.. I made cosmetic changes a bit in the script but can't remember which change made it to fail.

I am not familiar with:
30 * * * * su -  >/dev/null 2>&1 -c "/usr2/cedat/bin/rpt/MyCron.cron"

My all other cron jobs work but this one fails (does not run).
Is there any location where any cron error logs are found?
I did not make any changes to the .profile file since it was working before.


# id
uid=0(root) gid=0(root)
#Crontab -l:
30 * * * * /usr2/cedat/bin/rpt/MyCron.cron >/dev/null 2>&1
#/usr2/cedat/bin/rpt/MyCron.cron
Above command runs perfectly and does the job.
#cd /usr2/cedat/bin/rpt/
#pwd
/usr2/cedat/bin/rpt
# cat MyCron.cron
/usr2/cedat/bin/rpt/MyCron.cron1c > /usr2/copytemp/mysql/staging/changes1.txt
/usr2/cedat/bin/rpt/MyCron.cron2c > /usr2/copytemp/mysql/staging/changes2.txt
#pwd
/usr2/cedat/bin/rpt
#ls -l
-rwxrwxrwx   1 root     root         315 Feb 24 02:01 MyCron.cron
-rwxrwxrwx   1 root     root         156 Jan 14 15:18 MyCron.cron1c
-rwxrwxrwx   1 root     root         153 Jan 14 15:31 MyCron.cron2c
#pwd
/usr2/cedat/bin/rpt
#cat MyCron.cron1c
#!/bin/sh
/usr/bin/mysql -h abc.xxx.com -u myLogin -pMypwd mydb << -EOF
select * from mytab1;

#cat MyCron.cron2c
#!/bin/sh
/usr/bin/mysql -h abc.xxx.com -u myLogin -pMypwd mydb << -EOF
select * from mytab1;

Open in new window

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 8

Assisted Solution

by:JIEXA
JIEXA earned 225 total points
ID: 34990191
Crontab logs may be located at /var/log/cron*.
But I see that the syntax "document is here" (<< STRING) is not complete. The files should look like these:

#cat MyCron.cron1c
#!/bin/sh
/usr/bin/mysql -h abc.xxx.com -u myLogin -pMypwd mydb << -EOF
select * from mytab1;
-EOF

#cat MyCron.cron2c
#!/bin/sh
/usr/bin/mysql -h abc.xxx.com -u myLogin -pMypwd mydb << -EOF
select * from mytab1;
-EOF

Also, there is probably some environment variable that is missing when run from crontab, like MYSQL-something.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34997057
OK,

the end-of-file markers for the "here" documents are indeed missing. But please use

EOF

without the dash ( - ). The dash in << -EOF is used to indicate that EOF does not have to appear in the first column,
i. e. that spaces or TABs in front of it should be allowed.

wmp



0
 

Author Comment

by:toooki
ID: 35023738
It actually worked after I added #!/bin/sh
at the beginning og the file MyCron.cron
Thank you for your help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.

747 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

13 Experts available now in Live!

Get 1:1 Help Now