LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-15-2013, 09:36 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Cronjob not running, however script it calls works ok


I have a cronjob that runs apt-get automatically for Ubuntu 12.04 LTS x64 bit, which all lives as a guest in VirtualBox.

The cronjob is ran as root, however the script that it calls is under a regular users' home directory.

I am able to execute the script from CLI and it updates a log ok. However I'm not sure where the error lies with the cronjob not kicking it off automatically. I have checked /var/log/apt and don't find any entries and I also monitor top to see if the apt process kicks off, and adjust the cronjob's time and watch top and still nothing.

Here is some more info

cronjob
Code:
root@ubuntu64vm:~# crontab -l
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
 00 21 * * * root ./home/cmmiller1973/scripts/aptupdate
Permissions of the script
Code:
root@ubuntu64vm:/home/cmmiller1973/scripts# ls -al
total 12
drwxrwxr-x  2 cmmiller1973 cmmiller1973 4096 Sep 15 08:29 .
drwxr-xr-x 32 cmmiller1973 cmmiller1973 4096 Sep 15 21:31 ..
-rwxrw-r--  1 cmmiller1973 cmmiller1973  114 Sep 15 08:29 aptupdate
Script
Code:
root@ubuntu64vm:/home/cmmiller1973/scripts# cat aptupdate 
#!/bin/bash 

(apt-get update && apt-get -y -d upgrade) > /var/log/aptupdate.log

apt-get clean 

>/dev/null 2>&1
 
Old 09-16-2013, 12:57 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
probably the dot:
00 21 * * * root ./home/cmmiller1973/scripts/aptupdate
you must use full path in crontab, try remove that dot
 
Old 09-16-2013, 12:33 PM   #3
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
I took out the "." and still didn't run.

I'm going to add a time/date stamp to the script and try to re-run it...
 
Old 09-16-2013, 01:50 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Try to remove the word "root" before the command. I suspect it is interpreted as the command to run and it should result in a "command not found" error. Have you checked the root's mailbox (with the mail command) to see if the cron job sent an error message?
 
Old 09-16-2013, 07:51 PM   #5
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
That worked, cronjob ran successfully.

Not sure where I got the idea to put root in front of the path. I tried to find the URL again for that example, and can't find it.

thanks
 
Old 09-16-2013, 11:36 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The user name is required in system crontab, /etc/crontab and /etc/cron.d/*, where a job can be used for any user. Instead the user's crontab (root included) can be used only from the user to which the crontab belongs, hence the username is not needed.
 
  


Reply

Tags
cron, crontab, ubuntu


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script not running through cronjob? NotAComputerGuy Linux - Newbie 28 07-10-2013 12:51 PM
[SOLVED] Cronjob - Shell Script Not Running rcrosoer Linux - General 5 05-22-2013 07:35 AM
script not running in cronjob dningale Solaris / OpenSolaris 2 08-14-2008 12:27 AM
script expression not running in cronjob dningale Solaris / OpenSolaris 2 08-13-2008 12:04 AM
cronjob not working but script works dtra Linux - Newbie 4 02-28-2005 05:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:38 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration