Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding line in crontab from command line...

7,095 views
Skip to first unread message

contr...@gmail.com

unread,
Apr 9, 2008, 2:17:47 PM4/9/08
to

Hi:

Can you tell me if is there any way to make this task ?


00 1 * * * /monitor_file_system 2>/dev/null > crontab

Thank You !

Richard B. Gilbert

unread,
Apr 9, 2008, 2:36:20 PM4/9/08
to

man crontab

I think the -e switch does what you want.

Michael Schmarck

unread,
Apr 9, 2008, 3:22:57 PM4/9/08
to
· contr...@gmail.com <contr...@gmail.com>:

>
> Hi:
>
> Can you tell me if is there any way to make this task ?
>
>
> 00 1 * * * /monitor_file_system 2>/dev/null > crontab

Certainly. This can be done.

My solution would be dump the whole crontab, echo the
line you need and feed all of that back to crontab.

man crontab and man sh for the details.

Michael Schmarck
--
Politics makes strange bedfellows, and journalism makes strange politics.
-- Amy Gorin

Sharif Rizal

unread,
Apr 9, 2008, 4:58:32 PM4/9/08
to

If you are trying to do this manually and know vi,

export EDITOR=/usr/bin/vi
crontab -e

then add your entry then save / quit


If you are trying to do this from a script,
1. dump the content of the existing crontab to a file
# crontab > /tmp/dump
2. echo "your lines" >> to the corntab file
# echo " 00 1 * * * /monitor_file_system 2>/dev/null" >> /tmp/dump
3. import the new crontab
# crontab /tmp/dump

Sharif Rizal

unread,
Apr 9, 2008, 4:59:28 PM4/9/08
to

correction:


1. dump the content of the existing crontab to a file

# crontab -l > /tmp/dump

contr...@gmail.com

unread,
Apr 10, 2008, 2:36:49 PM4/10/08
to
>   # crontab -l > /tmp/dump- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -


Is there any way to issue this command ?

rsh machine01 00 1 * * * /monitor_file_system 2>/dev/null > crontab


I need put this entry in 30 machines...


Thanks...

Sharif Rizal

unread,
Apr 10, 2008, 4:01:47 PM4/10/08
to

You can't send it directly to crontab. If you want to run this cron as
root, you'll need to send it to /var/spool/cron/crontabs/root.
Be careful with the ">". This will overwrite your existing cron
entries. Use ">>" instead! man sh for more details.
Also try these man pages:
cron, crontab

I'm not sure if this will work. Give it a try...
rsh machine ""01 00 1 * * * /monitor_file_system 2>/dev/null" >> /
var/spool/cron/crontabs/root"

Helmut Kreft

unread,
Apr 10, 2008, 5:56:18 PM4/10/08
to
On Thu, 10 Apr 2008 13:01:47 -0700 (PDT), Sharif Rizal wrote:
>
> You can't send it directly to crontab. If you want to run this cron as
> root, you'll need to send it to /var/spool/cron/crontabs/root.
> Be careful with the ">". This will overwrite your existing cron
> entries. Use ">>" instead! man sh for more details.

Solaris cron won't pick up a crontab changed like that until someone
performs a change via crontab or cron is restarted.

Helmut

--
Almost everything in life is easier to get into than out of.
(Agnes' Law)

Andrew Deason

unread,
Apr 10, 2008, 6:27:35 PM4/10/08
to
On Thu, 10 Apr 2008 21:56:18 +0000 (UTC)
Helmut Kreft <kr...@unfug.org> wrote:

> On Thu, 10 Apr 2008 13:01:47 -0700 (PDT), Sharif Rizal wrote:
> >
> > You can't send it directly to crontab. If you want to run this cron
> > as root, you'll need to send it to /var/spool/cron/crontabs/root.
> > Be careful with the ">". This will overwrite your existing cron
> > entries. Use ">>" instead! man sh for more details.
>
> Solaris cron won't pick up a crontab changed like that until someone
> performs a change via crontab or cron is restarted.

Easy enough to issue `EDITOR=touch crontab -e` afterwards.

--
Andrew Deason
adea...@uiuc.edu

Helmut Kreft

unread,
Apr 10, 2008, 7:35:36 PM4/10/08
to

crontab -l | (cat;echo "00 1 * * * /monitor_file_system") | crontab

Andreas F. Borchert

unread,
Apr 14, 2008, 4:27:16 PM4/14/08
to
On 2008-04-10, Helmut Kreft <kr...@unfug.org> wrote:
> crontab -l | (cat;echo "00 1 * * * /monitor_file_system") | crontab

Yup but the cat process can be avoided:

(crontab -l; echo "00 1 * * * /monitor_file_system") | crontab

Andreas.

Helmut Kreft

unread,
Apr 14, 2008, 5:21:23 PM4/14/08
to

Damn... useless use of cat. I have been caught. ;)

Jaga...@gmail.com

unread,
Apr 25, 2008, 2:44:19 AM4/25/08
to
Is there way to JUST append a new line to crontab by program, so that
the other already running cornjobs will function without any
interrupt?

Thanks,
Jagadeesh

Horst Scheuermann

unread,
Apr 25, 2008, 3:40:15 AM4/25/08
to
Jaga...@gmail.com writes:

> Is there way to JUST append a new line to crontab by program, so that
> the other already running cornjobs will function without any
> interrupt?

- running cronjobs are not interrupted by changing the crontab.
- You can add lines to Your /var/spool/cron/crontabs/<user> file with
any programm, but You have to tell the cron-daemon, that the
crontab has changed. This is done by the crontab command.
--
11. Gebot: Wenn Du eine Fahrradklingel hörst, dreh Dich um, reiße
Mund, Nase und Augen auf, trete aber keinesfalls zur Seite.

0 new messages