Solved

Replace Crontab File Syntax ??

Posted on 2011-09-27
5
640 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 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
can i read my emails on lamp ftp 4 67
Apache LDAP Authentication 20 71
Shrink Linux Swap File Size CentOS 10 66
Krita v3 Linux Mint/Ubuntu 16.04 9 69
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

738 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