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 "cleanProcess.sh" $tmpfile > $newtmpfile
lcnt=`grep -c "cleanProcess.sh" $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
else
echo "Entry already existed. Replacing it..."
fi
echo "0,5,10,15,20,25,30,35,40,45,50,55 * * * * $/test/bin/cleanProcess.sh" >> $newtmpfile
crontab $newtmpfile
echo "Added the new entry.."



crontab is empty ==>

$> crontab -l
$>


but file is having string as follows :

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


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:
Code:
echo "\n" >> $newtmpfile

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

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

$> crontab -l
#\n
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /test/bin/cleanProcess.sh




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:
Code:
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
rafa_fed2
My shell script it.sh #!/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
30
Shell Programming and Scripting
Crontab issue
jrymer
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 file.sh) I get errors. Here is the script TIME=" -maxdepth 1...... UNIX for Dummies Questions & Answers
6
UNIX for Dummies Questions & Answers
Crontab Issue
aravindj80
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
10
UNIX for Advanced & Expert Users
Crontab issue
h@foorsa.biz
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
3
AIX
crontab issue
mac4rfree
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
2
Shell Programming and Scripting