first time cron user

Hi all, I am trying to set up a cron job. I have written my bash script which works well on its own.

when I enter crontab -e, nano opens up a new file for me to edit. i put my line in and go to save it

00 22 * */2 * /path_to_script

(10pm every 2 weeks I hope)

My question is, nano by default wants to save it to the tmp folder. I’m pretty sure that it should not go there. If I try to save it to any etc/cron folder, I need root permissions to save it there.

Does it need a special filename or extension?
If I save it to etc/cron…, won’t this then be a system job, not a user job?
So where do I save it for a user job?
Is the line above the only line I need?
Can I enter multiple lines in one file for each job I want processed?

hi,

has the command been tried,
crontab -u <username or root> -e

this will open up vi/vim (unless changed from default)
then input your script

on writing and closing vi/vim, your script will be placed in /var/spool/cron/tabs/<username>

root privileges needed

full spec is,
crontab -u user] -l | -e | -r] [file]

hth

nb.
typical file :-

# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.jVu6HB installed on Fri Nov 15 16:07:34 2013)
# (Cronie version 4.2)
SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin
MAILTO=root
#
# intialised 15-Nov-2013
#
*/15 * * * * /home/<username>/bin/tcpu

Using

crontab -e

(or other crontab calls without the -u <user> spec) will handle the user’s crontab.
The -u <user> spec. is only there when you want the crontab of another user, which is of course only allowed by root (and of course when root does not use -u <user> it will manage root’s crontab).

The OP did not specify if he does do this a s root or not, and thatis also noot his question.

To the OP. I do not know nano (in my environment crontab -e will use vi), but are you sure that it is stored in /tmp. It should store it in the correct place, not to be defined by you, It is even is gross error to change the place where it should be stored. It should go in the correct place, even if you do not know where taht is.

On 2013-12-18 23:46, vserghi wrote:
>
> Hi all, I am trying to set up a cron job. I have written my bash script
> which works well on its own.
>
> when I enter crontab -e, nano opens up a new file for me to edit. i put
> my line in and go to save it
>
> 00 22 * */2 * /path_to_script
>
> (10pm every 2 weeks I hope)
>
> My question is, nano by default wants to save it to the tmp folder. I’m
> pretty sure that it should not go there. If I try to save it to any
> etc/cron folder, I need root permissions to save it there.

Don’t you bother where nano saves it. You have not control of it, the
“crontab -e” command controls it, not nano, nor you.

When the edit is accepted, then it is copied over to the right place,
which is not etc, but “/var/spool/cron/tabs/”. Do not try to directly
edit the files in there.

> Does it need a special filename or extension?

Don’t try. Again, “crontab -e” uses the right name, not under your control.

> If I save it to etc/cron…, won’t this then be a system job, not a user
> job?

That is not done by “crontab -e”.

> So where do I save it for a user job?

Just use “crontab -e” and forget. Don’t try to change the name it uses.

> Is the line above the only line I need?

Maybe. Depends what you need. I have:


SHELL=/bin/bash
MAILTO="cer"

> Can I enter multiple lines in one file for each job I want processed?

Of course.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

I have been calling crontab under my own user credentials, not su or root.

As for using nano, I don’t use or like vi/vim, so my default text editor is nano. When I go to save the file with my additions as posted above, the file path is defined as “/tmp/crontab.random_letters

When I try to save to /var/spool/cron/tabs/<username>, I get a permission error. When I try to open the folder in Dolphin, it states it could not enter the cron folder.

However, when I do save it, the file is created somewhere else not in /tmp/. I’m guessing the tmp folder is just a temp place to store it until it is moved somewhere else. I can’t find it in any of the cron folders in the etc folder.

Using crontab -l shows me the file I just created, and I get mail come through as well.

I think I had some confusion with the “/tmp/” folder in nano.

Thanks for the help.

On 2013-12-19 13:16, vserghi wrote:
>
> I have been calling crontab under my own user credentials, not su or
> root.
>
> As for using nano, I don’t use or like vi/vim, so my default text editor
> is nano. When I go to save the file with my additions as posted above,
> the file path is defined as “/tmp/crontab.-random_letters-”

Yes.

> When I try to save to /var/spool/cron/tabs/<username>, I get a
> permission error.

Yes.
I told you not to try.

> When I try to open the folder in Dolphin, it states it
> could not enter the cron folder.

Absolutely correct.

> However, when I do save it, the file is created somewhere else not in
> /tmp/. I’m guessing the tmp folder is just a temp place to store it
> until it is moved somewhere else.

Yes.

> I can’t find it in any of the cron
> folders in the etc folder.

You looked for the wrong name. It is saved as “username”.

> Using crontab -l shows me the file I just created, and I get mail come
> through as well.

Yes.

>
> I think I had some confusion with the “/tmp/” folder in nano.

Absolutely! :slight_smile:


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

On Thu, 19 Dec 2013 12:16:02 +0000, vserghi wrote:

> However, when I do save it, the file is created somewhere else not in
> /tmp/. I’m guessing the tmp folder is just a temp place to store it
> until it is moved somewhere else. I can’t find it in any of the cron
> folders in the etc folder.

That’s not where it goes. It goes in /var/spool/cron/tabs/

Don’t worry about it saying it’s saving it in /tmp. crontab -e takes
care of making sure the crontab is placed properly when it exits - that’s
why you use that rather than opening the crontab in your editor directly.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

Guys, thanks for your help.

My script is working great as well as getting email notifications coming through. I configured Kmail to read the mail file created by cron, so now I get notifications in there instead of having to call mail in the command window.

The reason I ask about its location is for backup reasons. I don’t want to lose this info.

On 2013-12-20 22:16, vserghi wrote:

Oops. I did not notice this post till today, sorry.

> The reason I ask about its location is for backup reasons. I don’t want
> to lose this info.

Ah, that’s different. They are in “/var/spool/cron/tabs/”, one file per
user. Well, those users that created any cronjobs, that’s it.

Just do not directly edit those files :slight_smile:


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

When it is for backup reasons, then as a user that maintains his/her own crontab, that user is also responsable for the backup of it. As a user I would do a

crontab -l >saved-crontab

or the like. Then the copy would be in my user area (home directory) and thus subject to the same backup mechanism as all of my user data.

As a system manager, you might feel responsible for the crontabs and thus might feel that /var/spool/cron/tabs/ should be included in your system backup. In fact on my systems the whole of /var is made a backup of.