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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-25-2010, 10:17 PM
|
#1
|
|
LQ Newbie
Registered: Jun 2010
Location: India
Distribution: RHEL5, Ubuntu
Posts: 13
Rep:
|
Bash shell script to check the if empty files are being created & start the process
I have an Ubuntu server in which a file is dumped every hour and a new file for the next hour and the process continues. If there is any problem due to which the creation of file stops then empty files are created every minute till the process is killed & started again. I need help to make a shell script to check if the empty files are being created and then kill the process and start it again.
It would be a great help if anyone can help me regarding this.
|
|
|
|
06-25-2010, 11:08 PM
|
#2
|
|
Senior Member
Registered: Aug 2009
Posts: 3,497
|
Give this a try:
Code:
#!/bin/bash
for file in /tmp/test/*
do
if [[ ! -s $file ]]
then
echo "Found zero length file"
pkill -9 myproc
fi
rm -f $file
done
cheers
|
|
|
1 members found this post helpful.
|
06-25-2010, 11:22 PM
|
#3
|
|
LQ Newbie
Registered: Jun 2010
Location: India
Distribution: RHEL5, Ubuntu
Posts: 13
Original Poster
Rep:
|
Thanx for the reply @ kbp
Will this above script kill and start the process "myproc"
|
|
|
|
06-25-2010, 11:39 PM
|
#4
|
|
LQ Newbie
Registered: Jun 2010
Location: India
Distribution: RHEL5, Ubuntu
Posts: 13
Original Poster
Rep:
|
I'm kinda new to shell scripting and I don't have much idea about it. It would be a great help if you could help me.
In my scenario I need to run a script present in the home directory after th process is killed. Can I do it after changing your script as
Code:
#!/bin/bash
for file in /tmp/test/*
do
if [[ ! -s $file ]]
then
echo "Found zero length file"
pkill -9 myproc
./proc.sh
fi
rm -f $file
done
Thanks in advance.
Last edited by hussa1n; 06-25-2010 at 11:42 PM.
Reason: mistake
|
|
|
|
06-26-2010, 01:26 AM
|
#5
|
|
Senior Member
Registered: Aug 2009
Posts: 3,497
|
try '~/.proc.sh' .. this is the home directory of the current user or you can use the full path .. '/home/<user>/proc.sh'
cheers
|
|
|
1 members found this post helpful.
|
06-26-2010, 04:13 PM
|
#6
|
|
LQ Newbie
Registered: Jun 2010
Location: India
Distribution: RHEL5, Ubuntu
Posts: 13
Original Poster
Rep:
|
Thanks kbp.
I really needed this one.
|
|
|
|
06-29-2010, 04:20 PM
|
#7
|
|
LQ Newbie
Registered: Jun 2010
Location: India
Distribution: RHEL5, Ubuntu
Posts: 13
Original Poster
Rep:
|
When is use this script everything is fine. But the problem is that all the files including data files and empty files are being removed from /tmp/test/
Code:
#!/bin/bash
for file in /tmp/test/*
do
if [[ ! -s $file ]]
then
echo "Found zero length file"
pkill -9 myproc
/home/user/proc.sh
fi
rm -f $file
done
How can this script be modified in order to delete only the empty files.
|
|
|
|
06-29-2010, 05:21 PM
|
#8
|
|
Senior Member
Registered: Aug 2009
Posts: 3,497
|
Sorry.. you didn't specify that you wanted to keep the non-empty ones  .. try this:
Code:
#!/bin/bash
for file in /tmp/test/*
do
if [[ ! -s $file ]]
then
echo "Found zero length file"
pkill -9 myproc
/home/user/proc.sh
rm -f $file
fi
done
|
|
|
|
06-29-2010, 05:49 PM
|
#9
|
|
LQ Newbie
Registered: Jun 2010
Location: India
Distribution: RHEL5, Ubuntu
Posts: 13
Original Poster
Rep:
|
Thanks kbp. That works fine.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:27 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|