# Bash scripts for pwcview webcam



## binyo66 (Jun 19, 2012)

I am using a webcam (since it is cheap now, and sufficient for a small room) as CCTV and pwcview as the recording software. pwcview has been set to record in picture style so that a 500GB HD can be used for six months. It's been set to produce around 1200 pictures each hour. To maintain a bunch of files (and luckily pwcview sets the file name in date-time format), I move the files every four hours to a sub-directory yyyymm/dd/hh (for example 201206/02/03 for pictures recorded at 2-june-2012 3am).

To do that, I am creating a script using bash (I am a novice in freebsd FreeBSD, and even more novice in bash scripting). I am making two bash scripts. The first script will be launched by cron every four hours, and I named it checkmvfile.sh. The purpose is to creat*e* the parameter of dates. The second script (I named it mvfile002.sh) will be called by checkmvfile.sh, and accepting three parameters yyyy mm dd, to move the files to the respective directory.

I have no problem with the second script. The problem is with the first script. First when changing the date (midnight). I solved this by calling mvfile002.sh twice (first passing parameters "a day before current date", and second the current date). Second, almost similar problem, when the month is changing. In here I need to know what is the previous month so that I can pass "a day before current date" is 30 or 31. Then I realized
February was a different case. Then I stoped the script. Because the script will be complex, and I know I have to handle a special case for changing the year.

Question is if there is a simpler way to move pwcview files to a sub directory as I mentioned above, using anything in freebsd FreeBSD? *O*r at least make the script much simpler using buil*t*-in functions?

Thanks,


----------



## jalla (Jun 21, 2012)

Read up on date(1)(), in particular the -v option.

To find the year-month-day of yesterday you'd use this


```
snapper:~% date -v -1d +%y-%m-%d
12-06-20
```


----------



## binyo66 (Jun 23, 2012)

Thanks, I solved it.


----------

