I'm currently learning how to write bash scripts. How do I stop while loop once I get a 200 response code on my curl request? aws --endpoint-url http://s3.sample.com/ s3 cp hello.php s3://bucket/ while [ true ] do     curl http://sample.com/hello.php &amp;&gt; /dev/null done
123476
I've script as below :- (edited)  httpUrl="http://www.nnin.com" rep=$(curl -v -X POST -d "UID=username&amp;PWD=pass" $httpUrl)  status=$?   if [ "$?" -eq 0 ]; then      echo "Success"     exit $status   else     echo "Failed"     exit $status fi   when I run the script the return code always $?=0 because in a way the script is successfully execute but I want the return code for cURL to apply in next function.  I've try browsing around and use several method in this site particularly but doesn't help much, maybe because of the POST command and how to prevent the output from print when I run the script?  Thanks
106905
I am building a java server that needs to scale. One of the servlets will be serving images stored in Amazon S3.  Recently under load, I ran out of memory in my VM and it was after I added the code to serve the images so I'm pretty sure that streaming larger servlet responses is causing my troubles.  My question is : is there any best practice in how to code a java servlet to stream a large (>200k) response back to a browser when read from a database or other cloud storage?  I've considered writing the file to a local temp drive and then spawning another thread to handle the streaming so that the tomcat servlet thread can be re-used. This seems like it would be io heavy.  Any thoughts would be appreciated. Thanks.
101541
I'm trying to run some commands in paralel, in background, using bash. Here's what I'm trying to do:  forloop {   //this part is actually written in perl   //call command sequence   print `touch .file1.lock; cp bigfile1 /destination; rm .file1.lock;`; }   The part between backticks (``) spawns a new shell and executes the commands in succession. The thing is, control to the original program returns only after the last command has been executed. I would like to execute the whole statement in background (I'm not expecting any output/return values) and I would like the loop to continue running.  The calling program (the one that has the loop) would not end until all the spawned shells finish.  I could use threads in perl to spawn different threads which call different shells, but it seems an overkill...  Can I start a shell, give it a set of commands and tell it to go to the background?
16336
Given the following code (that doesn't work):  while True:     #snip: print out current state     while True:         ok = get_input("Is this ok? (y/n)")         if ok.lower() == "y": break 2 #this doesn't work :(         if ok.lower() == "n": break     #do more processing with menus and stuff   Is there a way to make this work? Or do I have do one check to break out of the input loop, then another, more limited, check in the outside loop to break out all together if the user is satisfied?
71907
I have a .txt file with 5 urls in it. I want to read it line by line, and perform 4 ping requests for each site, and extract the time. The code I wrote is below, but it isn't working.   Can anyone give me a hint?   #!/bin/bash  cat /home/akis/Desktop/sites.txt declare -i var=1 while read -r line do     while $var &lt;= 5      do         var2=$((var2+1))          name="$line" | ping -c 4 $name &gt; $var.txt | awk '{ print $8 }' &lt; $var.txt | awk '/time/' &gt; $var2.txt | tr '=' '\t' &lt; $var2.txt | awk '{ print $2 }' &gt; $var2.txt     done      var=$((var+1))   done
47668
I am tasked with writing an authentication component for an open source JAVA app.  We have an in-house authentication widget that uses https.  I have some example php code that accesses the widget which uses cURL to handle the transfer.    My question is whether or not there is a port of cURL to JAVA, or better yet, what base package will get me close enough to handle the task?   Update:  This is in a nutshell, the code I would like to replicate in JAVA:  $cp = curl_init(); $my_url = "https://" . AUTH_SERVER . "/auth/authenticate.asp?pt1=$uname&amp;pt2=$pass&amp;pt4=full"; curl_setopt($cp, CURLOPT_URL, $my_url); curl_setopt($cp, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($cp); curl_close($cp);   , I think you're on the right track, I think I'm going to end up using HttpsURLConnection and then picking out what I need from the response.
24737
Lets say I have a loop in Bash:  for foo in `some-command` do    do-something $foo done   do-something is cpu bound and I have a nice shiny 4 core processor. I'd like to be able to run up to 4 do-something's at once.  The naive approach seems to be:  for foo in `some-command` do    do-something $foo &amp; done   This will run all do-somethings at once, but there are a couple downsides, mainly that do-something may also have some significant I/O which performing all at once might slow down a bit. The other problem is that this code block returns immediately, so no way to do other work when all the do-somethings are finished.  How would you write this loop so there are always X do-somethings running at once?
44251
In Bash, piping tail -f to a read loop blocks indefinitely.   while read LINE0  do      echo "${LINE0}";  done &lt; &lt;( tail -n 3 -f /tmp/file0.txt | grep '.*' )  # hangs   Remove the -f or | grep '.*', then the loop will iterate.   The following does not hang.  tail -n 3 -f /tmp/file0.txt | grep '.*'    What causes this behavior?    Is there anyway in Bash to follow a file and read in a pipe expression?
114946
I'm writing a bash script to use inotifywait to monitor a directory and kick off actions when changes are detected. Something like:  inotifywait -m ... | while read f; do something; done   Since inotifywait doesn't terminate by itself, this script will not halt.  So my plan was to get the PID of the inotifywait process, save it to a file and have a different process kill it later, say like:  inotifywait -m ... | { echo ??PID?? &gt; pid-file; while ... }   But I don't know how to get the PID.  Is there a simple way to achieve this?  Another way is just to save the PID of the shell-script $$ to the file and kill the entire shell-script but I wanted to do some cleanup after the while loop.  I have tried using coproc and I think it will work but it seems like more complication than necessary.
100741
I am making a bash script for my own use. How can I run a command for a certain time (like 20 seconds) and then terminate it? I have tried a lot of solutions but nothing works. I also tried the timeout command with no success. Please give me some solution for this. For example: I want to run this command in a script and terminate it after 10 seconds some command
61547
I'm writing a bash script to install php5.4 and I'd like to automate this for a test VM. The rpm command I have is:  rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm yum install php54w   Now, in the middle of this running, there is a user prompt to enter [Y/N] whether or not to download the dependencies. So I either need to:   Simulate the user input of [Y]; or pass in a command for yum not to ask and assume [Y]   What is the best method for a bash script and how do I accomplish both of the above?
80926
I need a command that will wait for a process to start accepting requests on a specific port.    Is there something in linux that does that?  while (checkAlive -host localhost -port 13000 == false)   do some waiting  ...
111364
Some guy called one of my Snipplr submissions "crap" because I used if ($_SERVER['REQUEST_METHOD'] == 'POST') instead of if ($_POST)  Checking the request method seems more correct to me because that's what I really want to do. Is there some operational difference between the two or is this just a code clarity issue?
121907
I've got the following script:  #!/bin/bash echo "We are $$" trap "echo HUP" SIGHUP cat    # wait indefinitely   When I send SIGHUP (using kill -HUP pid), nothing happens.  If I change the script slightly:  #!/bin/bash echo "We are $$" trap "kill -- -$BASHPID" EXIT    # add this trap "echo HUP" SIGHUP cat    # wait indefinitely   ...then the script does the echo HUP thing right as it exits (when I press Ctrl+C):  roger@roger-pc:~ $ ./hupper.sh  We are 6233 ^CHUP   What's going on? How should I send a signal (it doesn't necessarily have to be SIGHUP) to this script?
26310
I have a file servers.txt, with list of servers:  server1.mydomain.com server2.mydomain.com server3.mydomain.com   when I read the file line by line with while and echo each line, all works as expected. All lines are printed.  $ while read HOST ; do echo $HOST ; done &lt; servers.txt server1.mydomain.com server2.mydomain.com server3.mydomain.com   However, when I want to ssh to all servers and execute a command, suddenly my while loop stops working:  $ while read HOST ; do ssh $HOST "uname -a" ; done &lt; servers.txt Linux server1 2.6.30.4-1 #1 SMP Wed Aug 12 19:55:12 EDT 2009 i686 GNU/Linux   This only connects to the first server in the list, not to all of them. I don't understand what is happening here. Can somebody please explain?  This is even stranger, since using for loop works fine:  $ for HOST in $(cat servers.txt ) ; do ssh $HOST "uname -a" ; done Linux server1 2.6.30.4-1 #1 SMP Wed Aug 12 19:55:12 EDT 2009 i686 GNU/Linux Linux server2 2.6.30.4-1 #1 SMP Wed Aug 12 19:55:12 EDT 2009 i686 GNU/Linux Linux server3 2.6.30.4-1 #1 SMP Wed Aug 12 19:55:12 EDT 2009 i686 GNU/Linux   It must be something specific to ssh, because other commands work fine, such as ping:  $ while read HOST ; do ping -c 1 $HOST ; done &lt; servers.txt
23537
How do I stop a Java process gracefully in Linux and Windows?  When does Runtime.getRuntime().addShutdownHook get called, and when does it not?  What about finalizers, do they help here?  Can I send some sort of signal to a Java process from a shell?  I am looking for preferably portable solutions.
9042
I am very new to Linux and I've only been using it to SSH to my web server using Putty. The issue I am having is this:  Basically I've got 2 php scripts. One get_tweets.php constantly listens for tweets on twitters Streaming API whilst the other - parse_tweets.php logs these into a db. In order for these to work they've to be kept running continuously.   I've been using the following commands to run them in the background and from what I've seen they run for most of the day, however whenever I log on to my computer in the morning the scripts have stopped and I've to run commands again.  nohup php my_script.php &gt; /dev/null &amp;   I'm just wondering if that is normal based on the commands I am using, should they run indefinitely when using nohup and if not what is the alternative? A CRON job?  Thanks for the help