LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2012, 10:34 PM   #1
rajeshj
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Rep: Reputation: Disabled
pass contro+C in loop


Hello,
I am new to shell scripts. I have a script to create some files on remote server. The file will be created in say 2 minutes. I want to exit after this part and loop to the next day. How can I do that. The part of the script is posted below and where I need to exit is also mentioned. Please help me in this.
Thanks in advance.
------------------------------------------
-------------------------------------------
while ( $difdt > 0) {
@date = ($year, $month, $day);
my $date = sprintf("%d-%02d-%02d", $year, $month, $day);
-------------------------------------------------------
----------------------------------------------------------
----------------------------------------------------------------

target => "data_flex3d_075_${date}.grib",
);

I WANT TO EXIT FROM HERE AFTER 1 MIN AND GO TO THE NEXT DAY


# move to next day
($year, $month, $day) = Add_Delta_Days($year, $month, $day, 1);
$difdt = Delta_Days(@date, @enddate);
print "Date=",$date, "\n";
}
 
Old 10-03-2012, 11:49 PM   #2
nugat
Member
 
Registered: Sep 2012
Posts: 122

Rep: Reputation: 31
Quote:
Originally Posted by rajeshj View Post
Hello,
I am new to shell scripts. I have a script to create some files on remote server. The file will be created in say 2 minutes. I want to exit after this part and loop to the next day. How can I do that. The part of the script is posted below and where I need to exit is also mentioned. Please help me in this.
Hi,

1) Is this code snippet Perl, I am guessing?

2) What do you mean by "loop to the next day"? Do you mean that you literally want the script not to function until some future time is met, or do you mean that you want to advance the time string you are using to create files?

3) Can you show more of the code that will help us to better understand exactly what it is you are trying to do (or explain it better)?
 
Old 10-04-2012, 12:01 AM   #3
rajeshj
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
hi,
Yes it is perl script. what I use the script for is to fetch some data from some server. In that script it creates the data and prepare it as a file say out.grb. Then it downloads the file to mu local machine. I want to escape from the section of downloading. Instead I want to create files for everyday. Then I know the file locations for these files and download using some download manager. What I manually do is, change the date manually, execute the script, when the file is created I press control+C and edit the file for next date. So I want to parse the contro+C to this script after waiting for 2 minutes (thinking it will create the files in two minutes) then move to next date, create file, after 2 minutes exit and so forth.
Is it sufficient?
Thank you very much
 
Old 10-04-2012, 12:50 AM   #4
nugat
Member
 
Registered: Sep 2012
Posts: 122

Rep: Reputation: 31
Now I understand. I think you could fork it. Look at this example:

Code:
#!/usr/bin/perl
use strict;
use warnings;

$| = 1;

my $max = 15;

my $script = '/tmp/sleep.sh';

my $pid = fork();
if(not defined $pid) {
    warn "resources not avilable.\n";
}elsif($pid == 0) {
#  warn "child process\n";
  print "Launching script...\n";
  exec($script);
  exit(0);
}else{
#  warn "parent process, PID=$pid\n";

  # wait for some period of time
  print "Sleeping for $max seconds";
  for(1..$max){
    print '.';
    sleep(1);
  }
  print "done\n";

  # kill the pid
  print "Killing pid $pid...";
  kill 9, $pid;
  print "OK\n";

  waitpid($pid,0);
}
just put in $max whatever value (in seconds) you want to allow the script to run before killing it.

also, define your script in the $script variable.
 
  


Reply



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] Loop through list of URLs in txt file, parse out parameters, pass to wget in bash. dchol Linux - Newbie 16 07-27-2011 02:19 PM
"volume control GStreamer plugins and/or device not found"-how do I get volume contro fishurmn Linux - Newbie 6 07-19-2010 10:55 PM
[SOLVED] How to pass arguments to a function using a loop 10110111 Programming 2 03-01-2010 03:24 PM
Recalculate variable for each pass of an until loop wideyes Linux - Newbie 5 02-12-2010 01:23 AM
Planning to change root pass and oracle system pass sathyguy Red Hat 1 12-20-2005 09:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:37 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
Open Source Consulting | Domain Registration