-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 20/04/2010 11:24:44, mcoyles wrote:
>>> On 20/04/2010 08:52:58, mcoyles wrote:
>>> Morning all - on FreeBSD 7.1 (for various reasons - don't ask)
>>> Am attempting to run the following via cron but it keeps erroring out:
>>>
>>> kill -9 `ps ax | grep backup | grep -v grep | awk '{print $1}'` && kill -9
>>> `ps ax | grep dump | grep -v grep | awk '{print $1}'`
>>>
>>> *snip* 
>>>
>>> Works OK from commandline - what do I need to change to make this cronable??
> 
>> The usual problem is that the environment under cron is not set up
>> anything like the way it is for an interactive session.  Particularly
>> the PATH.  Either write you command as a small shell script and setup
>> PATH within it, or use fully qualified names for all commands.
>>
>> Your command is probably better expressed as:
>>
>>     /bin/pkill -9 'backup|dump'
> 
> 
> Hi Matthew - cheers for that, I always forget the lack of common path in cron 
> *sigh*
> Anyhoo, there are multiple instances of backup and dump coming back in ps 
> -ax... your
> suggested command appears to only kill off the first instance? Have used my 
> commands 
> above in cron now using full path reference as per your advice - just waiting 
> for the
> clock to click round to 11.30 here for them to run...
> 

It should kill them all.  According to the man page:

     The pkill command searches the process table on the running system and
     signals all processes that match the criteria given on the command
line.

You can change 'pkill' to 'pgrep -l' to see what it would kill without
actually killing anything.

Note that pkill and pgrep by default won't report any process ancestors
in the same process group as themselves unless you use the '-a' flag.  So:

worm:/usr/src:% pgrep -l tcsh
worm:/usr/src:% pgrep -a -l tcsh
1244 tcsh

        Cheers,

        Matthew

- -- 
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
                                                  Kent, CT11 9PW
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkvNgp4ACgkQ8Mjk52CukIzBSACdFg+f1ea8b6wvbENW4aTBMCJO
RnoAn3CZKziqmAWSoAc8zMbvp5CppcvK
=Cjkj
-----END PGP SIGNATURE-----
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to