Solved

Replace Crontab File Syntax ??

Posted on 2011-09-27
5
614 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
5 Comments
 
LVL 6

Expert Comment

by:Eoin
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux Mint 18 31 73
Redirect on SBS hosted web not working from linux based browsers 3 72
Python variable _ manually assigned 9 63
Choosing CentOS 16 50
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now