![]() |
Newbie troubles with Bash if/then statements
Hi I'm trying to write a bash script to convert incoming faxes every hour and have managed to get it down ok, apart from and if/then statement:
#!/bin/bash FAXES="/var/spool/fax/incoming/*.01" check=0 nofaxes=0 for fax in $FAXES do check=$(($check+1)) done if [ $check > 1 ] > /dev/null then for fax in $FAXES do nofaxes=$(($nofaxes+1)) cat $fax | /usr/bin/g32pbm > "$fax".tif mv "$fax".tif /home/samba/faxesin/ rm -f "$fax" done echo $nofaxes " faxes processed" fi When I run the script I get cat: /var/spool/fax/incoming/*.01: No such file or directory 1 faxes processed Why doesn't the script realise that the directory is empty? Do I need some kind of "if not null" statement instead of trying to count the number of faxes? If so how do I do this? Regards, James |
Hi.
Try: if cat ....... then <deal with faxes> else <don't deal with faxes> fi the "if cat" will return false (if I remember correctly) if it encounters an error. Just don't use "if [cat.....] Dave |
You can check for existence first, I removed a lot of your file processing:
Code:
#!/bin/sh |
Thanks guys, I went for the second method in the end (works great, thanks!) because I wasn't sure about the first. Would I have included the ....... in the cat statement?
Thanks, James |
No, I just meant to continue with the rest of the line. Glad you got it working........ ;-)
|
| All times are GMT -5. The time now is 08:40 PM. |