Operating System - HP-UX
1834187 Members
2480 Online
110064 Solutions
New Discussion

Re: Need Helpl in setting the cronfile

 
SOLVED
Go to solution
kumar_choudhury
Occasional Advisor

Need Helpl in setting the cronfile

Hi,

I want set some cron files for different users. I have all the new cron files as username.new for all the users. So I want to set the new cron file using root. But
crontab [file_name] will set the cron file for current user, can you please help me setting the new cron file, login as a root"
8 REPLIES 8
MarkSyder
Honored Contributor

Re: Need Helpl in setting the cronfile

How about:

su - username
crontab file_name

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Ivan Krastev
Honored Contributor

Re: Need Helpl in setting the cronfile

Also add users in : /var/adm/cron/cron.allow


regards,
ivan
Peter Godron
Honored Contributor

Re: Need Helpl in setting the cronfile

Hi,
rename the username.new to username into /var/spool/cron/crontabs directory.
chmod 400 /var/spool/cron/crontabs/username
Add user to crontab.allow

All as root
Peter Nikitka
Honored Contributor

Re: Need Helpl in setting the cronfile

Hi,

I have a trick for this - but never tried this under HP-UX. Facts:
- The crontab command uses the value of the env-variable EDITOR to set a user specific editor.
- The crontab call 'crontab -e usrnam' edits the cron-entry of 'usrnam' (if called by root user).

Now use:
for cronfile in *.new
do
usrnam=${cronfile%*.new}
cat $cronfile | EDITOR=/usr/bin/tee crontab -e $usrnam
done

This will both print the content of the file to stdout and the temporary crontab-file without the need of further input.

Better perform a test with one file first ...

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
SANTOSH S. MHASKAR
Trusted Contributor

Re: Need Helpl in setting the cronfile

I think Peter Gordon's solution is most
suitable

U can do that like this as root

first add username in /var/adm/cron/cron.allow

then run following

for Users in user1 user2 . . .
do
cp ${Users}.new /var/spool/cron/crontabs/${Users}
chown root:users /var/spool/cron/crontabs/${Users}
chmod 400 /var/spool/cron/crontabs/${Users}
done

thats all

-Santosh Mhaskar
kumar_choudhury
Occasional Advisor

Re: Need Helpl in setting the cronfile

Thanks,

I Have some cronfiles like root, sys, adm etc, I want to replace this cronfile with my new cron file with .new as the extension. Please give me a solution for this. (I have two versions of cronfiles for different users I want to replace old version of cron with my new version of cronfile with .new as the extension)

Peter Nikitka
Honored Contributor
Solution

Re: Need Helpl in setting the cronfile

Hi,

my solution will do exactly that.
For a single file use:
cat username.new | EDITOR=/usr/bin/tee crontab -e username

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
kumar_choudhury
Occasional Advisor

Re: Need Helpl in setting the cronfile

Thanks All