Question: Just to be clear I want to comment crontab entries, not a basic file. Usually, I do it like

> 
> crontab -e
> 
> 
> 

```
30 * * * * /u01/app/abccompny/scripts/GenerateAWRReport.pl
01,31 * * * * /u01/app/abccompny/scripts/table_growth_monitor.sh
30 0,4,8,12 /u01/shivam/script/getMongoData.sh 

```

and I add "#" in front of each line and just save it. Similarly after work is done I remove the "#". 

```
#30 * * * * /u01/app/abccompny/scripts/GenerateAWRReport.pl
#01,31 * * * * /u01/app/abccompny/scripts/table_growth_monitor.sh
#30 0,4,8,12 /u01/shivam/script/getMongoData.sh 

```

Is there an efficient way to do this using the script?

Answer: 
Export your current crontab into a file, delete the crontab, then use the previously created file.

```
$ crontab -l > cron_content
$ crontab -r
$ <this is where you do your stuff>
$ crontab cron_content

```
You can use the below script to add or remove comments from crontab.

```
#!/bin/bash

# you must have permission to read the crontab

if [[ $1 == "-add" ]]; then
        crontab -l > /tmp/cron_export
        awk '$0="#"$0' /tmp/cron_export > /tmp/cron_comment
        crontab -r
        crontab cron_comment
elif [[ $1 == "-remove" ]]; then
        crontab -l > /tmp/cron_export
        awk '{ print substr($0,2) }' /tmp/cron_export > /tmp/cront_uncomment
        crontab -r
        crontab cron_uncomment
else    
        echo "no option was selected. Please use -add to add comments or -remove to remove comments"
fi

# Remove all the create files for the operations

for f in /tmp/cron*; do
    [ -e "$f" ] && rm cron* || echo "No files to remove were found"
    break
done

```

The usage of the script should be:

to add the comments

```
./youscriptname.sh -add

```

to remove the comments

```
./youscriptname.sh -remove

```