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

If you want to launch the script into the backround use the ampersand character:

[script] &

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.

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.

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

Also, if you run it as "./script.sh &", it will exit when you close your session. Try runnng it like this:

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.

DOH! thanks for pointing out my mental mistake, my ref source books are using % vs &...got a bit messed up there.

When I placed & in the script I get it to run in the background but get the stty: : No such device or address error.

Using ./script & runs nicely in the background but doesnt allow me to stop it (short of kill)...

You've all given me great advice and I thank you all...going to hack around on this and see if I can get it to play the way I want.

Again Thanks!

if you use ./script &

when you get your prompt back you can type "fg" adn it will bring that backgroup process to the fourground then you can control C to stop it.