Shell Script Command -- need help!


I am aiming to have a perl script on a test server, to be activated and run once an sql file is scp'd over from a web server.

Basically, I want the shellscript to run every 5 seconds, checking for the sql file on the test server (from the web server).

I have something like this now running on the test server:

while [true] ; do if [ -f pit[it/sq;]; then echo hi; fi; sleep 1; done

What am I doing wrong?  My perl script is not being activated to run.

Any advice or help would be greatly appreciated!  Thanks for your help!

Who is Participating?

Improve company productivity with a Business Account.Sign Up

fim32Connect With a Mentor Commented:
ah so... well, then you got 2 choices...

time it, and then give a little buffer, and set the interval to be greater than that (in hopes that you'll clear it before it runs again)

or, rename the file before you operate on it, either within the perl script or before you call the perl script... it's a kind of lock...
what shell?

and, i'm assuming you typed in that line real quick, as the typos would obviously make it not run...
jmc430Author Commented:

It's bash shell..

I did type that in without proof- reading ..

The actual line is:

while [ true ] ; do if [ -f output.sql ] ; then echo hi ; fi ; sleep 1; done

Sorry for that previously garbled and illegible line ... !
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

and that does nothing for you?  copying and pasting that into my shell (and changing the filename to one that exists) gives me a stream of "hi"s

jmc430Author Commented:

Yes, that does work .. but I was wondering if there were a way to make it so that instead of the stream of "hi's", something like

"perl"  (replacing the echo hi)

would stop running once it was started once.

Is that possible?

hmm, there should be no reason that shouldn't work:

while [ true ]; do
  if [ -f output.sql ]; then
    perl; # or /path/ if the first line is #!/bin/perl and execute permission
  fi; sleep 1;

for that matter, if you replace ther perl line with perl -e 'print "hi\n"', it also works just fine?
jmc430Author Commented:
the reason i ask is because when i set "perl" to run, it creates all these pages that continue to be overwritten infinite times,
since every time it finds the output.sql file, it continues to run the perlscript at the same time interval.

it works .. but i wanted it to be a finite sequence of events ..
jmc430Author Commented:
i like the second choice ... that's a great idea!  (and the one i think i can handle making modifications for).  thanks so much!

=) !

thanks again for all your help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.