LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 06-21-2015, 07:29 AM   #1
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 658

Rep: Reputation: 35
Question Cron job not running as root?


Hello

The following script runs fine when ran manually (as root), but it fails writing a file into /usr/share/nginx/acme/stuff/.

Here's the script:
Code:
/etc/cron.hourly# cat download_bash
#!/bin/bash

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
OUTPUT=/usr/share/nginx/acme/stuff/index.html

#This file is successfully created
echo "cron job running at `date`" > /tmp/testcron

NOW=$(date +"%A %d-%m-%Y %T")
echo "$NOW" > $OUTPUT

#No trace of this file in $OUTPUT :-/
wget -i list.txt -qO - | grep -Pzo 'some.pattern' >> $OUTPUT

sed -i 's@/local@http://www.google.com/local@g' $OUTPUT
Here's the destination directory:
Code:
# ll /usr/share/nginx/acme/stuff/
drwxr-xr-x 2 nobody nogroup   4096 Jun 21 14:20 ./
drwxr-xr-x 7 nobody root      4096 May 14 02:08 ../
-rw-r--r-- 1 root   root    106640 Jun 21 14:20 index.html
And here's Debian's crontab file:
Code:
# cat /etc/crontab

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Could it be that cron/run-parts doesn't run scripts as root, although that's what it says in /etc/crontab? No information is provided in /var/log/messages.

Thanks for any help.
 
Old 06-21-2015, 12:26 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
The script might not be able to find the file list.txt when running in cron. Try giving the full path name for list.txt.

---------------------------------
Steve Stites
 
Old 06-21-2015, 02:20 PM   #3
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 658

Original Poster
Rep: Reputation: 35
Bingo!

Moral of the story: Make sure all files can be found, either through the PATH line or absolute paths.

Thank you.
 
  


Reply



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
Cron Job Not Running - Looks Like Cron Tried Noble User Linux - Newbie 7 10-26-2014 10:26 AM
Is the cron job always running root? johnifanx98 Linux - Newbie 4 03-01-2012 12:10 PM
Cron Job is not running akshathajagadish Linux - Newbie 2 10-15-2009 07:21 PM
Running a Cron Job landysaccount Linux - Newbie 6 02-04-2009 05:29 PM
cron job not running vincebs Linux - Software 34 10-30-2004 01:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 01:08 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