Search code examples
shellunixubuntu

Generate unique filename for fswebcam


I have fswebcam installed in my ubuntu. I want the fswebcam to provide output as img1, img2 (if img1 is there), img3, img4... etc

I tried:

sudo fswebcam img

It stores the files as img but replaces the existing one instead of storing as img2.
Is there any specific type of unix command to store the filename as I specified?


Solution

  • location="your location directory"
    cd $location
    ls
    fname='filename'
    i=1
    j=1
        sudo fswebcam $fname 
        if [ -f $fname ]
        then
            echo "exist"
            while [ -f $fname$i ]
            do
                echo $fname$i
                i=$((i + j))
            done
            mv $fname $fname$i
        else
            echo "oops not found"
        fi