How to read cron log ?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to read cron log ?
# 1  
Old 09-28-2015
How to read cron log ?

Hi everyone,

I have set up a cron job and it ran as i have expected, however, i unable to determined whether it was executed by a regular user (rml5723 in this case) or by root. My intention was for it to run as root (notice the 's' bit set on the script), the script itself is owned by the regular user. As you can see per below cut/paste from /var/adm/cron/log, its command was executed but i am not able to determine who actually ran the script. I have been looking for documentation that might explain how to read this cron log but unable to find anythinng, your help is greatly appreciated.


Code:
>  CMD: /home/rml5723/testcron > /home/rml5723/logs
>  rml5723 6768 c Mon Sep 28 11:30:00 PDT 2015
<  rml5723 6768 c Mon Sep 28 11:30:01 PDT 2015


$ whoami
rml5723

$ pwd
/home/rml5723
$ ll
total 16
-rwsr-xr-x   1 rml5723    users           38 Sep 28 10:01 testcron
-rw-rw-rw-   1 rml5723    users            0 Dec 15  2014 testing


root@some_server[/var/adm/cron]
# cat cron.allow
root
rml5723


$  cat testcron
ll /home/rml5723 
echo "HELLO"

$ crontab -l
5,10,15,20,25,30 0 * * * /home/rml5723/testcron > /home/rml5723/logs

$ cat logs
total 32
-rw-r--r--   1 rml5723    users            0 Sep 28 11:30 logs
-rwsr-xr-x   1 rml5723    users           31 Sep 28 11:20 testcron
-rw-rw-rw-   1 rml5723    users            0 Dec 15  2014 testing
-rw-r-----   1 rml5723    users           31 Sep 28 11:20
HELLO

Thanks!
# 2  
Old 09-28-2015
Quote:
Originally Posted by rachael
My intention was for it to run as root (notice the 's' bit set on the script), the script itself is owned by the regular user.
Sticky-bits don't work on scripts.

Even if they did, it wouldn't run a user-owned script as root, but as the user that owns it. Otherwise anyone could create a script that would run as root.

If you want something in crontab to be run as root, I suggest telling cron so by putting it in root's crontab. This has the advantage that you're not opening the door for anyone to run that script as root, you're only permitting cron to do it.

Another way to manage this would be using sudo.

Last edited by Corona688; 09-28-2015 at 07:16 PM..
# 3  
Old 09-28-2015
Hello Corona688,

Thanks for your quick response. Our internal syst admin policy is we don't put application cron jobs in root's crontab, we separate them. Maybe i did not mention earlier, i put this cron job in the regular user's (rml5723 in this case) cron tab.

So if I provide this user sudo privs, i'd remove the 's' bit, and then keep the job in its user's crontab but how would i integrate the below sudoers with cron? It will need to run weekly.

The syntax in the sudoers file would be like

Code:
# Host alias specification
Host_Alias SERVERS=abc124

# User alias specification
User_Alias   Developer=rml5723

Developer  SERVER = (root) NOPASSWD:/home/rml5723/testcron

Again thanks!

Rachael

Last edited by jim mcnamara; 09-29-2015 at 05:07 AM..
# 4  
Old 09-28-2015
Instead of doing /path/to/script.sh, you'd do sudo /path/to/script.sh Otherwise you can use the line you had.
# 5  
Old 09-28-2015
Hi Corona688,

Do you mean put the below line in the user's crontab?

Code:
sudo /path/to/script.sh

Thanks,

Rachael

Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 09-29-2015 at 05:08 AM..
# 6  
Old 09-29-2015
suid-root is not the correct method (and neither the suid-root sudo)!
What OS do you have?
Code:
uname -sr

# 7  
Old 09-29-2015
Quote:
Originally Posted by rachael
Hi Corona688,

Do you mean put the below line in the user's crontab?

Code:
sudo /path/to/script.sh

No. I meant the line you had before, with 'sudo script' instead of 'script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Log error from cron job into log file

Hi Please would it be right to log the errors from a script running in cron in the following manner: /datax/vendor/dump.sh > /datax/vendor/err.log 2>&1 (16 Replies)
Discussion started by: fretagi
16 Replies

2. UNIX for Dummies Questions & Answers

How are cron.allow and cron.deny read?

Hi, all! I was working on my Debian, minding my own business but then I wanted to see what happened if the same user was included on both cron.allow and cron.deny :p I would have bet that cron.deny was going to override cron.allow for security reasons, but my computer proved me wrong:... (3 Replies)
Discussion started by: pereyrax
3 Replies

3. Shell Programming and Scripting

How to read log files from last read

Hi i am looking a way to look at a log file(log.txt) from the last time I've read it. However after some days the main log file(log.txt) is rename to (log.txt.1). So now i will have two log files as below. log.txt.1 log.txt Now, i have to read the log from the point where i have left... (3 Replies)
Discussion started by: sumitsks
3 Replies

4. Shell Programming and Scripting

Cron Log file

Hi Iam new to unix .please help me in writing a script.Suppose there are 100 scripts in a cron file which are scheduled to run at different times,different dates . I need to monitor all the scripts daily whether they ran or not if ran whether its sucessfully ran or not . if the script hasnt... (2 Replies)
Discussion started by: mskalyani
2 Replies

5. UNIX for Dummies Questions & Answers

How to change the log level for cron?

Hello, I'm wondering how to change the log level to level 2 for cron without manually have to restart it with every boot. I didn't thing this would be hard to find, but searching has cause me to come up empty. System is Ubuntu Karmic/9.10 With thanks, Narnie (6 Replies)
Discussion started by: Narnie
6 Replies

6. Shell Programming and Scripting

cron job issue..i hav read the basic threads already...

hi friends well m facing a different sort of issue in my cron. i hav set job like this 30 09 * * 1 /bin/backup14M 01 14 * * 1 /bin/backup14N 20 18 * * 1 /bin/backup14E that is for every Monday at three different times. but, first job executes well, later ones do not. I checked my... (13 Replies)
Discussion started by: oracle.test2
13 Replies

7. UNIX for Dummies Questions & Answers

Regarding Cron log creation

Cameron, I have deleted the cron log file and create a new cron log file as the older was sucking up the disk space. now i have rescheduled the cron job but i dont see any logs on the newly created log file. I am confused what has happened. Can u help me out on this. (0 Replies)
Discussion started by: sanei05
0 Replies

8. AIX

AIX and cron logs filtering ?: /etc/cronlog.conf, /var/adm/cron/log

Hi, I can use 'crontabs –e' and do all the scheduling I like. However I would like to auto send myself just the cronjobs logs that fail. That is to say the PIDs that fail and the related lines with those PID’s only. (Not the full set of logs) Has anyone done this work? Or does an AIX 5.3 tool... (0 Replies)
Discussion started by: Keith Johnson
0 Replies

9. UNIX for Dummies Questions & Answers

Cron log entries

Hi, I am confused with the entries in my cron log, I'm not sure what exactly these commands are doing, any body can show me the way to get understanding of what these entries mean:> CMD: $TFADMIN /usr/lib/uucp/uudemon.poll > /dev/null > CMD: $TFADMIN /usr/lib/uucp/uudemon.hour > /dev/null > ... (1 Reply)
Discussion started by: nervous
1 Replies

10. Shell Programming and Scripting

adding date to cron log

Hi. I'm trying to output the current date to a cronjob log file. Nothing seems to work, echo $(date), echo `date` or just date in the script. I'm using /sbin/sh Any ideas? Thanks, John (2 Replies)
Discussion started by: JohnH
2 Replies
Login or Register to Ask a Question