LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 07-01-2010, 08:05 AM   #1
froxxiieee
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Rep: Reputation: 0
Run script from cron - problem


Hii
Im having some difficulties with running a shell script from cron which I am unable to resolve for almost 2 days now.

For testing purposes, im trying this with simple shell script test.sh with chmod 777
------ test.sh ------
#!/bin/sh
#
echo asdasdasd
------

This script is located at /var
When I type /var/test.sh it runs perfectly and prints asdasdasd
When I type /var/test.sh > /home/log it writes asdasdasd to /home/log - works

The problem occurs whenever I add it as a cron job to var/spool/cron/crontab/root

there is: 11 10 * * * /var/test.sh > /home/log - however, at 10:11 there is no file at /home/log

Cron as a service works, forexample, every day at 4 am it makes this backup
sshpass -p xxxx rsync -avz -e ssh root@x.x.10.7:/data/backup/ /home/backups/isp_admin


However,
13 00 * * * cd /home mkdir asdasd
doesnt makes the folder

Where is the catch?
Thanksssss

Last edited by froxxiieee; 07-01-2010 at 08:39 AM.
 
Old 07-01-2010, 09:00 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,366

Rep: Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910
Hi and welcome to LinuxQuestions!

The syntax is correct and indeed it should work, provided the crontab's owner has permissions to write in /home. You can check three things:

1. see if the cron log actually reports the execution of your job. Usually it is /var/log/cron and you should see an entry like this:
Code:
Jul  1 10:11:02 hostname crond[29083]: (username) CMD (/var/test.sh > /home/log)
2. since you redirect only the standard output to /home/log, the standard error (if any) would be sent to the crontab's owner mailbox. You can check it from a terminal with the mail command.

3. see if the crontab's owner has permissions to run cron jobs. You can check the /etc/cron.deny and /etc/cron.allow files.

In any case, who is the crontab's owner? A regular user or root? And how did you edit the crontab (using the command crontab -e or something else)?

Edit: please note that the mkdir entry is wrong instead. It should be something like:
Code:
0 13 * * * cd /home && mkdir asdasd
or mkdir /home/asdasd.

Last edited by colucix; 07-01-2010 at 09:04 AM.
 
Old 07-01-2010, 09:13 AM   #3
froxxiieee
LQ Newbie
 
Registered: Jul 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
Hi and welcome to LinuxQuestions!

The syntax is correct and indeed it should work, provided the crontab's owner has permissions to write in /home. You can check three things:

1. see if the cron log actually reports the execution of your job. Usually it is /var/log/cron and you should see an entry like this:
Code:
Jul  1 10:11:02 hostname crond[29083]: (username) CMD (/var/test.sh > /home/log)
2. since you redirect only the standard output to /home/log, the standard error (if any) would be sent to the crontab's owner mailbox. You can check it from a terminal with the mail command.

3. see if the crontab's owner has permissions to run cron jobs. You can check the /etc/cron.deny and /etc/cron.allow files.

In any case, who is the crontab's owner? A regular user or root? And how did you edit the crontab (using the command crontab -e or something else)?

Edit: please note that the mkdir entry is wrong instead. It should be something like:
Code:
0 13 * * * cd /home && mkdir asdasd
or mkdir /home/asdasd.
thanks for ur amazing reply!
the problem was that I used winscp and editted var spool cron crontab root file, instead of crontab -e
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using cron to run PHP script GavB Linux - General 7 03-06-2009 12:36 PM
Script not being run in cron.daily hazmatt20 Linux - General 10 10-12-2008 08:24 PM
cannot get tu run a php script in cron alain Linux - General 6 02-06-2006 02:54 AM
FTP Script will not run from Cron grhansen Programming 12 01-13-2006 04:13 AM
can't get cron to run my script. dr_zayus69 Linux - Software 6 04-12-2005 06:34 PM


All times are GMT -5. The time now is 11:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration