LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (http://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   Editing other users' crontabs with STDIN (http://www.linuxquestions.org/questions/solaris-opensolaris-20/editing-other-users-crontabs-with-stdin-791008/)

Rohaq 02-23-2010 09:30 AM

Editing other users' crontabs with STDIN
 
I want to edit another user's crontab with the output from STDIN. crotnab usage is apparently as follows:

Code:

crontab [file | -e | -l | -r ] [user]
But entering the following pops up with a 'proper usage' error:

Code:

cat test.cron | sudo crontab - username
Similarly, trying to take the input from a file has the same error:
Code:

sudo crontab /tmp/test.cron username
On the other hand, I can edit my own crontab with no problems:
Code:

cat test.cron | crontab
Error for all is as follows:
Code:

crontab: proper usage is:
        crontab [file | -e | -l | -r ] [user]

I've trying to figure out the best way to do this - I want to do it from STDIN, rather than a file, since the command I'll be using outputs to STDOUT by default, however I don't even have the option to take input from a file, apparently!

If anyone could help with this, I would appreciate it.

jlliagre 02-23-2010 11:32 AM

The usage message is misleading. The newer one is better:
Code:

crontab: usage:
        crontab [file]
        crontab -e [username]
        crontab -l [username]
        crontab -r [username]


Rohaq 02-23-2010 11:35 AM

Ah, so basically you can't feed STDIN into a specific user's crontab? That's rather annoying!

Blinker_Fluid 02-23-2010 12:24 PM

Quote:

Originally Posted by Rohaq (Post 3874006)
Ah, so basically you can't feed STDIN into a specific user's crontab? That's rather annoying!

It's probably not the proper way to do it but you could just edit the files directly in /var/spool/cron/crontabs/ and then restart cron...

jlliagre 02-24-2010 12:29 AM

Quote:

Originally Posted by Rohaq (Post 3874006)
Ah, so basically you can't feed STDIN into a specific user's crontab? That's rather annoying!

Crontab doesn't handle stdin when specified as "-" but there are other ways to do it. The simpler would be:
Code:

su username "crontab /dev/stdin"


All times are GMT -5. The time now is 10:21 AM.