Looping a perl script in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping a perl script in a shell script
# 1  
Old 10-03-2002
Looping a perl script in a shell script

I am trying to get the follow script to run in the background on the 'fly'. I can launch it via cron and it will run in the background. BUT when I launch it from the command line it will run in the foreground. I figure it has to do with the while loop I have, but I have no clue how I can run the perl script (i didnt write the perl nor have any perl skills at this point) every 5 secs without a loop.



#! /bin/ksh
#

case "$1" in
start)
touch /tmp/vmstat.lk
while [ -f /tmp/vmstat.lk ]
do
su - weblogic -c "/usr/local/scripts/vmstat.pl"
sleep 5
done
;;
stop)
rm /tmp/vmstat.lk
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac

exit 0
# 2  
Old 10-03-2002
If you want to launch the script into the backround use the ampersand character:

[script] &
# 3  
Old 10-03-2002
I've tried that. I am assuming that because I have it set using a start and stop ex:start_vmstat start or start_vmstat stop, that when I add the % it is either ignoring it or it is having no effect.

Last edited by edkung; 10-03-2002 at 04:51 PM..
# 4  
Old 10-03-2002
If you want to background what I think you want to background, put your while loop inside parentheses and put an ampersand after the closing parenthesis.
# 5  
Old 10-03-2002
using your suggestion I put the () around the while...done adding the % at the end, ended up getting a syntax error % unexpected. I am going to try several variations of what was suggested.
# 6  
Old 10-03-2002
Quote:
Originally posted by edkung
using your suggestion I put the () around the while...done adding the % at the end, ended up getting a syntax error % unexpected. I am going to try several variations of what was suggested.
% = percent
& = ampersand
# 7  
Old 10-03-2002
Also, if you run it as "./script.sh &", it will exit when you close your session. Try runnng it like this:
Code:
nohup ./script.sh &

You may have to hit enter to get your shell prompt back, but it should run in the background until you kill it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using Shell Script in place of Perl script to Unzip the zip files.

Hi Expert, We have some shell scripts which Internally uses Perl Script to Unzip the source zip files which comes to inbound directory. So now our requirement is to avoid the dependency on Perl Script and us Shell Script to unzip the files. I have the Perl script with me attached can some one... (3 Replies)
Discussion started by: naveen.dasu
3 Replies

2. Shell Programming and Scripting

Looping not completing in shell script

Hi, Iam using below code to login to servers to get cpu utilisation. but output is coming for only one server. code is below root@blr-svr-oclan-01 # more SSSC_CPU_UTIL1.sh #!/bin/sh echo "CPU UTILIZATION" while read line; do IDLE=`/usr/local/bin/sshpass -p 'xxx' ssh xxx@$line 'sar 2 2' |... (1 Reply)
Discussion started by: surender reddy
1 Replies

3. Shell Programming and Scripting

Looping in the shell script with help of script timer.

Hello Experts- We are facing some issues in the while loop script when we use the script time to decide whether to exist from the loop or continue. Below is the script SrcExitLoop="FALSE" Src_InitialStartTime=`date +%s` Src_StartTime=`date +%s` Src_NUM_ALERTS=0 TOTAL_ALERTS=`expr <SOME... (4 Replies)
Discussion started by: Amey Joshi
4 Replies

4. Shell Programming and Scripting

C Shell Script: While function not fully looping

I am new to scripting and this is probably the 4th or 5th simple script I have written. I am working with a HUGE number of data that need to be organized into folders and named a certain way. I wrote the naming script using a while function to go through the 1000-some folders and rename the files... (0 Replies)
Discussion started by: notluckyhannah
0 Replies

5. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

6. Shell Programming and Scripting

Perl script 'system' linking to local shell script not working

Trying to figure out why this works: printpwd.pl #!/usr/bin/perl use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; $A = system("pwd"); $A = `pwd`; print "$A\n"; ^^actually that works/breaks if that makes any sense.. i get the working directory twice but when... (5 Replies)
Discussion started by: phpfreak
5 Replies

7. Shell Programming and Scripting

Looping through a shell script with sql statements

Hello members, I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting; Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a... (4 Replies)
Discussion started by: novice82
4 Replies

8. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script (auto.pl). I run the perl script using perl auto.pl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script blue.sh has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies

9. Shell Programming and Scripting

Convert shell script for looping

Situation: I have a working shell script on our file server (OSXS Tiger) to connect to a workstation, which is using a portable home directory (phd), and rsync a user's MirrorAgent.log. I'm not that strong of a scripter (obviously), but I would like to add other workstations to this script as they... (4 Replies)
Discussion started by: le0pard13
4 Replies

10. Shell Programming and Scripting

looping through a variable in a shell script

hi, my first question is :- i would like to know how do i loop through the output of a variable. for ex:- if i have a variable called x and echo $x gives the output like feb 19 07 feb 20 07 feb 21 07 i would like to know how do i loop through this since it is separated and i... (1 Reply)
Discussion started by: ramachandranrr
1 Replies
Login or Register to Ask a Question