LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 04-13-2009, 05:00 PM   #1
David_Elliott
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Rep: Reputation: 0
How do you assign a variable to be a variable file name in a directory?


I'm running Hylafax and receiving upwards of 1000 faxes daily. Sometimes I will receive partial pages that are less than 10k in
size. What I'm trying to do is ignore those and copy the ones larger than 10k into my faxes directory.

Here's my basic script so far.

#!/bin/bash

file="fax000038578.tif"
declare -i fsize
fsize=$(stat -c %s "$file")

if [ "$fsize" -gt 10000 ]
then
cp $file /home/user/faxes
fi



It works fine if I name the specific file as shown above. However, the file names change each time a fax is received. They will always have the tif extension. The number associated to the fax (000038578) does not always increase incrementally though.

I tried file="*.tif" but that didn't work. Stat returned no such file error.

So basically, I need file to be a variable with a variable file name with a tif extension inside it.

Thanks in advance

David Elliott
 
Old 04-13-2009, 05:16 PM   #2
ccargo
LQ Newbie
 
Registered: Feb 2009
Distribution: Slackware
Posts: 20

Rep: Reputation: 1
Hi,

You could use find to filter out files that end in .tif with

find /search-directory/ -name "*.tif"

where you replace search-directory with the path your .tif-files are in.

To put it in a for-loop covering multiple files you would write

for file in $(find /directory/ -name "*.tif");
do
<your code>
done

Cheers
 
Old 04-13-2009, 07:02 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
How about passing the filename as an argument to the script?
Code:
#!/bin/bash

file=$1
declare -i fsize
fsize=$(stat -c %s "$file")

if [ "$fsize" -gt 10000 ]
then
cp $file /home/user/faxes
fi
--- rod.
 
Old 04-13-2009, 08:26 PM   #4
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 227Reputation: 227Reputation: 227
How about just using find - say your faxes are in /faxdir and you want to copy to /home/user/faxes all files > 10k then :

Code:
find /faxdir/ -wholename '*.tif' -maxdepth 1 -type f -size +10k -exec cp '{}' /home/user/faxes \;
 
Old 04-14-2009, 11:19 AM   #5
David_Elliott
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Through trial and error from your suggestions, here's what I was able to use successfully.

file=$(find /var/spool/hylafax/recvq/ -name "*.pdf" -size +6k)
mv $file /home/fax-user/Desktop/ReceivedFaxes


I then created a cron job to run the script every few minutes.

thanks for all your help.
 
  


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
how to select a particular line from a file and assign it to a variable? pdklinux79 Linux - Newbie 4 06-18-2008 08:21 PM
assign converted string to variable bmaheni Linux - Newbie 2 12-28-2007 09:41 AM
create a variable in the .bashrc file in my home directory coldbeerz Linux - Newbie 2 12-14-2007 10:48 AM
How to assign a string to a structure variable in C? daYz Programming 7 06-13-2007 03:38 PM
Shell script --cannot assign variable-- ralvez Programming 6 02-24-2006 05:56 PM


All times are GMT -5. The time now is 07:54 PM.

Main Menu
Advertisement
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