?
Solved

Replace Crontab File Syntax ??

Posted on 2011-09-27
5
Medium Priority
?
673 Views
Last Modified: 2012-05-12
Hello Experts

Scenario:

1. FTP-ed Crontab from Solaris server.
2. Edited crontab off-line using a Unix text editor (Metapad)
3. FTPed back to Solaris server to a "home" folder.

I need to replace the existing crontab with the edited file. I have done this before quite some time ago and need to verify the syntax.

I believe it was

filename > crontab


...or something similar.

Please check / verify.

Thanks!
 





 
 
0
Comment
Question by:kboles101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Expert Comment

by:Eoin Ryan
ID: 36711057
I'd be sure to check the /var/spool/cron/crontabs/ folder itself before doing an overwrite.

I've seen the folder "crontabs" but never a file called that. usually within the folder there are files to change and edit depending on what you want run when.

while your command will write filename to another file called "crontab" to me it looks a bit odd, but that's what it'll do if you want it to.
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36711911
The location of crontab files varies due to different Linux distribution.
For RedHat/CentOS/Fedora, it is
/var/spool/cron/

For Ubuntu/Debian, it is
/var/spool/cron/crontabs/

Say for root user, the crontab file is
/var/spool/cron/root  (or /var/spool/cron/crontabs/root)

You can backup them up first before your override them
cp  -pr /var/spool/cron   /path-to-backup-dir/

0
 
LVL 4

Expert Comment

by:Anacreo
ID: 36712079
Just do:

crontab filename

That will overwrite your current crontab file...

If you want you could create a self fulfilling crontab of sorts:

--- updatecron.sh ----
#!/bin/sh

if [ -e newcron ]; then
  crontab newcron
  rm newcron
fi

---inside newcron ---
# Auto-Update Cron from FTP file...
* * * * * updatecron.sh

# Other cron entries here:
0 * * * * hourly.sh
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 2000 total points
ID: 36712456
you need to be careful while trying to edit the file and ftping it back, it should be ftped back in text or ascii mode

once this is done, the do the following steps

- save the current crontab file

crontab -l > mycron

- use the new crontab file e.g mynewcrontab

crontab mynewcrontab

- verify it

crontab -l

0
 

Author Closing Comment

by:kboles101
ID: 36891808
This is the procedure we used; the extra verification step is very prudent. Thanks all.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question