-2

I am new to servers and I want to setup cron. I want to check if cron is running on the server. To do that I use the following command.

crontab -l

I looked on Google for a command to check what is set to run in crontab. This is the command I think I should use.

crontab -u root -e

When I do that I get an editor. A picture of the editor is provided in the following screenshot.

ssh

I pasted the command below.

5 * * * * root /bin/sh /var/www/mour/cron.sh

Now I am stuck. How do I save the crontab?

1
  • 1
    On the screenshot you provide the default editor is vi which you can save by pressing "esc" then colon + wp it will look like this :wp
    – chojayr
    Mar 31, 2016 at 14:58

3 Answers 3

0

So this actually isn't a question about crontab, more so a question about your text editor. If you're just checking which crons are on running on your machine run the crontab -l command like you did.

If you want to actually edit the crontab file to, say, add or remove a cron, you can crontab -e. And then depending on your OS or your settings, it may ask you which text editor you want to use or it may default to one. Not 100% sure, but the screenshot you provided looks like the editor might be vim. If it is, after you are done editing the file, you can save and quit the file by entering :wq

1

To "check" if cron is running, that's very much depends on your OS (since you didn't provide that information, I'll provide these two: RHEL6 - service crond status, RHEL7 - systemctl status crond. To check which cronjobs are scheduled, you should use -l, like this:

$ crontab -l
* 12 * * Tue    /root/backup.sh
$ 

To learn more about VIM, read Vim documentation : vim online. You might also want to explore other editor(s), if VIM is too complicated for you.

0

First of all to edit the cron use command

crontab -e

In your case you are using vi editor

to edit the text use i

use esc to exit editing mode, and press :x to save and exit, :x! is used to save forcefully.

incase you dont want to save and wants to exit without saving use :q and :q! is used to exit forcefully.

To check the cronjob what you have scheduled use command

crontab -l

To check whether it is executing properly or not you can the check the logs of cron jobs. Location of cronlogs is

/var/log/cron

use command

cat /var/log/cron 

In your case use

cat /var/log/cron | grep cron.sh 
4
  • press :x to save and exit, :x! does not seems work do i need to press ctrl +x
    – mdeveloper
    Apr 1, 2016 at 5:40
  • just need should i use : 5 * * * * /bin/sh /absolute/path/to/magento/cron.sh or */5 * * * * /bin/sh /absolute/path/to/magento/cron.sh
    – mdeveloper
    Apr 1, 2016 at 6:04
  • First press esc to exit the editing mode. After that press :x to save and exit. Apr 1, 2016 at 14:03
  • for your second query you need be pretty clear so that i can evaluate. Apr 1, 2016 at 14:04

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