Solved

UNIX (Solaris10) Cron job does not run

Posted on 2011-02-24
6
824 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.
Suggested Courses

739 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