]> git.pond.sub.org Git - empserver/blob - scripts/savecore
Make savecore put $PWD in the mail subject
[empserver] / scripts / savecore
1 #!/bin/sh -e
2 # Script to save core files, to be run from post_crash_dump_hook
3 # Written by Markus Armbruster, 2008
4 # This script is in the public domain.
5
6 # Use: edit configuration variables below to taste, then set
7 #   post_crash_dump_hook = /wherever/savecore
8 # in econfig.  Make sure to run the server with core dumps enabled
9 # (ulimit -c unlimited).
10
11 # Rules when running as post_crash_dump_hook:
12 # Data directory is working directory.
13 # stdin, stdout, stderr are redirected to /dev/null, except in debug
14 # mode
15
16 # Configuration
17
18 # How your system names core files
19 #
20 # This is a pattern rather than a name, because modern kernels can put
21 # fancy stuff in the name we can't always predict.
22 core_pattern=core.*
23 #core_pattern=emp_server.core
24 #core_pattern=core
25
26 # Where to save core dumps
27 #
28 # If you leave cores in the data directory, backup scripts may pick
29 # them up, which is probably not what you want.
30 core_dir=../core-dumps
31
32 # Whom to send mail (leave empty to not send any)
33 privlog=
34
35 # Program to send mail
36 mailx=mailx
37 #mailx=mail
38
39 # End of configuration
40
41 saved=
42
43 alert_deity ()
44 {
45     local msg;
46     if [ "$saved" ]
47     then msg="Core dump $saved_core saved."
48     else msg="Could not save core dump."
49     fi
50     echo $msg | $mailx -s "emp_server dumped core in $PWD" "$privlog"
51 }
52
53 test -n "$privlog" && trap 'alert_deity' EXIT
54
55 core_name=`ls -td $core_pattern | head -n 1`
56 saved_core=$core_dir/core-`/bin/date +%Y-%m-%d-%H:%M`
57
58 mv -f $core_name $saved_core
59 saved=y