#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    15
    Rep Power
    0

    Replicating a crontab from one UNIX system to another one


    What is the most efficient and easy way to create a crontab from another one, on a UNIX platform (no Windows machines involved)?

    I want to replicate an existing crontab from a test system and copy it over to the development system.

    I am using "crontab -e" on both systems in a vi environment. Currently I am copying and pasting one line at a time, minus the last character of the line and typing that. If the line is so long that it wraps around to another line, then I am typing the last bit of the line and the first bit of the next line, then copying and pasting the rest of the line minus the last character and typing that.

    Why, you might ask? Well, I seem to get syntax errors otherwise and I do not know if I have any kind of debugging tool. However, this is not a short file.

    I get a syntax error trying to copy and paste within the test file itself, so it's not a question of the difference between the systems, just simply when trying to save the file. My UNIX book did not even mention using ZZ to save the file. I do have access to Safari Online at work.

    Suggestions?
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,247
    Rep Power
    9400
    So you just need to copy the file? Try something like SCP. Worst case, grab a USB drive and manually copy the file that way.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    15
    Rep Power
    0
    Originally Posted by requinix
    So you just need to copy the file? Try something like SCP. Worst case, grab a USB drive and manually copy the file that way.
    What is SCP? I do not even know where the file is located. I use the "crontab -e" command and there it is. I use :w! then the filename I used for a backup of the information to write the information to a file for safekeeping.

    Someone mentioned looking at /var/cron, so I will try looking there.

    Also, someone mentioned the following command to edit out what may be the problem with line feed characters:
    :1,$s/^V^M//g

    They called the caret the control key at one point and an escape character at another point. I believe they meant to literally type the above command. However, I saw no ^M at the end of the lines after copying and pasting.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,247
    Rep Power
    9400
    - I don't know what ^V is, but ^M is a line ending character. If you were seeing it then that would mean the file has Windows-style line endings (which would be weird for the crontab file).

    - crontab -e edits the crontab file. It's generally in /etc but could be somewhere else. That's what you'd want to copy. Your distro might have other crontab locations, like /etc/cron.daily or cron.monthly; you might want those too.

    - SCP lets you copy files across systems when you have SSH access to both. Google it.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    15
    Rep Power
    0
    I do not see any ^V or ^M when using "crontab -e".

    I can look in those locations for the saved file.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,477
    Rep Power
    1752
    There is alos the option of using crontab -l to list the cronfile, and redirecting the output to a file which you could copy across if you are not sure where the cronfiles exits. A man crontab should tell you the location of the files.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  12. #7
  13. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    859
    Rep Power
    388
    Follow SimonJM instructions:
    Code:
    crontab -l >cron.txt
    scp cron.txt otherHost:/`pwd`
    
    ## login to otherHost
    ssh otherHost
    crontab -e <cron.txt
    Good luck!

IMN logo majestic logo threadwatch logo seochat tools logo