3

I tried using crontab -l from my terminal as root, it showed no crontab for root. So I tried crontab -e, it returns the following

no crontab for root - using an empty one 888

and then the cursor starts blinking. I am not able to quit or save the file.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Joker
  • 161
  • What do you mean by “am not able to quit or save the file” — do you mean that you don't know how to, or that you tried and nothing happen? What did you try? You're in an editor, which may be in vi by default, it depends on your distribution. – Gilles 'SO- stop being evil' May 21 '14 at 11:32
  • @Gilles I am using Ubuntu 14.04. ctrl+z stops but I am not able to save the file. What does 888 there indicate? – Joker May 21 '14 at 11:37
  • On ubuntu the default editor is nano, which is very recognizable (it would say GNU nano … on the top line). It looks like the file is being edited in some GUI editor in another window. – Gilles 'SO- stop being evil' May 21 '14 at 18:35
  • @Gilles Only those two lines appear when I give crontab -e nothing else. Be it at the top or at the bottom. – Joker May 22 '14 at 04:38

1 Answers1

4

When you run the command crontab -e it typically defaults to the vi or vim editors. If you type the command Shift+Z+Z you can save any changes in this editor and exit.

To add entries to your crontab using this method you'll need to learn how to use this editor more extensively, which is beyond the scope of this question, and should be easy to find many tutorials on the internet.

If vi/vim is too much of a learning curve you can instruct crontab to use a different editor. Another console based editor that's easier for new people to Linux is nano, it's typically installed on most distros that I'm familiar with.

$ EDITOR=nano crontab -e

NOTE: To use nano's menu all the carets (aka ^X) commands at the bottom require the use of the Ctrl key. So to exit, Ctrl+X, for example.

You can of course use any editor here. A easy GUI based editor, if you're using a GNOME based desktop, would be gedit:

$ EDITOR=gedit crontab -e

This last one might be a challenge to use, for a different set of reasons, if your primary desktop is being run by a user other than root, which it likely is, so I would go with nano for starters.

slm
  • 369,824
  • “Cursor starts blinking” doesn't look like a description of any version of vi. There should be something like /tmp/crontab.wibble: … at the bottom of the screen. Nano is the default editor on Ubuntu, but it maintains 5 lines of screen estate. It looks like some X11 editor was launched. – Gilles 'SO- stop being evil' May 21 '14 at 18:32
  • @Gilles - total guess on my part. – slm May 21 '14 at 19:25
  • The OP's description sounds more like ed - typing q then ENTER should quit. The 888 is the character count of the template /var/spool/cron/$USER file I think. – steeldriver May 21 '14 at 20:07
  • @slm EDITOR=nano crontab -e brought up the editor. I typed @reboot sh -c /path/to/netbeans/netbeans. But on reboot, netbeans did not start. I entered the command as root – Joker May 22 '14 at 05:54
  • The same lines occur when i just give crontab -e – Joker May 22 '14 at 06:15
  • @slm sorry it was EDITOR=nano crontab -e -u user. This actually setup crontab for the user but it did not run netbeans. But the command sh -c /path/to/netbeans/netbeans runs from user terminal and root terminal. – Joker May 22 '14 at 07:01
  • I tried with chromium it did not work. The command I gave is @reboot /usr/bin/chromium-browser. This time i added crontab from user but still on reboot chromium did not start. – Joker May 22 '14 at 07:08
  • @Parthe - @reboot may just not work on your distro: http://unix.stackexchange.com/questions/109804/crontabs-reboot-only-works-for-root/109805#109805 – slm May 22 '14 at 11:03
  • @slm Ya. I got this point at the early stage of my research. Since I was using latest ubuntu version, I thought the problem would have been fixed. Anyways, I want to run a jar file at startup. I am just testing it with firefox command now. I want to get the basic idea about cron and startup programs. If you have any ideas, I started a new question [link]here(http://unix.stackexchange.com/questions/131503/run-a-script-at-startup)[/link] – Joker May 22 '14 at 11:16
  • @Parthe - I always test this feature using writing to a file first. If that works then the @reboot is working. I'm not sure the system will launch GUI's from cron, is there any particular reason you want to do this that way? I would be more inclined to make the launching of a GUI part of a user's startup. – slm May 22 '14 at 11:35
  • @slm As I said, I want to run a jar file at startup. That's my aim here. The jar won't contain any UI, it's just a daemon process running. – Joker May 22 '14 at 12:52