How to save a crontab???

In Konsole, I type:

sudo crontab -e

then I had created a new crontab,
Ex:

30 00 * * * shutdown -P 3 "shutdown"

but I couldn’t save new crontab???
Can you help me???
Thanks :slight_smile:

The way I have always created/edited crontabs was to create a file with the crontab information using any editor, such as vi. Save the file and then type

crontab <filename>

where <filename> is the path/name of the file you created. That will “compile” the entries into the cron table.

I’m currently at a hp/ux machine, but I’m assuming it’s similar on linux. According to the man page, the crontab files are located in /var/spool/cron/crontabs. The name of your crontab (which is what you’re attempting to edit by using the -e parameter) is essentially your username.

My guess is that if you’re unable to save, you may not have “write” privileges on the file. You may want to su to root and then try it. I’ve found that “sudo” does not give you full root privileges. It only allows you to execute certain commands. Therefore, sudo will allow you to run the crontab command, but it doesn’t give you extra privileges on files or directories. In those cases you will have to use su rather than sudo.

The crontab editor is “vi” by default so to exit hit “escape” and then “ZZ”.

I’m confused, how did you manage to insert text without knowing any “vi” commands?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Why couldn’t you save? What did you try? You’re in ‘vi’ most likely so
just hit ‘escape’ and then the following:

:wq

Once done it should be saved. You can also use the following instead of :wq:

ZZ

Good luck.

quangtrung1789 wrote:
> In Konsole, I type:
>
> Code:
> --------------------
> sudo crontab -e
> --------------------
>
> then I had created a new crontab,
> Ex:
>
> Code:
> --------------------
> 30 00 * * * shutdown -P 3 “shutdown”
> --------------------
>
> but I couldn’t save new crontab???
> Can you help me???
> Thanks :slight_smile:
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJKoAYQAAoJEF+XTK08PnB5edoQAKLRkzZhPduVDDXLinAY+0Px
YXwx357UsmmyClVRGkdVaiBj1tBfFSITkBIVRBBUApmuRlMfFZ7eiUVYzPXp0v9P
1LjJ5us6TIX9t+JGrYmze7pU6ae0MeuRRYMkGdRqlo/YBABZHu+XZ5yESXqzZrNr
CKpeodj0hscw1ojcLvCU/DEhuHjhUk+WSJo6yaNk1nQD4Dub05r++wlI2f5J/9zY
f8jycwaOMZw3iLM23k+deRH2kLDsdT7CcjW70BShtsXA4c1IsLctX6Yhu6cSRWFi
M/5PAQlzHLywbcoMspHuF62ddREVeMq75O9CIFJOqufk7bDlQpzUa1A5OCvg4hXP
NRphT6AZIeiPnO+EZAly5jZkWIXQwQeYgGJXAzl4czfS6AjaEpHJ7enpljIfn6mz
TwgKXwc8t8qiEpkF3MVMEfUQifTePAImihX0eNkPOD1cFXzBvl2pVs3sLyfk7PwA
Ybkm5ocxR+M47aLTvaq09o1YvGPQhQgsX/pJgxP2uxKXuW2sbDe4ouTvD0R3yIt2
ysTjYHBhku/t1c3tnIQwDI0ZxXd3UZLRbBoDJTyi/lQMWgLBW9DynkAzKXSC48Xo
Ebe2/pie/F3pV00l+ltla7pd4a6fU1ncWvSYAW2cGqoNZ6EH6AhKVxByXUcViG5m
Mh/QHA9vVHKtw0v0glCF
=9/jU
-----END PGP SIGNATURE-----

That creates problems. ‘crontab -e’ edits the crontab of the user who invokes it.

Sorry… that may be true. I’ve never used -e

I quite like the way you suggested, which I didn’t know about.

oh, I don’t really understand what you show :expressionless:
can you give me a example, I think I will understand more :expressionless:
Thanks :slight_smile:

