Re: [ilugd] Help required to setup a cron job

2013-03-16 Thread Anoop Sharma
Check it out: http://mywiki.wooledge.org/BashFAQ/045

Summary: Use flock.

man -s 1 flock provides examples on usage that may suit you.



On Fri, Mar 15, 2013 at 11:27 AM, Satish Kr Malanch satishmala...@gmail.com
 wrote:

 Hello all,
 Can anyone plz help me create a scrropt to run a cron job

 , I have schedule fetmail in every 5 minutes. but some time my cron get
 stucked due to another running instance

 I want a script that execute in every 3 minutes and check whether fetchmail
 is running or not if running then abort it and re run.

 Thanks s

 --
 With Best Regards:
 *Satish Kr Malanch*
 
 The only real voyage of discovery consists not in seeking new landscapes
 but in having new eyes. 

 --
 Visit my Blog by clicking here  http://sd-malanch.blogspot.in/
 ___
 Ilugd mailing list
 Ilugd@lists.linux-delhi.org
 http://frodo.hserus.net/mailman/listinfo/ilugd

___
Ilugd mailing list
Ilugd@lists.linux-delhi.org
http://frodo.hserus.net/mailman/listinfo/ilugd


Re: [ilugd] Critical System state: when only bash utilities work.

2013-02-03 Thread Anoop Sharma
In this case you have to use only bash inbuilt features (which include bash
builtins, special builtins as well as looping, variable manipulation and
redirection capabilities of bash).

Following techniques come to mind (though I have never used/tested any of
them!):

1. Since process IDs are visible in /proc and kill is a bash builtin.
Therefore we may use the following simple shell script. This was the first
solution I thought of. It is quick and dirty solution but it will save you
from a reboot (if you are not running as a superuser):

cd /proc;
for i in *; do echo kill ${i/[!0-9]*/}; done;

This attempts to send SIGTERM to all processes. So, it also kills your
useful processes too (like shell you would be typing this command on!).

A more refined approach would be the following script that tries to kill
all process of a specified name. I tried this on my machine for bash. You
may type ruby or whatever you typed on command line. This script does not
start a new process.
/***/
cd /proc
for i in *
do
if [ -f $i/cmdline ]
then
 read $i/cmdline
if [[ $REPLY == bash ]]
then
 echo kill $i
fi
fi
done
/***/

2. I am not familiar with ruby and what you exactly did. But, if this
technique work, it is better than first one - Use bash builtin named
jobs, to see if the offending process was started as a bash job. If yes,
use kill to send signal to the Jobspec.

Also remember that you may also send signal to process group instead of
sending it to individual processes. Whether it would be better or not would
depend upon how exactly you started the process that is spawning others.
But if you used a script to start whatever you were doing, then they would
almost certainly belong to same process group and it may be easier for you
to find process id of that script. That process id would be the process
group id of all the spawned processes. Therefore you may use kill
-pid_of_script (note the - sign) to kill all the processes started by that
script.

HTH,
Anoop



On Sat, Feb 2, 2013 at 10:05 PM, Chirag Anand anand.chi...@gmail.comwrote:

 On 2 February 2013 21:54, Amar Akshat amar.aks...@gmail.com wrote:
  Chirag,
 
  I understand your point of pkill, but I don't think you got my question.
  Basically, my system runs into a state, where all you can run are the
 bash
  commands, like echo, cat etc.
  Any system command like ps won't execute, perhaps because the system
 can't
  find resources to execute them and it will exit saying : cannot fork();

 Ah okay. Only bash built-in commands I haven't used for this purpose,
 in fact I did not even think of them as such at that time. Well 'kill'
 itself is a built-in command, but it requires a pid or jobspec, which
 I don't think you will be able to get at that time.

  On Sun, Feb 3, 2013 at 1:16 AM, Chirag Anand anand.chi...@gmail.com
 wrote:
 
  On 2 February 2013 20:49, Amar Akshat amar.aks...@gmail.com wrote:
   Hi,
  
   Other day I was writing a small pro-active system monitoring script in
   Ruby, and I forgot to close my IO pipe for pgrep command, every time I
   checked my system status.
   So after a day, there were more than 32,000 zombie pgrep processes. I
   could
   only run bash commands and nothing else.
  
   I could only find out number of processes due to bash-completion in
   /proc/
   directory.
   So I had to reboot my system.
  
   However my concern is, in a case like this, is there a way we could,
   find,
   kill the processes by just using bash utilities.? I tried Googling it,
   and
   found a couple of answers, but I am sure you would have run into such
   situations before.
 
  Hi Akshat, in such situations, I generally recommend using pkill
  (perhaps with -9), and _patience_ to kill all the instances of that
  particular process. It may not get triggered instantaneously but
  definitely does the job. You might want to keep doing it until you
  have killed the source which is forking every second. 'ps aux | grep '
  also comes in handy, but again takes some time, but gives you a sense
  of how many processes are left to kill.
 
  I have faced similar situations as these, where I have managed without
  a reboot. The thing which you would want to keep in mind is if there
  are other users using the process, make sure you are not killing
  those, and watch out for the critical ones (for example ssh, network
  etc. services).
 
 
  --
  Chirag Anand
  http://atvariance.in
 
 
 
 
  --
 
 
  Thank you...
 
  Amar Akshat (アマール)
 
   Walking on water and developing software from a specification are easy
 if
  both are frozen.



 --
 Chirag Anand
 http://atvariance.in

 ___
 Ilugd mailing list
 Ilugd@lists.linux-delhi.org
 http://frodo.hserus.net/mailman/listinfo/ilugd

___
Ilugd mailing list
Ilugd@lists.linux-delhi.org
http://frodo.hserus.net/mailman/listinfo/ilugd


Re: [ilugd] Shocking and Sad news.

2012-12-12 Thread Anoop Sharma
Shocked Unbelievable...

Any info on what happened?




On Thu, Dec 13, 2012 at 1:00 AM, Kishore Bhargava kish...@linkaxis.comwrote:

 12-12-12. What a very very sad day. We lost a very dear friend, Raj Mathur.

 People who knew and have met Raj will always remember him as a lively and
 humourous person - brutally honest and a man of principles.

 Raj was a founder member of the Indian Linux Users Group and a very active
 member of the Free and Open Source community. Well respected and extremely
 knowledgable, he was often sought after for advice which he readily
 dispersed.

 Raj loved to have fun and encouraged everyone around him to do the same.
 He loved his food, his movies, his music and being with friends and family.

 A brilliant hacker and much respected for his pioneering work, he will be
 missed by one and all.

 Rest in peace, Raj Oldmonk Mathur.
 --


 __**_
 Ilugd mailing list
 Ilugd@lists.linux-delhi.org
 http://frodo.hserus.net/**mailman/listinfo/ilugdhttp://frodo.hserus.net/mailman/listinfo/ilugd

___
Ilugd mailing list
Ilugd@lists.linux-delhi.org
http://frodo.hserus.net/mailman/listinfo/ilugd