0

I have Ubuntu 16.04. From here Run Scripts on Start UP. I followed this answer:

One approach is to add an @reboot cron task:

Running crontab -e will allow you to edit your cron. Adding a line like this to it:

@reboot /path/to/script

will execute that script once your computer boots up.

I was successfully able to edit file crontab.

but I couldn't be able to save it using:

  • :q
  • :wq
  • CTRL+x

None of them worked. I got this message on command :q:

No write since Last Change (add ! to override
  • After executing command - EDITOR=vi crontab -e

    Output - no crontab for admin - using an empty one

  • Again on executing command - sudo EDITOR=vi crontab -e

    Output - no crontab for root - using an empty one

16
  • 1
    If you gat that message with :q, then :wq should work.
    – muru
    Jun 8, 2017 at 4:48
  • Hi, @muru that is my point :wq exit the window but it not save cron file. Jun 8, 2017 at 4:59
  • 1
    If that was your point, then say so in the question. What does crontab -l show after you edit and do :wq?
    – muru
    Jun 8, 2017 at 5:00
  • 3
    @george I get the impression that creating a cron job that causes a reboot may be ill-advised and beyond the current skill level of the OP. Unless the OP's user account is admin I'd be concerned as to what cron he is actually editing. Stuffing something like this in cron is probably not the best thing for an obviously novice user to be doing.
    – jones0610
    Jun 8, 2017 at 5:14
  • 1
    How come it comes preinstalled, use which nano to see if its there. It should be. Jun 8, 2017 at 5:34

2 Answers 2

1

You have done well so far. The No write since Last Change(add ! to override) means you have written something and are closing without saving so the editor assumes you don't wish to save your changes and offers you the option of doing so with :q!. Now you need to use :wq to ensure that the changes are written then the editor is quit or exited.

Where its a nano editor as I noticed crontab uses this please do the following:

  1. To save: Ctrl+o, then press Enter

  2. To close: Ctrl+x

6
  • Hi, @George it shows Not an editor command :qw. Jun 8, 2017 at 4:55
  • Updated the answer, sorry syntax error Jun 8, 2017 at 4:56
  • @UtkarshDubey its :wq not :qw
    – d a i s y
    Jun 8, 2017 at 6:00
  • 1
    Okay sorry i didn't checked edited answer - Your comment syntax error is about :qw
    – d a i s y
    Jun 8, 2017 at 6:27
  • 1
    Thanks a lot @George, It works perfectly on Client other Ubuntu machine which have nano installed. And for 1st machine may be there is something wrong in machine. Jun 8, 2017 at 6:31
0

Having a cron job that causes an unexpected, immediate reboot could cause you frustration and confusion.

If you are convinced that you want to do this, the command to write and exit the editor depends on what editor you selected when you invoked the crontab -e command.

Esc :wq! or Shift ZZ will work for vi

For nano, Ctrl O followed by Ctrl X

2
  • Hi, @jones0610 How to invoke editor? Jun 8, 2017 at 5:02
  • @UtkarshDubey EDITOR=nano crontab -e
    – muru
    Jun 8, 2017 at 5:04

Not the answer you're looking for? Browse other questions tagged .