Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Needed "Urgent"

Status
Not open for further replies.

warangalboy1

Programmer
Aug 8, 2005
3
US
Im a newbie to Unix Shell Scripting and im trying to solve the problem.
can any one plz help.
This is the problem.
Im trying to write a WW script which takes 2 arguments: 1) the name of some script ($1) and (2) an integer value ($2)
WW should execute the specified script for the specified number of seconds ($2) and suspend it for the same number of seconds ($2)
and continue this cycle until the specified script is completely executed.
DO let me know
Thanks in advance
 
Hi

I don't know what WW is, but the base idea must be similar for all shell scripts. Maybe this [tt]bash[/tt] script gives you a starting point :

Code:
#! /bin/bash

$1 &                             [gray]# run it in background[/gray]
pid=$!                           [gray]# note it's process ID[/gray]

i=1                              [gray]# first state is 1=running[/gray]
while :; do                      [gray]# endless loop[/gray]
  sleep $2                       [gray]# wait[/gray]
  ps $pid > /dev/null || break   [gray]# if no process, the exit loop[/gray]
  test $i -eq 1 \                [gray]# if current state is 1=running...[/gray]
  && kill -SIGSTOP $pid \        [gray]#... then stop it...[/gray]
  || kill -SIGCONT $pid          [gray]#... else continue[/gray]
  ((i=1-i))                      [gray]# change the state between 1 and 0[/gray]
done

Feherke.
 
just curious..... what IS WW?
care to enlighten the audience?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
WW is the script that i want to write that takes those arguments.

ARGUMENT 1 --> ANY SCRIPT
ARGUMENT 2 --> ANY INTEGER VALUE.

SO THE WW SCRIPT TAKES THESE TWO ARGUMENTS AND RUN ARGUMENT 1 FOR ARGUMENT 2 VALUE AND THEN SLEEPS FOR ARGUMENT 2 VALUE AND MUST CONTINUE THIS CYCLE UNTIL ARGUMENT 1 IS EXECUTED

CAN YOU HELP ME
THANKS IN ADVANCE
 
No need to shout. People are rightly confused at your question.

You've asked how to write a "WW script." To a reader, that indicates that you believe "WW" is significant information needed to answer your question. If WW is only what you intend to name your script, then it's not significant, and it's strange that you've mentioned it at all, and certainly that you've mentioned it so prominently in the question.

That's why people keep asking you about it.


If I asked you, "Where can I get a blarg dog?", you'd assume "blarg" was an important description of the type of dog I wanted, not what I wanted to name it.

See where the confusion comes from?
 
Hi

Ok, than :
[ol]
[li]save the code from my previous post into a file called [tt]WW[/tt][/li]
[li]give execute permission to it[/li]
[li][tt]WW big_bad_program 3[/tt][/li]
[/ol]

The parameters are as you required.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top