crontab issue

Login or Register to Reply

Thread Tools Search this Thread
# 1  
crontab issue

I am adding a piece of code which adds entry in crontab ((in brown color))

\crontab -l > $tmpfile
echo "Removing the cleanProcess entry if it already existed.."
grep -v "" $tmpfile > $newtmpfile
lcnt=`grep -c "" $tmpfile`
echo "Number of entries in cron is : $lcnt"
if [ $lcnt -eq 0 ]; then
echo "Entry didn't exist before. Adding new...."
echo "\n" >> $newtmpfile
echo "Entry already existed. Replacing it..."
echo "0,5,10,15,20,25,30,35,40,45,50,55 * * * * $/test/bin/" >> $newtmpfile
crontab $newtmpfile
echo "Added the new entry.."

crontab is empty ==>

$> crontab -l

but file is having string as follows :

echo "0,5,10,15,20,25,30,35,40,45,50,55 * * * * $/test/bin/"

becoz of that the crontab is not able to initialized properly .

any anybody help me out whats wrong with it?

Last edited by crackthehit007; 03-22-2009 at 10:21 AM..
# 2  
Solaris cron does not like empty lines and will not work that way as you have discovered, so your line:
echo "\n" >> $newtmpfile

needs to be:
echo "#\n" >> $newtmpfile

# 3  
my system is linux redhat.
and now entry in crontab is

$> crontab -l
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /test/bin/

is that #\n is valid entry in crontab?

Last edited by crackthehit007; 03-22-2009 at 10:30 AM..
# 4  
More valid than an empty line or a "\n", the crontab will now work, I see the \n is being treated literally, should have said:
echo "#" >> $newtmpfile

The \n is quite unnecessary! Should have realised that before, doh!
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Another issue with crontab
My shell script #!/bin/sh ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH today=`date "+%m-%d-%Y %H:%M:%S"`; export today CUR_DIR=$1; export CUR_DIR LOG_FILE=$CUR_DIR/error.log; export LOG_FILE # Direct...... Shell Programming and Scripting
Shell Programming and Scripting
Crontab issue
Hello, I have a bash script that finds files older than 31 days and deletes them. I have this file loading into crontab to run everyday. It ran fine the first time i loaded it in, but now when I try to run it manually (bash I get errors. Here is the script TIME=" -maxdepth 1...... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
Crontab Issue
My colleague who was a sysadmin , has created a cron job script which collects logs and process them. The script works perfectly as per the defined time set by him. it works when we keep the timing as 55 05 * * * , whereas if we try to prepone the cron task is not getting executed. Where...... UNIX for Advanced & Expert Users
UNIX for Advanced & Expert Users
Crontab issue
Hi all, I'm having a problem with a crontab entry execution for a non root user. AIX version 5.3 user@host ~ $ oslevel -r 5300-10 cron status user@host ~ $ ps -ef | grep cron root 377044 1 0 Oct 27 - 0:22 /usr/sbin/cron cron entry for user user@host ~ $...... AIX
crontab issue
Hi Guys, I am having a prob with crontab.. When i enter "crontab -e", i am getting an message "History file has no read permission. " And my crontab is not executed (means the script is not called). What is the problem. can anybody help me.. Thanks for the help in advance.. ...... Shell Programming and Scripting
Shell Programming and Scripting