Solved

UNIX (Solaris10) Cron job does not run

Posted on 2011-02-24
6
827 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
[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
  • 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
Independent Software Vendors: 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 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

Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

728 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