Solved

Replace Crontab File Syntax ??

Posted on 2011-09-27
5
604 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:EoDawg
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
This is the procedure we used; the extra verification step is very prudent. Thanks all.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
AWS EC2 Linux 1 28
How to clone Linux server? 15 62
Write an app 10 60
Replace Ubuntu Desktop with Ubuntu Server 7 41
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…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

762 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

5 Experts available now in Live!

Get 1:1 Help Now