Again.
When you use crontab -e you are editing using an editor called **vi (**or **vim **in its latest incarnation).

You then type** i **which is the command to enter insert text mode.
You then type your text (the crontab entry in this case).
Then you hit the Esc key to leave text mode.
Now you type a : This : will show in the lower left hand corner of the terminal emulator.
Now you finish with the characters wq and Return, this will write to disk and quit
v
i.

HTH.

And try to find some information about vi/vim. It is not the user friendliest editor (to make an understatement), but some knowledge comes handy doing basic sysadmin work like this.

The crontab file requires the last line to be a blank line or else it won’t save. Did you add a blank line?

oh, i will do it step by step :expressionless: (sorry for a new user :slight_smile: )

tuanquoc@linux-bmyp:~> su -
Password:
linux-bmyp:~ # crontab -e

and,
http://upnhanh.sieuthinhanh.com/userimages/images/sieuthiNHANH2009090424636yjy3ote2ow40751.jpeg
then I press Esc and + to quit this crontab.
this is result:

linux-bmyp:~ # crontab -e
no crontab for root - using an empty one

[1]+  Stopped                 crontab -e
linux-bmyp:~ # crontab -l
no crontab for root
linux-bmyp:~ #

I don’t understand :frowning:

On Thu, 03 Sep 2009 19:36:02 +0000, hcvv wrote:

> then I press Esc and <Ctrl>+<Z> to quit this crontab.

There’s your problem - you’re just suspending the editor by using CTRL
+Z. Use the keystrokes “ZZ” (ie, two capital Zs) to save and exit.

Jim


Jim Henderson
openSUSE Forums Moderator

Who talked about <Ctrl>+<Z>?
I have seen two methods (that are equivalent) mentioned above: :wq and ZZ. No Ctrl key there.

With <Ctrl>+<Z> you tell the shell to run something in the background. And that is the place where the

[1]+  Stopped                 crontab -e

is coming from. It is your background job #1 that finished!

Edit: Ok Jim, you were first :wink:

You can use your favourite GUI editor (maybe Kate, Kwrite, Gedit, Leafpad, whatever) rather than the power-user editors like Vi etc. Simply open the hidden file .bashrc in your home folder/directory and add one of these lines into it:

  • for Gedit in Gnome add this line:
 export EDITOR=/usr/bin/gedit
  • for Kwrite in KDE4 add this line:
export EDITOR=/usr/bin/kwrite
  • for Kate in KDE4 add this line (I think – can’t remember):
export EDITOR=/opt/kde3/bin/kate

Then you can edit the normal way when you invoke cron with the command “crontab -e”.

For future users who happen by, there’s a tutorial on Cron/Crontab in openSUSE here: Cron Tables (Crontab) in Suse / openSUSE [Event Scheduler for 10.x, 11.x]

Afterthought: If you want to use your favourite GUI editor when you edit the cron table as root, then you place the relevant line (one of the lines in the post I made above) into a text file that you name as “profile.local” and place into the directory /etc. Then log out and log back in and the root editor will be automagically changed to your favourite GUI editor too.

On Thu, 03 Sep 2009 20:16:01 +0000, hcvv wrote:

> is coming from. It is your background job #1 that finished!

Actually, “Stopped” doesn’t mean finished, it means “paused in the
background”. ie, not running, but still an active process. :slight_smile:

> Edit: Ok Jim, you were first :wink:

:slight_smile:

Jim

Jim Henderson
openSUSE Forums Moderator

You are of course correct, but I doubt that these finer details are of any use to the OP.

On Thu, 03 Sep 2009 20:56:01 +0000, hcvv wrote:

> You are of course correct, but I doubt that these finer details are of
> any use to the OP.

Perhaps, perhaps not; it seems that the “stopped” message may have been
the source of the confusion for the OP.

Jim


Jim Henderson
openSUSE Forums Moderator