Help about comment verification

Hello,

I have a file, in which line 40 is commented. It is basically a cron job,


#05,35,50 * * * * /usr/local/scripts/my.sh

how i can i verify the line 40 is commented, if not then give me message not commented, otherwise provide us message it is commented.

if [ $(sed -n '40p' filename.txt | cut -c1) = '#' ]
then
    echo "commented"
else
    echo "not commented"
fi

I am using AIX

Output the line and check that the first non space character is a hash, something like...

crontab -l |head -40 | tail -1 |egrep '^\s*#' || echo line 40 is not commented out

If it is not commented then how we can check?

line is like that


05,35,50 * * * * /usr/local/scripts/my.sh

If you want to check the status for some particular script, its not a good idea to rely on the line_no. It can change anytime if someone add another script/comment/newline before that script.
You can search with the /path/to/script.sh

something like

crontab -l | grep -Eq '^#.*/path/to/script.sh'
status=$?

if [ $status -eq 0 ]; then
 #stopped
else
 #active
fi

Modify the pattern accordingly if you expect spaces before the "#" as in other post.