Solved

Replace Crontab File Syntax ??

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.

813 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

12 Experts available now in Live!

Get 1:1 Help Now