RE: Kill via Cron...
kill -9 `ps ax | grep backup | grep -v grep | awk '{print $1}'` And you don't have to remember grep -v grep if you remember to use ps axc (note the c), since arguments won't show up so the arguments to grep won't generate a false positive. I'm actually trying to kill the following in one swep if they've taken more than 8 hours to complete... : 39028 ?? Is 0:00.01 /bin/sh -c sh /root/tools/backup/fullbackup.sh 39070 ?? I 0:00.04 /usr/bin/perl /root/tools/backup/backuptodisk.pl (perl5.8.9) 62219 ?? I 0:00.00 sh -c /sbin/dump -0 -auf - /usr | gzip -q /backup/wednesday/usr.dump.gz 62220 ?? I 0:00.33 /sbin/dump -0 -auf - /usr (dump) 62221 ?? S 0:27.11 gzip -q 6 ?? S 0:03.07 dump: /dev/da0s1e: pass 4: 3.82% done, finished in 1:09 at Wed Apr 21 09:48:59 2010 (dump) 62223 ?? DL 0:01.80 /sbin/dump -0 -auf - /usr (dump) 62224 ?? DL 0:01.79 /sbin/dump -0 -auf - /usr (dump) 62225 ?? DL 0:01.81 /sbin/dump -0 -auf - /usr (dump) Have tried everything suggested thus far but nothing's done it as effectively as the original command run at commandline... just trying to automate the process by having cron kill at 8am. Cheers! Marci ___ 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
Re: Kill via Cron...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 21/04/2010 09:36:24, mcoyles wrote: I'm actually trying to kill the following in one swep if they've taken more than 8 hours to complete... : 39028 ?? Is 0:00.01 /bin/sh -c sh /root/tools/backup/fullbackup.sh 39070 ?? I 0:00.04 /usr/bin/perl /root/tools/backup/backuptodisk.pl (perl5.8.9) 62219 ?? I 0:00.00 sh -c /sbin/dump -0 -auf - /usr | gzip -q /backup/wednesday/usr.dump.gz 62220 ?? I 0:00.33 /sbin/dump -0 -auf - /usr (dump) 62221 ?? S 0:27.11 gzip -q 6 ?? S 0:03.07 dump: /dev/da0s1e: pass 4: 3.82% done, finished in 1:09 at Wed Apr 21 09:48:59 2010 (dump) 62223 ?? DL 0:01.80 /sbin/dump -0 -auf - /usr (dump) 62224 ?? DL 0:01.79 /sbin/dump -0 -auf - /usr (dump) 62225 ?? DL 0:01.81 /sbin/dump -0 -auf - /usr (dump) Have tried everything suggested thus far but nothing's done it as effectively as the original command run at commandline... just trying to automate the process by having cron kill at 8am. Hmmm is that because the system needs the resources for its usual functions after 8am? Or because if it hasn't finished by that time, it is clearly hung up and never going to finish? In the first case, I'd suggest simply running the backup at very low priority by renicing it to a high value -- it will run at usual speed *unless* there is anything else that wants a CPU timeslice, when it will be made to wait. In the second case, fixing whatever is causing the hang would be a better idea. (Processes that are hung up trying to do IO may not respond to signals very promptly which could explain some of your difficulties.) Unless you've got literally terabytes of content or are trying to write to a ridiculously slow device, and assuming you start the backup process at midnight, 8h is more than enough to backup most hard drives. Is your /backup partition on the *same* disk you're backing up? Or perhaps /backup is on the slave and /usr is on the master of the same IDE bus? Either of those could cause significant IO congestion. Other things to check for are filesystem corruption -- you'll need to take the machine down to single user, unmount the partitions in question and run fsck(8) on them -- or hardware problems - -- check the system log for any reports of trouble, try installing smartd and see if it tells you anything interesting. If your disk is flaking out, then don't try and coddle it along: replace it ASAP. Once things have got to the state where errors are affecting the OS, for any modern drive that indicates complete failure is imminent. Cheers, Matthew PS. You'll get better results if you add -L -C 32 to the dump(1) command line. Should speed things up nicely as well. - -- 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/ iEYEARECAAYFAkvOxokACgkQ8Mjk52CukIzwXACggmDSc35Y+r936agwCuihzghT tIgAmgLemFna0dbuhRsJau5QAQ1lnvo0 =vKgz -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
Re: Kill via Cron...
On 21/04/2010 09:36:24, mcoyles wrote: M I'm actually trying to kill the following in one swep if they've taken M more than 8 hours to complete... : M 62221 ?? S 0:27.11 gzip -q M 62223 ?? DL 0:01.80 /sbin/dump -0 -auf - /usr (dump) M 62224 ?? DL 0:01.79 /sbin/dump -0 -auf - /usr (dump) M 62225 ?? DL 0:01.81 /sbin/dump -0 -auf - /usr (dump) If they're running under the same process groupid, then sending it a signal via killpg(2) would kill them all. Two things that might help: * The default blocksize (Kb/output block) in dump used to be 10, but you could go as high as 64. Check the -b option. * Use gzip -1q for speed at the cost of slightly less compression. compress -c also works very well on dump images, and it's fast. -- Karl Vogel I don't speak for the USAF or my company phrasemonger, noun: a person who uses phrases or quotes that were coined by other people. --http://www.wordspy.com/TechWordSpy/ ___ 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
Re: Kill via Cron...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 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}'` Error: usage: kill [-s signal_name] pid ... kill -l [exit_status] kill -signal_name pid ... kill -signal_number pid ... 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' 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/ iEYEARECAAYFAkvNaMAACgkQ8Mjk52CukIzY7ACfaRdjM5GhHDwger7dZyZ0089F asoAn01GiwM4Fxqnf2cfzqhgWxbQmw50 =HqkV -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
RE: Kill via Cron...
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... Cheers... Marci ___ 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
Re: Kill via Cron...
-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
Re: Kill via Cron...
mcoyles == mcoyles mcoy...@horbury.wakefield.sch.uk writes: mcoyles kill -9 [from a post I made frequently in comp.unix.questions...] No no no. Don't use kill -9. It doesn't give the process a chance to cleanly: 1) release IPC resources (shared memory, semaphores, message queues) 2) clean up temp files 3) inform its children that it is going away 4) reset its terminal characteristics and so on and so on and so on. Generally, send 15 (SIGTERM), and wait a second or two, and if that doesn't work, send 2 (SIGINT), and if that doesn't work, send 1 (SIGHUP). If that doesn't, REMOVE THE BINARY because the program is badly behaved! Don't use kill -9. Don't bring out the combine harvester just to tidy up the flower pot. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ 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
Re: Kill via Cron...
On Tue, 20 Apr 2010 08:52:58 +0100, mcoyles mcoy...@horbury.wakefield.sch.uk said: M kill -9 `ps ax | grep backup | grep -v grep | awk '{print $1}'` I've typed ps ax | grep something | grep -v grep often enough to automate it. The psax script below accepts an optional egrep-style regex and displays only the matching processes. You can make your life easier by using process groups more often. For example, in the comments below there are four separate httpd processes in the same process group. If I wanted to kill them all, I could send HUP to PGID 198 instead of using four kill commands. There's a perl version of kill included in Perl power tools. I made some minor changes to use process groups instead: http://www.pobox.com/~vogelke/src/toolbox/perl/killpg.txt -- Karl Vogel I don't speak for the USAF or my company Son, looks to me like you're spending too much time on one subject. --Shelby Metcalf, basketball coach at Texas AM, to a player who received four F's and one D --- #!/bin/sh #psax: runs ps, looks for an optional egrep regex (BSD version). # # me% psax 'super|http' # USERPID PPID PGID RSZ TT STARTED TIME COMMAND # root198 1 198 1384 ?? 11Jul09 7:53.76 /path/to/httpd -DSSL # www 252 198 198 1976 ?? 11Jul09 0:44.96 /path/to/httpd -DSSL # www 253 198 198 1992 ?? 11Jul09 0:47.81 /path/to/httpd -DSSL # www 54291 198 198 1992 ?? 13Jul09 0:47.78 /path/to/httpd -DSSL # root 92729 204 8 304 ?? 25Feb10 0:01.25 supervise qmail-send # root 92730 204 8 300 ?? 25Feb10 0:01.40 supervise log # root 92731 204 8 304 ?? 25Feb10 0:01.04 supervise qmail-smtpd # root 92732 204 8 300 ?? 25Feb10 0:01.16 supervise log PATH=/bin:/usr/sbin:/usr/bin:/usr/local/bin export PATH umask 022 # Solaris: ps -cef -o user,pid,pgid,class,pri,rss,time,args # Linux: ps ax -o user,pid,pgid,rss,start,bsdtime,args cmd=ps -axw -o user,pid,ppid,pgid,rsz,tt,start,time,command case $# in 0) exec $cmd ;; *) exec $cmd | egrep COMMAND|$* | egrep -v egrep|/bin/sh $0 ;; esac exit 0 ___ 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
Re: Kill via Cron...
Karl == Karl Vogel voge...@hcst.com writes: On Tue, 20 Apr 2010 08:52:58 +0100, mcoyles mcoy...@horbury.wakefield.sch.uk said: M kill -9 `ps ax | grep backup | grep -v grep | awk '{print $1}'` And you don't have to remember grep -v grep if you remember to use ps axc (note the c), since arguments won't show up so the arguments to grep won't generate a false positive. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ 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
Re: Kill via Cron...
On Tue, Apr 20, 2010 at 12:57:25PM -0700, Randal L. Schwartz wrote: Karl == Karl Vogel voge...@hcst.com writes: On Tue, 20 Apr 2010 08:52:58 +0100, mcoyles mcoy...@horbury.wakefield.sch.uk said: M kill -9 `ps ax | grep backup | grep -v grep | awk '{print $1}'` And you don't have to remember grep -v grep if you remember to use ps axc (note the c), since arguments won't show up so the arguments to grep won't generate a false positive. Alternatively: ps ax | grep [b]ackup | awk '{print $1}' Or to avoid being nominated for something like the Useless Use of Cat award: ps ax | awk '/[b]ackup/ {print $1}' Making use pgrep/pkill would seem to make the most sense. -- George ___ 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