|
From: Dan Stromberg on 5 Apr 2008 00:29 On Fri, 04 Apr 2008 02:51:10 +0200, Martin Jørgensen wrote: > Martin Jørgensen wrote: >> Martin Jørgensen wrote: >>> Dear all, >>> >>> I'm using a linux pc which runs some large calculations that take >>> about 1-2 days. I would like to use a script that every fifth minute >>> checks if the cpu-usage is above, say 30% (or whatever). If it aint >>> above 30% I assume that perhaps the calculation is done. Once done, I >>> want the script to send me an e-mail using standard linux commands. >>> However, to be absolutely sure the computation is done the cpu-usage >>> for that process should be above 30% twice in a row (at polls 2*5 >>> minutes). >> >> Oops, .... should be _below_ 30% twice in a row, ofcourse... Then I >> assume the computation is done... >> >>> Is this possible? How? I'm pretty bad at scripting but know a few >>> basics. I was wondering about using "top" or similar. Ofcourse I would >>> need the program to automatically figure out the PID. But I guess I >>> can use some kind of "ps | grep -i "program_name" "... >> >> All script suggestions are welcome... I hope I don't need root access >> (else I might talk to the sysadm). System: linux running redhat >> (something - about 1-1,5 year old installation I think). > > Erh, sorry. About the mail-thing: > > I just googled a bit around and I think a mail-server should be > installed which I don't think is the case. However: > > Is it possible to automate the following? > > ------- > $ ssh -X mylogin(a)myother_server.dk > (password entered) > (wait about 10 seconds) > $ mail my_email(a)address.com > Hi there, your computation using "program_name" is finished. Thank you > and goodbye. > . > (mail should now be sended) > $ exit > ------ > > Server should now respond with: > logout > Connection to myother_server.dk closed. > > > I hope the above mail-thing is possible to automate.... > > > Best regards > Martin Jørgensen It's a simple program, but I use it a lot so I can run off and work on task n+1 while as I'm waiting for tasks 1..n to finish: http://stromberg.dnsalias.org/~strombrg/notify-when-up2.html It'll do the e-mail, give you a little X11 popup window, and handle the ssh stuff for you if you set up passwordless authentication: http://stromberg.dnsalias.org/~strombrg/ssh-keys.html
From: Dan Stromberg on 5 Apr 2008 00:46 On Sat, 05 Apr 2008 00:33:58 +0200, Martin Jørgensen wrote: > Janis wrote: >> On 4 Apr., 02:38, Martin Jørgensen <megaf...(a)hotmail.com> wrote: >>> Dear all, >>> >>> I'm using a linux pc which runs some large calculations that take >>> about 1-2 days. I would like to use a script that every fifth minute >>> checks if the cpu-usage is above, say 30% (or whatever). If it aint >>> above 30% I assume that perhaps the calculation is done. Once done, I >>> want the script to send me an e-mail using standard linux commands. >>> However, to be absolutely sure the computation is done the cpu-usage >>> for that process should be above 30% twice in a row (at polls 2*5 >>> minutes). >> >> Polling is a bad approach and usually unnecessary. Moreover the CPU >> load doesn't really tell you anything in any reliable way. > > What is a better alternative? > >>> Is this possible? How? I'm pretty bad at scripting but know a few >>> basics. I was wondering about using "top" or similar. Ofcourse I would >>> need the program to automatically figure out the PID. But I guess I >>> can use some kind of "ps | grep -i "program_name" "... >> >> It's of course possible to intercept the PID and check that. >> >> But given the small time scale you posted above I suppose you don't >> need that to be informed once about the actual job but rather for >> future invocations? If that is the case you may try >> >> program_name program_args ; mailx -s finished you(a)your.domain > > Sorry, that doesn't work. > > The computation is started from inside a GUI and I cannot make the > program exit automatically after the simulation is done.... > > Also: I believe "mailx" requires a mail-server to be installed? I added > something about ssh'ing in my last posting, AFAIR. > >> You can provide a text body to the mail command through standard input. >> Or even pipe the whole output of your program to the mail command >> (beware if the output is huge) >> >> program_name program_args 2>&1 | mailx -s ... > > Thank you, but that doesn't work for me since the simulation is started > from a GUI and the simulation program is not text/console-based... > >> If you want your prompt back after invocation start that program >> sequence within a subshell as a background process >> >> ( ... )& >> >> In case you insist on polling because your program is already running >> something like the following can be done >> >> while ps ... | grep -s known_pid >> do sleep 600 # 5 minutes >> done > > I'm not really sure I understand what to do with this. What do I insert > at the 3 dots? > > I need to check when the CPU falls below 30% twice in a row, as I wrote. > You're assuming my simulation program is text/console-based, which it > isn't. > > The process will not kill itself after simulation is done. > >> But mind that you typically cannot rely on the ps output format; see >> whether it supports option -o to make the grep more reliable. > > Well, thank you for trying even though I really think you misunderstood > the question... > > Again: Since the simulations are started from a GUI I don't believe I > can use most of your suggestions... > > I welcome any other suggestions anyone has... I hope somebody here knows > how to solve the problem and wants to share the knowledge about how to > do it. > > > > Best regards > Martin Jørgensen This being a simulation that doesn't have a pid that disappears at the end, you're probably best off checking how much CPU time is being accumulated (whether by ps or top), or perhaps using strace and counting syscalls. I have lots of notify-when-up (the old version of the program which doesn't do ssh for you) examples at http://stromberg.dnsalias.org/ ~strombrg/notify-when-up.html including checking for when something drops out of top for a while. The usage is mostly the same between notify-when- up and notify-when-up2. Machine polling isn't great typically, but it's generally better than human polling :) notify-when-up2 and notify-when-up are both pollers with most of their options. I used to avoid machine polling on some sort of principle, but my life got more productive when I got over it.
From: Maxwell Lol on 7 Apr 2008 12:14 Janis <janis_papanagnou(a)hotmail.com> writes: > Hmm.. - I've not seen a Linux box without programs mail or mailx > installed, and sendmail running. Sorry to hear that. But then, how > do you think your requirement to send a mail can be be fulfilled at > all if you have no mail system available? Well, you can telnet to the SMTP port and send text.
From: Janis on 8 Apr 2008 07:13 On 7 Apr., 18:14, Maxwell Lol <nos...(a)com.invalid> wrote: > Janis <janis_papanag...(a)hotmail.com> writes: > > Hmm.. - I've not seen a Linux box without programs mail or mailx > > installed, and sendmail running. Sorry to hear that. But then, how > > do you think your requirement to send a mail can be be fulfilled at > > all if you have no mail system available? > > Well, you can telnet to the SMTP port and send text. Good point. (I often forget about that; it's just so rare that basic programs are missing on a system which makes it necesary to resort to a lower-level generic telnet solution.) Janis
|
Pages: 1 Prev: Mounting a hard drive from another computer Next: Writing shell scripts to automate |