LVM Snapshot script



  • So I noticed an issue, I figured I'd post it in case anyone else has the same problem.

    I created a bash script on a CentOS 7 server to do some LVM snapshots and then export them to .gzip files. If I put the script under /etc/cron.daily it worked fine, however if I added the script in crontab as root or sudo, the script would run, but would give the error command not found for lvcreate and lvremove.

    I just had to add this to the script:

    PATH=/usr/sbin:/usr/bin:/sbin:/bin
    

    and it works fine now.


  • Service Provider

    Best practice, which almost no one follows, is to use explicit paths in scripts rather than implicit. then you don't need that at all.



  • @scottalanmiller said:

    Best practice, which almost no one follows, is to use explicit paths in scripts rather than implicit. then you don't need that at all.

    I guess that makes 100% sense since you have to start the script with an absolute path ha.