build crontab from a text file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers build crontab from a text file
# 1  
Old 03-27-2009
build crontab from a text file

We are reorganizing our UNIX Crontab file by first making changes in a word pad text file. The intent is to then copy it back to Crontab. Will this work? Copy and Paste does not seem to work.
# 2  
Old 03-27-2009
From the crontab man page -
Code:
        crontab [file] 
                                 Create or replace your crontab file by
                                   copying the specified file, or standard
                                   input if file is omitted or - is
                                   specified as file , into the crontab
                                   directory, /var/spool/cron/crontabs.  The
                                   name of your crontab file in the crontab
                                   directory is the same as your effective
                                   user name.

So, something like this:
Code:
cat mynotepadfile | crontab -

mynotepadfile will have to have ALL of the entries needed from the old crontab, because this wipes all of the lines in the existing crontab file.
# 3  
Old 03-27-2009
Quote:
Originally Posted by jim mcnamara
From the crontab man page -
Code:
cat mynotepadfile | crontab -

mynotepadfile will have to have ALL of the entries needed from the old crontab, because this wipes all of the lines in the existing crontab file.
I would recommend using dos2unix to ensure no errant CRLF (^M) make it into the file.
Code:
dos2unix mynotepadfile | crontab -

# 4  
Old 03-27-2009
One way is to work on the crontab file in another existing directory (e.g. /home/myuser/crontabs).
For example (for root crontab).
cd /home/myuser/crontabs
cp /usr/spool/cron/crontabs/root root
cp /usr/spool/cron/crontabs/root root.270309
Then you can use vi to edit the file called root. Within vi the ":r filename" function is the easy way to import a block of lines from a file called filename).
After reviewing your new crontab, submit it with "crontab root".
Using this method if you find that you have made an editing error, you still have a copy of the original crontab.
# 5  
Old 03-27-2009
I always follow this process to update the crontab file to make sure I can recover. Also remember no blank lines in crontab. Also I agree with tpietschmann if your not familiar with VI and your using a Windows editor run dos2unix on the file prior to updating crontab.
Code:
# # backup your current crontab file
export backup_date=`date +20%y%m%d-%H%M%S`
crontab -l > backup/crontab.${backup_date}
# # create a copy of the crontab to edit
crontab -l > backup/crontab.out
# # make the edit to create the new crontab file
vi backup/crontab.out
# # this will request crontab to run using this new command file
crontab backup/crontab.out
# # output crontab to validate your updates
crontab -l

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Windows & DOS: Issues & Discussions

(VS 2008) New build config looking files from other folder build config

Hi Team, My new build configuration always looking for the files from the build where i copied from. please help me to resolve this. I am using Visual studio 2008.It has Qt 4.8. plugins,qml,C++ development I created new debug_new build configuration with additional preprocessor from the... (1 Reply)
Discussion started by: SA_Palani
1 Replies

3. Shell Programming and Scripting

Build.xml invocation by Build Script

Hi I have a build.xml file and I can run it on Windows via cmd. Now I want to write a script to invoke the same. Is there a way to do this? (1 Reply)
Discussion started by: ankur328
1 Replies

4. UNIX for Dummies Questions & Answers

Adding SDK Build on Kernel Source Build

Hi, So I downloaded this kernel source and was able to build it successfully. But I want to add this SDK source code inside, can anyone help me how to do this? Note that the SDK source can be built by itself. I added the SDK in the main Makefile: init-y := init/ #added SDK... (0 Replies)
Discussion started by: h0ujun
0 Replies

5. Shell Programming and Scripting

crontab not creating text file

while running the following code in ssh crontab, Its running successfully but its not creating text file IFC1.txt, file1.txt, file2.txt while running manually its working. please help me #!/bin/ksh hostname > file1.txt 2>/dev/null hostname >> file1.txt 2>/dev/null sudo df -h | grep... (2 Replies)
Discussion started by: elango963
2 Replies

6. SuSE

g++ build on SUSE 12.1, cannot open included file

Hello, I have a project that I have compiled on a number of linux systems including CentOS, Ubuntu, and Windows Cygwin. I am trying to build the project under SUSE 12.1. The make file runs allot of the way through, but then throws an error that an included file can't be opened. This is the... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

7. Shell Programming and Scripting

Need to build Shell Script to search content of a text file into a folder consist several files

Have to read one file say sourcefile containing several words and having another folder containing several files. Now read the first word of Sourcefile & search it into the folder consisting sevral files, and create another file with result. We hhave to pick the filename of the file in which... (3 Replies)
Discussion started by: mukesh.baranwal
3 Replies

8. UNIX for Dummies Questions & Answers

Build and display a file

What is the command to build and display a file in one step? ----------- cat myfile ----------- i need something better then cat. (3 Replies)
Discussion started by: oxoxo
3 Replies

9. Ubuntu

How to build as web base File Server

Hi folks, Ubuntu 7.04 server amd64 apache2-2.2.3 postfix-2.3.8 mysql Ver 14.12 SquirrelMail version 1.4.11 I have a running Mail Server. I need to make it as a file server, in addition, allowing users who have accounts (Linux/shell) on the Mail Server to upload/download their files... (1 Reply)
Discussion started by: satimis
1 Replies
Login or Register to Ask a Question