LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-04-2008, 05:15 AM   #1
p_raju
LQ Newbie
 
Registered: May 2008
Posts: 11

Rep: Reputation: 0
Problem in Writing IF statement


Hi Gurus,

Goal: I am trying to create a shell for compressing/zipping files which are of more than some size value and
which are not being used by any process

Problem: I am not able to write the 'if' statement correctly

Description:

I created file "spoolfile.txt" with the list of all files which are more than size +5000 with following command

find . -name "*req" -size +5000 -exec fuser {} + >> spoolfile.sh 2>&1

Here is my shell code:

----------------

for FILE in `cat spoolfile.sh`
do

filename=`echo $FILE | cut -d ":" -f1`
fileinuse=`echo $FILE | cut -d " " -f2`
echo $filename
echo $fileinuse

if [ <check the file is in use> ] --- this is to campare 2nd column of the spoolfile is having any process number
then
file is not in use then gzip <filename>
else
move to next entry present in spoolfile.txt
fi

done

------------


Expecting your suggestions.

Thanks All,
P.Raju
 
Old 06-04-2008, 05:34 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
lsof lists open files. If a file is open, it is in use, yes?

Code:
if [ lsof | grep $filensme ] true; then
do gzip 
else
continue 
fi
or something along those lines.
 
Old 06-06-2008, 04:06 AM   #3
p_raju
LQ Newbie
 
Registered: May 2008
Posts: 11

Original Poster
Rep: Reputation: 0
Question

Hi,
if a file is in use. Then fuser not shows it as a process is using that file.
ex: I created a file xys.txt and made vi of xyz.txt in a putty session. then in another session when I run fuser xyz.txt, then it not showing that xyz.txt is in use.

Need some other solution.

Regards,
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Makefile include statement problem wampire Programming 1 05-21-2008 10:32 PM
problem using if statement evaluation inside pool robadawb Linux - Server 2 11-28-2007 02:18 PM
problem with if statement in bash script crewblunts Programming 3 03-11-2006 12:38 PM
Problem with unix if statement abefroman Programming 3 07-30-2005 04:24 PM
Bad switch statement (problem in the code block?) nifflerX Linux - General 2 07-14-2004 03:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:56 AM.

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
Open Source Consulting | Domain Registration