Hi. I have a situation where I need to constantly read a command's output in order to loop through it to determine something that is happening over our system. The command td <filename> interactively prints 'filename' as text is written to it and this is redirected to standard output. I have been trying to loop through this output interactively within a shell to catch any new messages to the files but without success. I have tried with:
but it complains with
what I want to, is feed while with the output of the command interactively, which I believe will in turn run for ever (which I expect and want) thus achieving what I want. But as you can see, it doesn't work like this. I have also tried with for with not success.
If anyone could come with something similar to what I want, please advice. It will be very appreciated.
matrixmadhan, thanks for your prompt reply. I have done what you suggested, but apparently the shell hangs there and does nothing (no output or anything). I even tried redirecting echo's to a file and the file doesn't even gets created, which I believe that it hangs before it goes into the loop.
Hi matrixmadhan. Thanks again. I dont understand at all your statemnet about 'blocking on a read', could you please ellaborate more on that ?
Here is an example of what I am trying to do.
I executed on a terminal
See how it waits to show you there are no more 'trace to debug' on the file test. I then send a message from another terminal, that writes to this file.
Then, in my first terminal I see
td just seem to do something like "I am watching this file for you, write to it, and I will show you what did you write". I am trying to do the same thing to catch any new message written to some file.
I just see that td is just a wrapped tail -f under the covers. So, this actually make things easier, since I just want to, as new lines are added to this output, verify them to apply my criteria based on what I found on these. Still, if I do `tail -f file` while just seem to hang there.
has a fair shot at doing what you want. But it depends on how td is written. It may be line buffered only when writting to a tty device. When writing to a pipe, it may be fully buffered. Use "man setvbuf" if you don't understand buffering.
The below command works in the terminal interactively but not as part of a bash script. I though maybe I needed to escape the "$dir" so it isn't interpreted literally, but that's not it. Thank you :).
interactively in terminal
dir=/path/to
new=$(ls "$dir"/*.csv -tr | tail -n 1) && echo... (6 Replies)
I have 300 servers listed in servers.txt
I motto is to check if my id "user1" has sudo privileges on the 3000 servers. I m using sudo -l to check if I have privileges or not. If wish to check this either non-interactively; if not; interactively.
Below is the script I wrote:
... (5 Replies)
Hi there
I have a global zone with 178 zones on it :-)
The entire box is moving to an entirely new network and I need to write a script that will configure the zones config file in /etc/zones for each of them changing the IP address - but non-interactively
The line I need to change would... (5 Replies)
hi,
i have script which installs around 20 packages. during installation of each package script will be prompted for user input.
i need to run the script in non-interactive by using here document. is it possible to generate here document by running the script in interactive mode on Solaris?... (1 Reply)
Hello
Am trying to run top /glance non-interactively using ssh
from redhat to hp-ux hosts
but getting following errors..
=======================
ssh msi 'top -n 1'
Sorry, I need to know a more specific terminal type than "unknown".
ssh msi top -d1 -n20 > /tmp/top.out
Sorry, I need... (3 Replies)
Hi guys,
I am using Solaris 10 and we install IBM OnDemand server there. there's a command called arsload that we use to load document and query document too. I need to write a script to query document but when querying document, this command prompt for username then password.
My question is... (3 Replies)
My application has r.cron file which removes the cron job automatically during un-installation (pkgrm). But I want to take user input to decide on the deletion of cron job. I tried to put the code (to prompt user) in r.cron itself. But it is not waiting for user input. Where can I put that code? We... (0 Replies)
Hello,
I am making a script to copy files interactively from one directory to another using the "i" option because I dont want to overwrite the files.
cp -i *.html ./../otherdir/
cp: do you want to overwrite (y/n) ?
I used
cp -i *.html ./../otherdir/
ans='n'
read $ans
... (4 Replies)
hi,
To search and replace a string in multiple files i am using following command:
find . -name '*.txt' -print0 |xargs -0 perl -pi -e 's/find_string/replace_string/g'
I want to be prompted while replacing the string.
how this can be done.
thanks for every help. (2 Replies)
I'm wondering if there is a way to zip a file and password protect it non-interactively.
zip -e will prompt for a password but I don't want a prompt. This needs to be done automatically as part of a shell script.
I'm using the zip command because the will be unzipped by a Windows machine. ... (1 Reply)