Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 04-13-2009, 04:00 PM   #1
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.


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

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

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, 04:16 PM   #2
LQ Newbie
Registered: Feb 2009
Distribution: Slackware
Posts: 20

Rep: Reputation: 1

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");
<your code>

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

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
How about passing the filename as an argument to the script?

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

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

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

find /faxdir/ -wholename '*.tif' -maxdepth 1 -type f -size +10k -exec cp '{}' /home/user/faxes \;
Old 04-14-2009, 10:19 AM   #5
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.


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 07:21 PM
assign converted string to variable bmaheni Linux - Newbie 2 12-28-2007 08:41 AM
create a variable in the .bashrc file in my home directory coldbeerz Linux - Newbie 2 12-14-2007 09:48 AM
How to assign a string to a structure variable in C? daYz Programming 7 06-13-2007 02:38 PM
Shell script --cannot assign variable-- ralvez Programming 6 02-24-2006 04:56 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:34 AM.

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