Search for a cronjob with crontab -l

前端 未结 1 1699
南笙
南笙 2021-02-01 21:01

I am trying to find a cronjob that was created to ensure that the script doesn\'t duplicate the same exact cronjob.

I\'ve been trying to use something along these lines

相关标签:
1条回答
  • 2021-02-01 21:29

    /var/spool/cron/crontabs is the usual parent directory for crontab files. There are files there that have names of users - root is the root crontab, for example. There is a potential for every user on the system to have used crontab -e and created his/her own crontab.

    As root you can :

    cd /var/spool/cron/crontabs
    grep  'search string' *
    

    This command (as root) will tell you what user's crontab has the string. And if it exists.

    You would do this if if you are not sure what crontabs things are in. crontab -l only gives the stuff in YOUR crontab, the user who is currently logged in. If you are sure that is the best place to check:

    crontab -l | grep -q 'search string'  && echo 'entry exists' || echo 'entry does not exist'
    
    0 讨论(0)
提交回复
热议问题