LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-21-2015, 01:03 AM   #1
sagar666
Member
 
Registered: Feb 2013
Posts: 212

Rep: Reputation: Disabled
Shell script for time count


Hi Guys,

I want a syntax or suggestion for implement below.

-->start x command and count time
--->send y cmd after 20 mins and stop count time
---> send z cmd and start count time.
Thanks in advance
 
Old 04-21-2015, 01:34 AM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
It will be good if you share the script that you have written so far. Let us know where exactly you are stuck and what exactly you are trying to do?
 
Old 04-21-2015, 07:06 AM   #3
sagar666
Member
 
Registered: Feb 2013
Posts: 212

Original Poster
Rep: Reputation: Disabled
Below is my script what i am trying but it is not working because timeout will kill the process after 20 minutes and executes further commands. I don't want to kill the process it has go to execute further commands.
#!/bin/sh

timeout 20m sh /dv4/delete-dv4.sh
PID=`echo $$`
if ps -p $PID > /dev/null
then
echo "$PID is running"
fi
timeout 20m sh /dv4/delete-dv4.sh
PID=`echo $$`
if ps -p $PID > /dev/null
then
echo "$PID is still running"
fi
kill -s 15 $PID

1. My requirement is sh /dv4/delete-dv4.sh has to be run up to 20 minutes and count time in X varable
3. After 20 minutes i need to send My process running
4.After 20 minutes again i need to be start sh /dv4/delete-dv4.sh and start count time from where it stopped earlier (In x Variable)
5. After 20 minutes i need to send My process is still running
6 If count time reached 40 minutues
7 kill the process
 
Old 04-21-2015, 07:28 AM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by sagar666 View Post
Below is my script what i am trying but it is not working because timeout will kill the process after 20 minutes and executes further commands. I don't want to kill the process it has go to execute further commands.
#!/bin/sh

timeout 20m sh /dv4/delete-dv4.sh
PID=`echo $$`
if ps -p $PID > /dev/null
then
echo "$PID is running"
fi
timeout 20m sh /dv4/delete-dv4.sh
PID=`echo $$`
if ps -p $PID > /dev/null
then
echo "$PID is still running"
fi
kill -s 15 $PID

1. My requirement is sh /dv4/delete-dv4.sh has to be run up to 20 minutes and count time in X varable
3. After 20 minutes i need to send My process running
4.After 20 minutes again i need to be start sh /dv4/delete-dv4.sh and start count time from where it stopped earlier (In x Variable)
5. After 20 minutes i need to send My process is still running
6 If count time reached 40 minutues
7 kill the process
It is always good to put your script in code tags as it makes it easy to read. In the script I don't see that you are killing the script the first time. So where the question comes to start it again? Are you saying that it should run for 20 minutes, send the status, kill the process and then start the same process again with 20 minutes timer, at the end of timer send the status, kill the process and shouldn't start again?
 
Old 04-21-2015, 09:51 AM   #5
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
This may do:

Code:
TX=`date +s`
PID=`pidof sh /dv4/delete-dv4.sh`
echo running  $PID ...
TC=`date +%s`
TD=$(($TC-$TX))
while [ ! $TD -ge 1200 ]; do
sleep 5s
TC=`date +%s`
TD=$(($TC-$TX))
done
kill $PID
PID=`pidof sh /dv4/delete-dv4.sh`
echo running $PID ...
TC=`date +%s`
TD=$(($TC-$TX))
while [ ! $TD -ge 2400 ]; do
sleep 5s
TC=`date +%s`
TD=$(($TC-$TX))
done
kill $PID
 
  


Reply

Tags
linux, programing, shell script, shell scripting


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
[SOLVED] shell script to get count of records in a mysql table Quakeboy02 Programming 3 10-24-2010 10:21 AM
Row count Shell Script zaeem Linux - Newbie 4 10-08-2010 07:35 PM
count multiple objects in shell script raggmopp1961 Linux - General 1 07-22-2010 08:56 AM
time count bash script help mad_penguin Programming 1 06-08-2010 09:12 AM
[SOLVED] count number of CD-ROMs on a system using shell script kushalkoolwal Programming 2 04-07-2010 08:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:01 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