How do I fix my crontab after a username change?

1

I recently changed my username, and I can't seem to access my crontab now:

% crontab -e
crontab: no crontab for blackl - using an empty one

I thought I'd just edit the one I had under my old username, copypaste the jobs to the new one, and then use crontab -r to remove the old one.

% sudo crontab -eu olduser
crontab: user `olduser' unknown

Oops.

I dug around a bit and found where the crontabs are stored (/usr/lib/cron/tabs) and copied my old one out of there. The first line, though, is this:

# DO NOT EDIT THIS FILE - edit the master and reinstall.

It seems to me that for whatever reason, manually removing the old crontab with something like sudo rm /usr/lib/cron/tabs/olduser would be a bad idea. What is the correct way to do this?

Blacklight Shining

Posted 2012-10-22T06:38:39.313

Reputation: 2 127

Answers

3

[root@localhost cron]# pwd
/var/spool/cron
[root@localhost cron]# ll
total 4
-rw------- 1 root     root   0 Jul 13 12:06 root
-rw------- 1 max      max    20 Oct 22 12:22 max

Here particular users crontabs are stored.

This is the content of man usermod

-l, --login NEW_LOGIN
           The name of the user will be changed from LOGIN to NEW_LOGIN. Nothing else is changed. In particular, the user´s home directory name should probably be changed manually to
           reflect the new login name.

Here clearly mentioned that Nothing else is changed so the file under /var/spool/cron will not be updated, because this file will be created while creating user account (path may vary in your system)

just rename this file to your new username.

After that type crontab -l it will list your old crontab also.

you are telling that this is not the correct method right?

If i get any other method i will update my post.

max

Posted 2012-10-22T06:38:39.313

Reputation: 3 329

Is it as simple as renaming the crontab file? I'm wary of doing anything like that manually because of the warning on the first line of the file. I'm not saying your other answer was incorrect, just that it didn't answer my question. :P – Blacklight Shining – 2012-10-22T07:52:36.940

As an aside, I didn't use usermod (as a matter of fact, OS X doesn't seem to /have/ a usermod). I just logged in using a temporary account, opened Users & Groups Preferences, right-clicked on my account, chose Advanced Options…, and updated the Account name and Home directory fields. I then used mv to rename my home directory and rebooted. This seems to have worked for the most part; that was a few weeks ago and this is the only trouble I've had with it so far. – Blacklight Shining – 2012-10-22T08:02:51.613

@BlacklightShining I don't no about os x. so sorry... – max – 2012-10-22T08:21:32.703