Editing crontab of non-root user from file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Editing crontab of non-root user from file
# 1  
Old 08-22-2011
Editing crontab of non-root user from file

Hi All,

Ref: "build crontab from a text file" in same forum. (I am not allowed to post URL's in the first post)

We are reorganizing our UNIX Crontab file by first making changes in a word pad text file. The intent is to then copy it back to Crontab. Will this work? Copy and Paste does not seem to work.

From the crontab man page -

Code:
Code:
 
crontab [file] Create or replace your crontab file by copying the specified file, or standard input if file is omitted or - is specified as file , into the crontab directory, /var/spool/cron/crontabs. The name of your crontab file in the crontab directory is the same as your effective user name.

So, something like this:


Code:

Code:
cat mynotepadfile | crontab -mynotepadfile

will have to have ALL of the entries needed from the old crontab, because this wipes all of the lines in the existing crontab file.
-----------------------------

My script does many actions as root. A part of this script is to add a new crontab entry for a normal user.

I used this method and now need to transfer "mynotepadfile" to crontab of "myuser". But the method "crontab [file]" only works for the user invoking it. So this will edit root's crontab, but not someone else's. At the same time, the whole script cannot be executed as non-root.

How would the syntax "cat mynotepadfile | crontab -" change?

Thank you.
# 2  
Old 08-22-2011
It'd be better just to edit it on the UNIX system with crontab -e -- typing text into a black window really isn't that different than typing text into a white one.

If you insist on a solution that edits in windows, you don't need to redirect the file into crontab when you give it a file name:

Code:
crontab filename

Be very very sure that you're not giving cron a file filled with garbage carriage returns after you've edited it on windows! Windows text files are not the same as UNIX ones, Windows uses \r\n in the CPM/DOS tradition.
# 3  
Old 08-23-2011
Hi Corona688,

Thank you for your reply.

But I did a mistake by referring another thread, as I created an impression that I am working in Windows. There is no Windows system in the picture. I would like to clarify the situation. The system runs on AIX. I referred to the thread because I got this when I searched a solution for this issue.

My requirement is to run a script as root, which adds a job to a normal user's cron file.
But the constraints are:
1)Other portions of the script needs root privileges. So normal user cannot execute it.
2)It is not possible to manually edit cronfile, because this and other steps should be part of a big script that would be executed on a number of systems.
3)Root cannot give the command
Code:
cat /tmp/tmp_cronfile | crontab -

(where /tmp/tmp_cronfile contains the text to add the job to the normal user's cron file)
because this command ends up in changing root's cron file and not the normal user's cron file.

The command
Code:
crontab filename

will also not help for the same reason.

My question is how to modify the above command in such a way that it modifies a normal user's cron file, even while running as root.
Is it something to do with the -l or -u flags of the crontab command?

Thanks again.
# 4  
Old 08-23-2011
Yes, -u tells it the user.

You can't just add text to a crontab with - because that will replace the entire cron table.

All these questions and more can be more rapidly answered by reading man crontab.

Last edited by Corona688; 08-23-2011 at 12:13 PM..
# 5  
Old 08-24-2011
Hi Corona688,

I asked for help as I didnt get a clue on the syntax if the user is other than invoking user.

Thanks.
# 6  
Old 08-24-2011
-u user
# 7  
Old 08-25-2011
Yes I understand it is -u for another user Smilie. But my question was about using this syntax in this particular case, i.e within a script?.

Anyway, thanks for your help Corona688 Smilie .
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Root and non-root user not able to delete the file

Hi!! one strange problem occurred with my RHEL 5 box. i'm having logs folder with ownership of non-root user. Created some files with root user under logs folder. here is the scene: -rw-r----- 1 root root 1048227 Feb 28 12:34 SystemOut_13.02.28_12.34.10.log -rw-r----- 1 root root ... (6 Replies)
Discussion started by: sukhdip
6 Replies

2. Solaris

Bad user root in crontab

Hi everyone, I got error which is "!bad user (root)" in crontab... I tried changing password, I checked etc/cron/cron.allow and cron.deny, And also I checked the permissions of my files, its(my crontab script) still not working.... Please help... (12 Replies)
Discussion started by: ijustneeda
12 Replies

3. UNIX for Dummies Questions & Answers

Sudo to delegate permission from non-root user to another non-root user

I've been through many threads before i decide to create a separate thread. I can't really find the solution to my (simple) problem. Here's what I'm trying to achieve: As "canar" user I want to run a command, let's say "/opt/ocaml/bin/ocaml" as "duck" user. The only to achieve this is to... (1 Reply)
Discussion started by: canar
1 Replies

4. Shell Programming and Scripting

Editing crontab via ksh

Hi all, I am trying the following I am hoping that the crontab would be changed. but it prints the previous crontab and says Can anyone tell me the correct ksh command that should be used here? I don't want to edit the crontab with crontab -e, I need to edit it via ksh. Thank... (2 Replies)
Discussion started by: ajaba
2 Replies

5. Fedora

editing crontab help

I'm using fedora 5 and sql 5.0. I'm trying to edit the crontab to perform automatic backups of my database. For some reason it isn't working. Here is what I have so far. 15 2 * * * /usr/bin/mysqldump -opt -all-databases u root -ppassword -h localhost... (10 Replies)
Discussion started by: randerson21
10 Replies

6. UNIX for Dummies Questions & Answers

Editing a cron file with crontab

I want to set up a file with crontab to run the cron deamon so I can use at to schedule jobs. I think the crontab file (or whatever you call it) has to be set up. Currently, I don't have a crontab file (I checked by typing sudo crontab -u myusername -l), and I don't know the syntax for creating... (6 Replies)
Discussion started by: Ultrix
6 Replies

7. UNIX for Dummies Questions & Answers

If user has own crontab, results in accumulation of root CRON processes

Hello, I seem to be having a problem with accumulation of root CRON jobs occuring when I have a user's cron job(s) running. Here is an example of a user's crontab file: */1 * * * * echo "hello" > /dev/nullps aux|grep CRON root 14333 0.0 0.0 91236 2172 ? S ... (12 Replies)
Discussion started by: Narnie
12 Replies

8. AIX

Crontab cannot run by non-root user

Good morning everybody. I have just receiedv a complaint from our DBA saying that if he create a scripts to run some Oracle performance scripts using crontab and the scheduling part is ok but the job is failed when I checked on /var/adm/cron/log. I have tried his scripts using Oracle id directly... (4 Replies)
Discussion started by: kwliew999
4 Replies

9. UNIX for Dummies Questions & Answers

Possible to give non root user sudo to "crontab -l"

Does anyone know if this is possible? I want to give some users access to root's crontab but only with a read privilege. Is this possible to do or can only root or people with full root sudo view root's cron? (4 Replies)
Discussion started by: LordJezoX
4 Replies

10. Shell Programming and Scripting

Editing Crontab

Hi I am not able to edit crontab. Following is the comand that is being issued $crontab -e 2764 ............ This is what I am able to see But when I do $crontab -l List of all the crontab entry is displayed. Also I am seeing one entry in my /etc/cron.d prw------- 1 root ... (6 Replies)
Discussion started by: pankajkrmishra
6 Replies
Login or Register to Ask a Question