Shell Script Command -- need help!

Posted on 2004-03-29
Last Modified: 2010-04-17

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!

Question by:jmc430
  • 4
  • 4

Expert Comment

ID: 10705816
what shell?

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

Author Comment

ID: 10705885

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 ... !

Expert Comment

ID: 10705956
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


Author Comment

ID: 10706431

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?

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.


Expert Comment

ID: 10706586
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?

Author Comment

ID: 10707027
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 ..

Accepted Solution

fim32 earned 160 total points
ID: 10707405
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...

Author Comment

ID: 10707693
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!

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now