delete specific task in crontab queue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete specific task in crontab queue
# 1  
Old 10-01-2008
delete specific task in crontab queue

Hi everyone,

I'm a newbie to Linux scripting. I've been reading this forum for the last 6 hours trying to figure out the crontab and mail commands for the first time. I get to the point of successful copying and mailing. My question is how do I delete a specific task in the crontab queue without using crontab -r or without using vi editor from crontab -e, and then send me an email confirmation?

Below is a portion of my script:
-------------------------------------------------
#!/bin/bash

if test -f $file
then
# test if file exists and notify via email
echo "file already exists. Don't need to copy" | mail -s "file exists" $mail_user

else
echo "file does not exist ... starting crontab copy every half an hour."
echo "*/30 * * * * cp /tmp/file1 /tmp/file2 >> /tmp/file3

# Start the crontab
crontab file3
rm file3
fi

------------------------------------------------


Currently, this is what I have in my crontab queue (crontab -l):
*/30 * * * * cp /tmp/name1 /tmp/name2
*/30 * * * * cp /tmp/file1 /tmp/file2
*/30 * * * * cp /tmp/name1 /tmp/name2
*/30 * * * * cp /tmp/name1 /tmp/name2

How do I delete just one line (the second line from above list) from the crontab queue?
*/30 * * * * cp /tmp/file1 /tmp/file2

Again, I prefer not to use crontab -r because that would delete everything. Also I prefer not to use crontab -e and then delete just that line with vi editor, because I'm trying to automate this entire process.

After that line is deleted from the crontab queue, then send me an email saying that "File2 has been copied sucessfully."

If anyone has any suggestions or solutions, I would be greatly appreciated Smilie Thanks!
# 2  
Old 10-02-2008
This is a difficult problem ..

Well, it has been a few days since I posted this thread. So far are there are 36 viewers and 0 replies Smilie This must be a challenging one.

While waiting for a solution, I've found a "not so clean" way to delete a specific task in the crontab queue.

crontab -l > filename_list
sed -e '/file/d' filename_list > filename_queue
crontab filename_queue

The above 3 codes: First, get the queue list. Second, remove a specific line or lines from this list. Third, put the list back into queue.
# 3  
Old 10-02-2008
crontab -e and run an ed script under vi?

crontabs are physically located in /var/spool/cron. All of the manuals I have ever read have this warning:- DO NOT edit those files directly Usually in bold type.

- which is your only other choice. If you are just hacking your own desktop system and like rebuilding the OS from scratch, try writing a sed or awk script to edit those files automatically.

This is probably why there have been no answers - there are no good answers except 'use crontab'.
# 4  
Old 10-03-2008
But editing the files directly worked well with me in Solaris 10 Boxes

Code:
for i in hostname1 hostname2 hostname3
do
echo Modifying in $i
remsh $i "cp -p /var/spool/cron/crontabs/root /var/spool/cron/crontabs/root.bkp1" # Taking bkp
remsh $i "grep -v  file1 /var/spool/cron/crontabs/root > /var/spool/cron/crontabs/root.tmp" # Removing the entry
remsh $i "echo '<if any new entry to be made.....>' >> /var/spool/cron/crontabs/root.tmp" # Optional
remsh $i "cat /var/spool/cron/crontabs/root.tmp > /var/spool/cron/crontabs/root" # Modifying the original crontab
done


Last edited by ./hari.sh; 10-03-2008 at 12:27 AM.. Reason: added <if any new entry to be made>
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Running script in crontab in a specific directory

I am trying to run a script from crontab but the entire script (which is 70+ lines) is written in bash and I need it to run from a certain directory. So when I run it manually I cd to /local/mnt/scr and then type ./reordersc and it works fine. However, I want it to run from the crontab and I... (20 Replies)
Discussion started by: newbie2010
20 Replies

3. Shell Programming and Scripting

recursively going through folders and subdirectorys and running delete from crontab

Hio, So I have a crontab delete of older files setup. This script works fine if I run them by each individual directory. Problem is there are so many thousands of files and hundreds of directories and sub directories that I need to recursively have it go through and delete files by directory... (2 Replies)
Discussion started by: vsekvsek
2 Replies

4. Shell Programming and Scripting

Find and delete files before a job is submitted to queue

Hello all. I need some help modifying the following script: #!/bin/bash #PBS -l nodes=1:ppn=8,walltime=48:00:00,os=centos53computeA ## To submit type: qsub x.sh # If not an interactive job (i.e. -I), then cd into the directory where # I typed qsub. if ; then if ; then cd... (3 Replies)
Discussion started by: marcozd
3 Replies

5. Shell Programming and Scripting

Shell script to generate daily crontab entries between to specific dates

Hi, I am currently writing a shell script to enter daily reoccurring jobs into the crontab. I want to be able to specify any two dates for which I want these daily jobs to run between. Below is an example of what I need to be written to crontab. # Give a start day of 21/10/2009 09:00... (2 Replies)
Discussion started by: JM_86
2 Replies

6. Shell Programming and Scripting

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies

7. UNIX for Dummies Questions & Answers

How to delete specific files only

Hello, I have these files in my directory. ABC123 ABC12.sls.20080809111121 ABC233 ABC12.sls.20080403123212 ABC543 ABC12.sls.20080804231212 ABC323 ABC12.sls.20080809111232 ABC765 ABC12.sls.20080809112343 ABC654 ABC12.sls.20080809113133 I want to delete only files in first... (2 Replies)
Discussion started by: i.scientist
2 Replies

8. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies

9. AIX

Delete specific characters

Hi every1 Well i have a list of numbers e.g 12304 13450 01234 00123 14567 what i want is a command to check if the number is starting from 0 and then delete the 0 without doing anything else!!!! any help wud b appreciated!!!!!!!!:( (4 Replies)
Discussion started by: masquerer
4 Replies

10. UNIX for Dummies Questions & Answers

Crontab job queue

My cronjob triggers the script late by 6 minutes. /var/cron/log shows that it got triggered at the right time then where can I track, the late starting of the script. Is there some queue mechanism, some log? This happens sometimes, not daily. but it affects me, whenever it happens. Logging... (1 Reply)
Discussion started by: pksingh2
1 Replies
Login or Register to Ask a Question