1826215 Members
2819 Online
109691 Solutions
New Discussion

Cron job behaviour

 
ikbea
Frequent Advisor

Cron job behaviour

Hi all,

I have some questions cron job behaviour:

Question 1
==========
For directory
/home/appl mode: 777 owned by appluserA:applgroup

appluserB (same group of appluserA), create /home/appl/file, mode:640, owned by appluserB:applgroup

a. appluserA telnet to server, rm /home/appl/file
it returned "640 mode (y/n)?"

b. appluserA uses cron job "rm /home/appl/file", it removed without any warning/question

Why cron job can remove file without "rm -f" option ?

Question 2
==========
In directory /home/appl,
a. telnet and create file /home/appl/file, mode is 666
When run umask, it showed 00

b. Use cron job to create file /home/appl/file,
mode is 644
When run umask, it showed 022

Why the umask is different ? Where to set the global umask ?

I just know cron job is difference from telnet as cron job is not "logged on" to server, so /etc/profile and .profile are not called.

Thanks
3 REPLIES 3
Emanuele_4
Regular Advisor

Re: Cron job behaviour

I'm not so sure but...

Question 1) Cron jobs run as root user...so they can delete files bypassing permissions.

Question 2) you have to check .profile files

When you make telnet you have to check the profile of the user who makes telnet (umask setting in user profile .profile)...when you use cron job you have to check the global setting.../etc/profile and set umask in this file.

I hope to help you.

Emanuele
BONNAFOUS Jean Marc
Trusted Contributor

Re: Cron job behaviour

Hi,

1) Cron jobs have the rights of the user who execute the job. If rm command is using in a root cron job, it's normal that files are removed without -f option because root has all permissions on files.

2) For security reasons, no user profile is read by cron job. You can set ENV variables into scripts separately. If you want to read a profile you must specify it:
a) in the script or
b) on each line in cron file:
* * * * * . YourProfileFile ; YourCronScript

Rgds
JMB
Si vous ne faites jamais de bétises, c'est que vous ne faites rien de difficile. Et ça c'est une grosse bétise.
Michael Schulte zur Sur
Honored Contributor

Re: Cron job behaviour

Hi,

the following is a quote from man rm

greetings,

Michael

If a user does not have write permission for a file to be removed and standard input is a terminal, a prompt containing the file name and its permissions is printed requesting that the removal of the file be confirmed (see Access Control Lists below). A line is then read from standard input. If that line begins with y the file is deleted; otherwise, the file remains. No questions are asked when the -f option is given or if standard input is not a terminal