From: no.top.post on 12 Dec 2009 10:05 In article <pan.2009.12.12.07.55.24.522793(a)deadspam.com>, Henrik Carlqvist <Henrik.Carlqvist(a)deadspam.com> wrote: > no.top.post(a)gmail.com wrote: > > PSS. I just did: 'top > /root/top' > > But '/root/top' is accumulating instead of renewing ?! > > Yes, it is supposed to do that. > > command > file > > means that the file is opened for writing and all output from command is > written to the file until the command ends. OK. > > The fact that a command might send some output that can move the cursor on > a terminal does not mean that there are any seeks done while writing the > file. > > To me it seems as if you would rather > > top -n 1 > /tmp/top.txt > > .... and possibly also repeat that, maybe from a cron job, maybe from a for > loop in a shell script. > ........... OK, I can't wait 1 minute to get a reply, but I can wait 1 minute for the 'mode' to get up steam; which would THEN: REPEAT 1. IF file:/tmp/ETHoberonFlag exists THEN execute the script [which was written by ETHoberon] eg. ls -l *dog > /tmp/ETHoberonCmndOutput; rm /tmp/ETHoberonFlag UNTIL file:/tmp/ExiLoop exists So then to start this mode, I'd 1. write the file which tells cron-1minute to loop 2. write the command to be executed 3. write the flag-file for 'command pending' and for each additional command I'd do steps 2,3. and to leave this mode: 4. rm <the flag-file which tells cron-1minute to loop> OR ?? So if the concept is valid, which file/S get the commands to execute every minute ? == TIA. PS. I see: http://en.wikipedia.org/wiki/Inotify > intended as a replacement for dnotify > kernel from release 2.6.13 I'm still using K 2.4* and don't want to mess at K-level.
From: Henrik Carlqvist on 12 Dec 2009 16:55 no.top.post(a)gmail.com wrote: > Henrik Carlqvist wrote: >> .... and possibly also repeat that, maybe from a cron job, maybe from a for >> loop in a shell script. >> ........... > OK, I can't wait 1 minute to get a reply, but I can wait > 1 minute for the 'mode' to get up steam; which would THEN: With cron you will get no better precision than 1 minute. If you use a sleep in a shell script loop you can fractions of seconds by doing something like: sleep 0.5 in your loop. In C you can call usleep to achive the same. Most languages do have support for pausing for only a few seconds or less. Instead of this group explaining how it is done in every language it would probably be more effective if you told us in which language you plan to implement your service. > REPEAT > 1. IF file:/tmp/ETHoberonFlag exists > THEN execute the script [which was written by ETHoberon] > eg. ls -l *dog > /tmp/ETHoberonCmndOutput; > rm /tmp/ETHoberonFlag > UNTIL file:/tmp/ExiLoop exists > > So then to start this mode, I'd > 1. write the file which tells cron-1minute to loop > 2. write the command to be executed > 3. write the flag-file for 'command pending' > and for each additional command I'd do steps 2,3. > and to leave this mode: > 4. rm <the flag-file which tells cron-1minute to loop> > > OR ?? "the file which tells cron-1minute to loop" seems a little strange to me. Either you have a cron job running or not. That cron job might be looking for files to start commands as you have described above. But if your service now has become implemented as a cron job and you stopped that cron job, how would you be able to start your service again? Most services running as daemons are alive all the time, waiting for a client to connect to them. The exception to this rule is services started by inetd where inetd is the only running daemon. > So if the concept is valid, which file/S get the commands to execute > every minute ? /var/spool might be a good place to put a directory for your service. You could even use the command-file (script-file?) itself as the flag-file, if the file exists run the file. You probably want to consider which user the daemon is run as and which clients will be able to put commands in that file. Many years ago I implemented a service which could be controlled by email. A shell script was sent in a zip-file as an attachment to an email. The service unzipped the file and run the shell-script. This email-address was used for nothing else and I thought that no-one except my unauthorized knew about the email address. One day I got a spam to that email address. Somehow a spammer had been listening on the internet traffic and found the address. The spam did not contain any zip-file with any script so no harm was done. Still it scared me off enough to shut down that service and replace it with a vpn solution. > PS. I see: http://en.wikipedia.org/wiki/Inotify >> intended as a replacement for dnotify kernel from release 2.6.13 > I'm still using K 2.4* and don't want to mess at K-level. You probably don't need to use that. It would be better to stick to portable standard posix features. regards Henrik -- The address in the header is only to prevent spam. My real address is: hc3(at)poolhem.se Examples of addresses which go to spammers: root(a)localhost postmaster(a)localhost
From: Eef Hartman on 22 Dec 2009 05:43 In alt.os.linux.slackware no.top.post(a)gmail.com wrote: > BTW. can any body comment on my 'top > nextTop' accumulates > instead of updates' observation ? Why should it NOT? top updates its screen every 5 seconds, and all that output is accumulated in the redirected output file. Someone already told you to use the -n 1 option to let top exit after a single iteration: -n : Number of iterations limit as: -n number Specifies the maximum number of iterations, or frames, top should produce before ending. and the -b option might also be useful: -b : Batch mode operation Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. (both from the man page) -- ******************************************************************* ** Eef Hartman, Delft University of Technology, dept. SSC/ICT ** ** e-mail: E.J.M.Hartman(a)tudelft.nl - phone: +31-15-278 82525 ** *******************************************************************
From: unruh on 22 Dec 2009 13:18 ["Followup-To:" header set to comp.os.linux.misc.] On 2009-12-22, Eef Hartman <E.J.M.Hartman(a)tudelft.nl> wrote: > In alt.os.linux.slackware no.top.post(a)gmail.com wrote: >> BTW. can any body comment on my 'top > nextTop' accumulates >> instead of updates' observation ? Because a redirection redirects the output of the command to a file. That output is a combination of the top listing and commands to the terminal to tell it to do things like clear the screen. These are all output to the file. There is no command which says "clear the file", certainly not the clearscreen command. > > Why should it NOT? > top updates its screen every 5 seconds, and all that output is > accumulated in the redirected output file. > Someone already told you to use the -n 1 option to let top exit > after a single iteration: > -n : Number of iterations limit as: -n number > Specifies the maximum number of iterations, or frames, top > should produce before ending. > and the -b option might also be useful: > -b : Batch mode operation > Starts top in 'Batch mode', which could be useful for sending > output from top to other programs or to a file. > (both from the man page)
|
Pages: 1 Prev: HOW2 implement a daemon? Next: Compiling an optimized kernel for VirtualBox or real machines |