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
Thanks!