LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-04-2003, 09:23 AM   #1
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Rep: Reputation: 15
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
 
Old 12-04-2003, 09:58 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
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
 
Old 12-04-2003, 10:00 AM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
You can check for existence first, I removed a lot of your file processing:
Code:
#!/bin/sh
FAXES="/home/wherever/*.01"
check=0
nofaxes=0
ls $FAXES > /dev/null 2>/dev/null
if [ $? -gt 0 ]; then
   echo "No files found"
   exit
fi
for fax in $FAXES
do
  nofaxes=$(($nofaxes+1))
done
echo "$nofaxes  faxes processed"
 
Old 12-04-2003, 12:08 PM   #4
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Original Poster
Rep: Reputation: 15
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
 
Old 12-04-2003, 06:33 PM   #5
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
No, I just meant to continue with the rest of the line. Glad you got it working........ ;-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java newbie question method headers and if statements dflan98783 Programming 6 02-21-2007 11:18 PM
cron bash script troubles zzyzx Slackware 3 04-12-2005 12:27 PM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 02:41 AM
Newbie modem troubles Theylan Linux - Hardware 2 09-24-2003 08:28 PM
Newbie in troubles CleonII Linux - General 3 05-15-2003 07:22 AM


All times are GMT -5. The time now is 11:32 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration