Solved

UNIX (Solaris10) Cron job does not run

Posted on 2011-02-24
6
807 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
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 
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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now