Need to know why crontab -e fails


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to know why crontab -e fails
# 1  
Old 12-12-2016
Bug Need to know why crontab -e fails

Code:
more cron.txt
1 * * * * /u/ways.sh 2>&1 >/dev/null

Code:
bash-4.1$ export EDITOR=vi
bash-4.1$ crontab -e <cron.txt
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: Finished.
The crontab file was not changed.
bash-4.1$ echo $?
1

Code:
bash-4.1$ uname -a
SunOS mymac 5.11 11.2 sun4v sparc sun4v


Can you please explain why my crontab failed to add the entry in the cron.txt file.
# 2  
Old 12-12-2016
crontab -e is made for interactive input, and so is vi.
Two reasons for
Code:
crontab -e

No redirection from a file. In vi you can load the file with command
Code:
:r cron.txt

--
For non-interactive input from a file - without vi - you can do
Code:
crontab < cron.txt

that will replace the whole current crontab.
For non-interactive adding of crontab entries you can do
Code:
(crontab -l; cat cron.txt) | crontab

# 3  
Old 12-12-2016
Tools

Code:
(crontab -l; cat cron.txt) | crontab

This is what i was looking for ... but can i prevent it to append any entry from cron.txt into the crontab that is already present in the crontab ?
# 4  
Old 12-13-2016
grep out the existing entries!
For example grep out all the exact entries
Code:
(crontab -l | fgrep -vxf cron.txt; cat cron.txt) | crontab

---------- Post updated at 12:03 ---------- Previous update was at 12:02 ----------

If you want to regularly check for update, it is advisable to only replace the crontab if a change happens.
Code:
addto=$(
crontab -l | nawk 'FILENAME=="-" {A[$0]; next} !($0 in A)' - cron.txt
)
if [ -n "$addto" ]
then
  (crontab -l; echo "$addto") | crontab
fi

In theory you can also do a process substitution
Code:
addto=$(
fgrep -vxf <(crontab -l) cron.txt
)

but I have seen temporary malfunction in Solaris.
These 3 Users Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

2. Shell Programming and Scripting

Script won't fails when running from crontab

Hi, My script runs fine from the command line, but when crontab tries to launch it encounters lack of permissions: could not open /dev/kbd to get keyboard type US keyboard assumed could not get keyboard type US keyboard assumed split: Permission denied This is the head of the script: ... (2 Replies)
Discussion started by: Cvg
2 Replies

3. Programming

SFTP fails from crontab but works from terminal

Dear community, I'm driving crazy with a strange issue. I have a simple script to transfer a file to a remote system:#!/bin/bash echo "put /tmp/server.log" > /tmp/server1_transfer.sftp sftp -b /tmp/server1_transfer.sftp user@10.99.1.2:Between client and server there is a SSH KEY, so if I run... (15 Replies)
Discussion started by: Lord Spectre
15 Replies

4. Programming

realloc() fails

Not sure in which forum to post this. I'm trying here, in Programming. I'm working on a PC with Intel Duo processor & 2GB of ram. OS is Ubuntu 10.04. I'm having problems with a C++ program that makes extensive use of realloc(). It happens that as soon as the overall memory allocated(OS +... (14 Replies)
Discussion started by: mamboknave
14 Replies

5. AIX

Find command fails in crontab

Hi , I imported find command I have on my hp-ux server to clean up the /tmp of my new IBM AIX servers. Though, the commands always fails in the cron but if I past it at the prompt, it works find. I tried with at jobs and regular 'find' . Could anyone tell me what I am doing wrong? Many... (4 Replies)
Discussion started by: cforget2810
4 Replies

6. Programming

realloc fails in C : what next ?

Hi all I'm trying to use someone else's software, which has a realloc that fails in it. This is probably due to memory limitations, as it only happens when I use this software on huge datasets. First question : how to diagnose if it's a soft or hard limitation? I mean, if it's due to my... (10 Replies)
Discussion started by: jossojjos
10 Replies

7. Programming

What happens when realloc() fails?

Hi, I am seeing varying results about, when realloc() fails in reallocation. Which one is correct out of the below? a) realloc() maintains the original pointer (i.e) the original pointer is left unaltered/untouched but relloc() returns the NULL value. b) original buffer pointer is lost... (3 Replies)
Discussion started by: royalibrahim
3 Replies

8. Shell Programming and Scripting

crontab fails to run script

OS is Ubuntu 8.04.3. When I run the command: /usr/bin/syslogMailer < /etc/syslog.pipes/criticalMessagesFrom a bash shell it works and i receive an email as per the script however when run from crontab it does not work. Can anyone explain why and how to fix it? /usr/bin/syslogMailer... (4 Replies)
Discussion started by: jelloir
4 Replies

9. UNIX for Dummies Questions & Answers

pkg_add fails

Hi, I have created a package on a 64 bit FreeBSD machine. when i install this (on another 64 bit FreeBSD machine )i get the following error : tar: Skipping pathname containing .. pkg_add: tar extract of /home/vcr/testpackage.tgz failed! pkg_add: unable to extract '/home/vcr/testpackage.tgz'!... (0 Replies)
Discussion started by: HIMANI
0 Replies

10. Shell Programming and Scripting

fgrep fails...!?

Hi all, I need to transport a number of files from one server to other. I like to ensure the integrity using file checksum values. The action plan is, 1. create the list of checksum values for all the files using cksum command in source server. 2. Transfer all the files including the file... (5 Replies)
Discussion started by: r_sethu
5 Replies
Login or Register to Ask a Question