My Question has 2 parts. Help with both parts is greatly appreciated.GIVEN INFO: - Lets assume there are 2 Folders, Folder A and Folder B. - Folder A contains many files. - Folder B contains the Shell script (code.sh)PART A:The script code.sh has to delete all the files in folder A and also afterwards delete the Folder B Including the script code.shPART B:Also this has to be scheduled via crontab at some particular time which in itself is not a problem. But after the script has deleted contents of Folder A, it should remove its entry from crontab and then proceed with deleting Folder B as mentioned in PART A.Is the above possible? If so can someone please tell me how or atleast point me in the right Direction. I'm new to UNIX so any help would be greatly appreciated.Note: In the whole process, only scheduling the script (code.sh) in crontab should be manual.
Unix Shell script to delete all traces of itself after execution through crontab
shell;shell script;scripting
If this script is ran as root...then removing the entry from crontab can be done by removing its crontab line from /var/spool/cron/root. (This is what crontab -l and crontab -e use). At the end of your delete commands add the following line (substituting {pattern} for your script name):sed -i '/{pattern}/d' /var/spool/cron/rootSo if your entry in crontab that runs code.sh looks like0 21 * * * /etc/cron.daily/code.shThe command would be:sed -i '/code.sh/d' /var/spool/cron/rootThis will remove the line containing code.sh from your root crontab file.You can add the line above to the end of your script so that both files are deleted, and the entry is removed from crontab. As @Barmar stated, you can just delete both folders aread of time. Yes this is a very old question, but the direct question on removing from crontab specifically still needed an answer.