If the webcam isn't connected, then the character device (/dev/video0) doesn't exits. You can use an if statement and the test command (or the [[ compound command) to check if the file exists and it's a character special. See:
Code:
help test
help [
help [[
and http://mywiki.wooledge.org/BashGuide...ndConditionals
Code:
if [ -c /dev/video0 ]; then
printf '%s\n' "webcam connected"
fi
Or, you could use fuser or lsof to check if a process is using the file or not:
Code:
if fuser -v /dev/video0 > /dev/null 2>&1; then
printf '%s\n' "device in use"
else
printf '%s\n' "device available"
fi
But, fswebcam should also throw an error if the device is not available. So, I'd try something like:
Code:
if fswebcam [OPTIONS] pic.png > /dev/null 2>&1; then
pic="pic.png"
else
pic="camera offline.png"
fi
ncftpput [OPTIONS] "$pic" || {printf '%s\n' "$0: error - cannot upload picture"; exit 1;} 1>&2
Bookmarks