LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-03-2003, 09:05 AM   #1
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Rep: Reputation: 32
Newbie bash scripting question...


I have an entry in my crontab as follows:

0,15,30,45 * * * * cd /home/user/seti; ./setitime.sh > /dev/null 2> /dev/null

It is set to launch a script (setitime.sh) that logs the time it takes my machine to process seti@home packets.
The script is as follows:

#!/bin/bash
# display the duration in a logical string
duration ()
{
totalsecs=$1
secs=$(($totalsecs % 60))
mins=$((($totalsecs % 3600) / 60))
hours=$(($totalsecs / 3600))

if [ $hours = 0 ] && [ $mins = 0 ]
then
result_str="$secs second(s)"
elif [ $hours = 0 ]
then
result_str="$mins minutes(s) $secs second(s)"
else
result_str="$hours hour(s) $mins minute(s) $secs second(s)"
fi

echo $result_str
}

# clean up old files
#rm -f time
touch setitime

echo "Seti packet started at `date`" >> setitime
START_DATE=`date +%s`

#Do some stuff
./setiathome -nice 1 -stop_after_process


echo "Seti packet finished at `date`" >> setitime
END_DATE=`date +%s`
echo "Seti packet duration = `duration $(($END_DATE - $START_DATE))`" >> setitime
echo "----------------------------------------" >> setitime
echo "" >> setitime

In normal operating mode multiple instances of setiathome will not run if an instance of setiathome is already running.

Is there a way to prevent multiple instances of my script from running?

The way I would like this to work is:
- cron launches setitime.sh.
- setitime.sh logs the start time to setitime, launhes setiathome (with the option to stop after processing)
- setiathome stops processing, setitime.sh logs the stop time to setitime.
- setitime.sh stops
- cron launches setitime.sh
- (repeat)
If cron attemps to start a second instance of setitime.sh, it aborts.

Here's what's happeneing:
- cron launches setitime.sh.
- setitime.sh logs the start time to setitime, launhes setiathome (with the option to stop after processing)
- 15 minutes pass and cron launches a second setitime.sh
- setitime.sh logs the start time to of the second seti@home to setitime.
- can't run 2 setiathome. second instnace of setiathome aborts.
- setitime.sh logs the stop time of 2nd setiathome to setitime.
- setitime.sh logs the duration of 2nd instance of setiathome to setitime (0 seconds)
- (repeat from step 3 every 15 minutes)

Any thoughts on how to only allow 1 instance of my bash script?
 
Old 05-03-2003, 09:08 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
hey hey hey

Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php
 
Old 05-03-2003, 09:26 AM   #3
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Original Poster
Rep: Reputation: 32
Check.
 
  


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
Newbie Bash Scripting Question jsaxton86 Programming 2 11-26-2005 08:58 PM
bash scripting question Red Squirrel Linux - General 1 07-11-2005 10:57 PM
bash scripting question mehesque Programming 2 03-07-2004 02:37 PM
Newbie Bash scripting question Caidence Programming 2 08-03-2003 05:53 AM
Scripting Question (BASH) merana Linux - General 4 01-12-2003 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration