Solved

UNIX (Solaris10) Cron job does not run

Posted on 2011-02-24
6
818 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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…
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.:
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…

820 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