scc(1)



NAME


	scc - collect and send snapshot-files to server

RELEASE


	scc	1.23.185

SYNOPSIS


	scc [ -a|--alternate <alt> ] [ -c|--comment <remark> ] [ -d|--delay <delay> ]
	        [ -e|--extra <mod> ] [ -S|--selection <mod> ] [ -f|--fqdn ]
	        [ -F|--from <from> ] [ -h|--help ] [ -i|--smtp <smtp> ]
	        [ -I|--ident <ident> ] [ -k|--key <key> ]
	        [ -l|--label <label> ]
	        [ -m|--max_age <max> ] [ -n|--norun ] [ -o|--option <option> ]
	        [ -p|--prog <prog> ] [ -P|--port <port> ] [ -r|--restart ]
	        [ -s|--destination <dest> ] [ -t|--test ]
	        [ -u|--user <user> ] [ -v|--virtual <host> ] [ -V|--version ]

DESCRIPTION


	Run the program scc-log and optionally send the resulting files 
	to the destination. By default the files are prepared for a pull by
	scc-srv. Other transfer mechanisms are ftp, rcp, scp and cp. When 
	scc-log exits with an error, no files are transferred.

	The security setup of the server receiving the files is very
	important. Refer to the documentation of scc-srv for the setup
	of the server.

	The collection of scc-data from the system is done by means of
	modules. Two kinds of modules exist, user and system modules. 
	The system modules are installed and run by scc. To extend the
	reach of the snapshots, user modules can be added to collect
	additional data. Refer to scc-collect(1) for more details. To
	run all user modules, use the following command-line:

		scc -e "*"

	When a specific user module requires much time, you can run
	it less frequent. The data from the last run of the module is
	kept in the directory /var/opt/scc/data/plugin_data. Suppose
	you have three user modules, named:

		scc_0550_u_abc
		scc_0650_u_def
		scc_0750_u_ghi

	Where module scc_0650_u_def should be run only once a week,
	while you want scc to run daily. You can use the following
	cronjobs to achieve this:

		0 6 1-6 * * /opt/scc/bin/scc -e "scc_0[57]50_u_"
		0 6 0   * * /opt/scc/bin/scc -e "*"

	You have to use the naming convention and shell filename
	generation wildcards to specify multiple modules to run.

	When stdin is not a terminal, after running scc-log, a random 
	delay is used to sleep before the files are transferred to the
	destination. This avoids flooding the receiving system when all
	your systems start scc at the same time.
	The transferred files are tarred, compressed and uuencoded when
	sent via email. For RedHat, uuencode is part of 
	Applications/Archiving.

	The files to be transferred can be several MB. Check the mail-
	connectivity first by using the -t option. This will send empty files.
	Use the -p option with "smtp" to use the SMTP-protocol directly and
	skip the mail-transport facility of the client.

	Refer to the manual page of scc-log(1) for troubleshooting
	when scc seems to "hang".

	Use the environment variable SCC_PROFILING to add timing data
	to the snapshot. This enables you to locate possible performance
	bottlenecks. The default value activates profiling and performance
	data is added to the snapshot.

	scc-collect and its modules use sensible defaults to avoid that 
	many systems require a configuration file. When the defaults are
	insufficient, copy /etc/opt/scc/newconfig/scc-localize to
	/etc/opt/scc/conf/scc-localize and uncomment the required variables.
	When the --no_conf_sub_dir option was used with the relocate script,
	the copy is not required.

OPTIONS


	-a|--alternate <alt>      Use <alt> as directory where from snapshots
	                          and logbooks of alternate systems are to
	                          be transferred to the scc-server.
	                          The -f option is ignored. The program
	                          that produces the alternate snapshots is
	                          responsible for the correct format and
	                          contents of the scc-data.
	                          When the files are symbolic links, they are
	                          removed after transferring their contents.
	                          For each system <s>, this directory should
	                          contain the files: scc.<s>.cur, scc.<s>.log,
	                          scc.<s>.html and scc.<s>.log.html
	                          Implies the -n option.
	-c|--comment <remark>     Add a remark to the logbook, indicating
	                          a "specific" reason to run scc. To mark the
	                          implementation of RFC "123" on a system, use:

                                 scc                # record changes up to this moment
                                 # perform the tasks required by the RFC
                                 scc -c "RFC 123"   # record changes due to RFC

	-d|--delay <delay>        Maximum delay (in seconds) to wait before the
	                          collection of data starts.
	-e|--extra <mod>          scc-collect runs all system modules and matching <mod> user modules.
	                          Where <mod> can contain shell filename wildcards. When used in 
	                          combination with the -v option, make sure that each 
	                          invocation activates the same set of user modules.
	-S|--selection <mod>      Run selected (system or user) module(s) for virtual host (-v).
	                          Where <mod> can contain shell filename wildcards.
	                          To detect and process layout version changes, use the -r option
	                          on the next invocation or include module general in the selection.
	-f|--fqdn                 Use the full qualified name, not the short
	                          hostname, when sending files to the SCC server.
	                          On the SCC client, all filenames contain the 
	                          short hostname only.
	-h|--help                 Display the syntax and exit.
	-F|--from <from>          Mail-address used as sender of mailed data.
	                          Default value is <root@host.domain.com>.
	-i|--smtp <smtp>          SMTP-server to connect to; implies "-p smtp".
	                          Use the -F option when the SMTP-server does
	                          not allow relaying and the domain of the system
	                          differs from the domain of the SMP-server.
	                          Check the logfile in /var/opt/scc/data.
	-I|--ident <ident>        Identity file for scp; implies "-p scp"
	-k|--key <key>            File containing public key of scc-server;
	                          used to encrypt the data that is sent via 
	                          mail/smtp. Refer to the documentation of scc-srv for details.
	                          Add the key-file to scc-localize (SCC_KEY_FILE) to make sure
	                          that all invocations of scc (and scc-log during upgrades) 
	                          lead to encrypted data for scc-pull.
	-l|--label <label>        Label to indicate the function of the system. Use <label>
	                          in the webinterface of scc-srv to select/group systems.
	                          The label is preserved for next runs until this option is
	                          used again.
	-m|--max_age <max>        Entries in the log-file, that are older
	                          than <max> months, are deleted
	-n|--norun                Do not collect new SCC-data. Send the files
	                          right away.
	-o|--option no_hosts      No strict host checking for scp. Implies -p scp.
	                          Dropbear ignores the ssh/scp options used for this.
	            new_pack      Use new routine to pack scc-data for transfer. Upgrade scc-srv
	                          to 1.15.20 before using this option.
	-p|--prog <prog>          Use <prog> to send the files in a specific
	                          packaged bundle to scc-server. Default value
	                          for <prog> is pull. Supported values are:
	                            cp      copy to local directory <dest>
	                            ftp     transfer to <dir> on <host> by using ~/.netrc
	                            mail    email to scc-server
	                            pull    local transfer to /var/opt/scc/data/transfer;
	                                    transfer is done later by scc-srv.
	                                    Ignores -s options.
	                            rcp     remote-copy to scc-server
	                            scp     SSH-copy to scc-server
	                            smtp    use SMTP to connect directly to port
	                                    25 of host-part of <dest> or to <smtp>
	                                    of -i option. Optionally use the port
	                                    specified with the -P option.
	                                    Logfile in /var/opt/scc/data/smtp.log
	-P|--port <port>          The non-default port for -p scp|smtp.
	-r|--restart              Restart collection by removing the existing/current
	                          snapshot. This option is usefull for systems with
	                          frequent changes where you want the latest snapshot
	                          on scc-srv.
	-s|--destination <dest>   Destination to send the files to. The format 
	                          depends upon the transfer program:
	                            cp          local directory: /usr/local/share/scc-srv/data
	                            ftp         destination: <host>:<dir>
	                            mail|smtp   email-address: scc@myserver.com
	                                        With smptp, use the -F option when
	                                        the domain of <dest> differs from the
	                                        domain of the SMTP-server (-i option).
	                            rcp|scp     destination: <user>@<host>:<dir>
	                                        The <user> and <dir> parts are optional.
			                        Optional use the port for scp specified
                                             with the -P option.
                               When the directory part is omitted for cp, ftp, rcp and
                               scp, the data directory of scc is used to determine the
                               default data directory of scc-srv.
	-t|--test                 Test connectivity by sending empty files, no delay 
	                          is used (implies -d 0) and no data is collected.
	-u|--user <user>          To be used with -p pull option. The files can be 
	                          transferred by <user>.
	-v|--virtual <host>       Do not use the hostname of the system, as base for
	                          all scc-files, use <host> instead. This option should
	                          be used to run specific user modules with frequently
	                          changing data using the -e option. This avoids
	                          "changes" in the scc-data of the system itself.
	                          This option requires the -e option.
	                          Note that the resulting files differ from the regular
	                          SCC data and html files.
	-V|--version              Print version of program and exit

ARGUMENTS


	None.

DIAGNOSTICS


	The program issues the following messages to stderr:

	Syntax error, use: scc <options>
	A syntax error has been detected and reported.

	scc: Syntax error, missing argument for option <option>
	The indicated option is missing argument(s).

	scc: non-numeric interval
	A non-numeric value has been specified for <delay>.

	scc: wrong format with of mail-address: <address>
	The mail-address (supplied with the -F or the -s option) does not 
	start with "<" or does not end with ">".

	scc: non-numeric argument for -m option: <max>
	Use only numeric arguments for -m option.

	scc: unknown transfer-method: <prog>
	The argument of the -p option has an unsupported value.

	scc: missing destination for method <prog>
	Add the --dest option to specify a destination.

	scc: cannot use -S option without -v option
	Limiting system modules only makes sense for a virtual host run.

	scc: use -e and/or -S option with -v option
	The -v option can only be used when the -e and/or -S option is used.

	scc: mail not found
	This program is used to sent scc data to scc-srv.

	scc: uuencode not found
	This program is used to sent scc data to scc-srv. On RedHat
	it is part of: Applications/Archiving.

	scc: openssl not found
	This program is used when the -k option is used to encrypt the data to 
	be sent via email. When openssl is not found in PATH, no data is sent.

	scc: cannot find nc and telnet to transfer data
	One of these programs is used to send data via smtp to scc-srv.

	scc: scp not found
	This program is used to send the scc data to scc-srv.

	scc: cannot use -t option combined with -a option
	Do not combine the -a and the -t option.

	scc: cannot access target directory: <dest>
	The target directory for the copy does not exist.

	scc: cannot determine domainname
	The domainname cannot be determined while using the -f option.

	scc: cannot access <alt>
	The directory for scc-data of alternate systems cannot be accessed.

	scc: cannot access identity/key-file <ident>
	The indicated file cannot be accessed.

	scc: unknown user: <user>
	The supplied username is not a known user.

	scc: no data to transfer, run scc without -n option
	The transfer directory does not contain any files. Rerun scc (without 
	the -n option) to collect data in the transfer directory.

	scc: non-root users cannot use the -u option
	Use the -u option only when invoking as root.

RETURN VALUE


	Upon completion, the program returns one of the following values:

		0 successful completion
		1 Syntax error
		2 Runtime error

EXAMPLES


	To take a daily snapshot and transfer the files to myserver, use a 
	cronjob like:

	   0 23 * * * /opt/scc/bin/scc -s "<scc-transfer@otherserver.mydom>"

	This runs scc-log daily and transfers the files to otherserver.
	On otherserver the alias file should contain a line like:

	   scc-transfer: "|/usr/local/bin/scc-receive-mail"

	Refer to the manual page of scc-srv for the proper setup of the
	server part of SCC.

EXTERNAL INFLUENCES


	The names of the files that are sent to the scc-server, must be
	known in the server-software also: scc-transfer.gz, scc-transfer.Z
	or scc-transfer depending on the presence of compression software.
	Refer to the manual page of scc-srv for the setup of the scc-server.

	The files that are send to the server, do not contain the style.css
	and main index.html file as this transfer to the sever is meant to
	process the data from the client.

	This program uses gzip or compress to compress the data.
	It uses uuencode to transfer the data through email.
	Either netcat (nc) or telnet are used with transfer via smtp.

	Use environment variable SCC_DATA to specify an alternative directory
	for the SCC data files. Should be an absolute path.

COPYRIGHT


	scc is free software under the terms of the GNU General Public 
	License. Copyright (C) 2001-2004 Open Challenge B.V.,
	2004-2005 OpenEyeT Professional Services, 2005-2015 QNH.

FILES


	- /var/opt/scc/data - directory for data files
		scc.<hostname>.cur - current SCC-snapshot
		scc.<hostname>.html - current SCC-snapshot in HTML-format
		scc.<hostname>.log - logbook for changes in SCC-snapshots
		scc.<hostname>.log.html - logbook in HTML-format
		smtp.log - logfile for transport with -p smtp
	The filename on the scc-server is: scc.<hostname>.tar.gz When
	gzip is not found, compress is used and ".gz" is changed in ".Z".
	When compress is also not found, cat is used and ".gz" is removed
	from the filename. When the -f option is used, the DNS-domain is
	added to the remote filenames.
	When rcp/scp are used, the file scc.<hostname>.signal is used to
	indicate the completed transfer of the scc-data on the server.
	- /var/opt/scc/data/transfer - directory for pull and transfer

SEE ALSO


	scc(1), scc-cmp(1), scc-collect(1), scc-log(1), scc-log2html(1),
	scc-plugin(1), scc-snap2html(1), scc(4), scc(5)

VERSION


	$Revision: 5917 $

)	;;
	echo "${ProgName}: alternative SCC_DATA (${SCC_DATA}) should be an absolute path" >&2
xit 2;;
ac

Perform the security settings before calling any program.
TH=${SCC_BIN}:/sbin:/usr/sbin:/usr/bin:/bin;	export PATH

port TMPDIR=${SCC_TMP}
port TMP=${SCC_TMP}

port SHELL=/bin/sh

ask 066
! -d ${SCC_DATA} ] && mkdir -p ${SCC_DATA} 2>/dev/null
! -d ${SCC_DATA}/transfer ] && mkdir -p ${SCC_DATA}/transfer 2>/dev/null
! -d ${SCC_TMP} ] && mkdir -p ${SCC_TMP} 2>/dev/null
ask 077

${SCC_BIN}/scc_modules/scc_utils

-r ${SCC_CONF}/scc-localize ] && . ${SCC_CONF}/scc-localize

Some systems do not provide nice.
exe="$(which nice 2>/dev/null)"
[ ! -x "${n_exe}" ]
en
lias nice=""


The default directory on scc-srv to send data to, determine according to our installation.
fault_srv_dir="$(echo "${SCC_DATA}" | sed -e 's/scc/scc-srv/')/transfer/cp"

ndom="$(get_RANDOM)"
st_dir="${SCC_TMP}/scc-d-$$_${random}"
P_FILE="${SCC_TMP}/scc-f-$$_${random}"

D_LINE="${ProgName} [ -a|--alternate <alt> ]
	[ -c|--comment <remark> ]
	[ -d|--delay <delay> ]
	[ -e|--extra <mod> ]
	[ -S|--selection <mod> ]
	[ -f|--fqdn ]
	[ -h|--help ]
	[ -F|--from <from> ]
	[ -i|--smtp <smtp> ]
	[ -I|--ident <ident> ]
	[ -k|--key <key> ]
	[ -l|--label <label> ]
	[ -m|--max_age <max> ]
	[ -n|--norun ]
		[ -o|--option no_hosts ]
	[ -p|--prog <prog> ]
	[ -P|--port <port> ]
	[ -r|--restart ]
	[ -s|--destination <dest> ]
	[ -t|--test ]
	[ -u|--user <user> ]
	[ -v|--virtual <host> ]
	[ -V|--version ]"

NTAX_ERROR="Syntax error, use: ${CMD_LINE}"

SSING_OPT_ARG="${ProgName}: Syntax error, missing argument for option:"
pty_files=0
og=pull
x_interval=0
ternate_dir=""
port SCC_KEY_FILE=""
bel=""
x_months=0				# 0 means: no limit.
port SCC_NEW_PACK=""
st=""
er_modules=""
lect_modules=""
mark=""
dn=""
_run=1
rt_default=""
rt=""
start=""
tp_server=""
h_identity=""
rict_host_checking=""
er=""
rtual_host=""
rtual_host_opt=""
tp_from=""
ile [ $# -gt 0 ]

ase "${1}" in
a|--alternate)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	alternate_dir="${2}";
	if [ ! -d "${alternate_dir}" ]
	then
		echo "${ProgName}: cannot access ${alternate_dir}" >&2
		exit 2
	fi
	do_run=0;
	shift 2;;

c|--comment)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	remark="$(echo "${2}" | tr -d "\012")"	# be sure that the remark is single-line
	shift 2;;

d|--delay)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	case "${2}" in
	[0-9]*)	max_interval=${2};;
	*)	echo "${ProgName}: non-numeric interval: ${2}" >&2
		exit 1;;
	esac
	shift 2;;

e|--extra)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	user_modules="${2}";			# Pass on to scc-log
	shift 2;;

S|--selection)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	select_modules="${2}";			# Pass on to scc-log
	shift 2;;

F|--from)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	smtp_from="${2}";
	case "${smtp_from}" in
	\<**\>)		;;				# valid form: <adress>
	\<*|*\>)	echo "${ProgName}: wrong format of mail-address: ${smtp_from}" >&2
			exit 1;;
	*@*)		smtp_from="<${smtp_from}>"	# non-rfc compliant; add < and >
	esac
	shift 2;;

i|--smtp)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	smtp_server="${2}";
	prog=smtp;		# No need for -p smtp with -i option
	port_default=25
	shift 2;;

I|--ident)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	if [ ! -f "${2}" ]
	then
		echo "${ProgName}: cannot access identity-file ${2}" >&2
		exit 1;
	fi
	ssh_identity="-i ${2}"		# -i option for scp.
	prog=scp
	port_default=22
	shift 2;;

k|--key)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	if [ ! -f "${2}" ]
	then
		echo "${ProgName}: cannot access key-file ${2}" >&2
		exit 1;
	fi
	SCC_KEY_FILE="${2}";
	shift 2;;

l|--label)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	label="${2}";
	shift 2;;

m|--max_age)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	case "${2}" in
	[0-9]*)	max_months=${2};;
	*)	echo "${ProgName}: non-numeric argument for -m option: ${2}" >&2
		exit 1;
	esac
	shift 2;;

o|--option)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	case "${2}" in
	no_hosts)	strict_host_checking="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
			prog="scp"
			port_default=22
			;;
	new_pack)	SCC_NEW_PACK="yes"
			;;
	*)		echo "${ProgName}: unknown value for -o option: ${2}" >&2
			exit 1;;
	esac
	shift 2;;

p|--prog)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	port_default=25
	case "${2}" in
	cp|ftp|pull|mail|rcp)	prog="${2}";;
	scp)			port_default=22
				prog="${2}";;
	smtp)			port_default=25
				prog="${2}";;
	*)			echo "${ProgName}: unknown transfer-method: ${2}" >&2
				exit 1;;
	esac
	shift 2;;

P|--port)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	port="${2}"
	shift 2;;

s|--dest)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	dest="${2}"
	shift 2;;

u|--user)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	user="${2}"
	id -u ${user} >/dev/null 2>/dev/null
	if [ $? -ne 0 ]
	then
		echo "${ProgName}: unknown user: ${user}" >&2
		exit 2
	fi
	shift 2;;

v|--virtual)	[ -z "${2:-}" ] && echo "${MISSING_OPT_ARG}: ${1}" >&2 && exit 1
	virtual_host_opt=" -v ${2}";	# Pass on to scc-log
	virtual_host="${2}";
	shift 2;;

f|--fqdn)	fqdn="-f"			# Pass on to scc-log
	shift 1;;

h|--help)	echo "${CMD_LINE}"
	exit 0;;

n|--norun)	do_run=0
	shift 1;;

r|--restart)	restart="-r"
	shift 1;;

t|--test)	empty_files=1
	shift 1;;

V|--version)	echo "1.23.185"
	exit 0;;

)		echo "${SYNTAX_ERROR}" >&2
	exit 1;;
sac
ne

[ ${empty_files} -eq 1 -a "${alternate_dir}" ]
en
cho "${ProgName}: cannot use -t option combined with -a option" >&2
xit 2


[ -z "${virtual_host}" -a "${select_modules}" ]
en
cho "${ProgName}: cannot use -S option without -v option" >&2
xit 1


[ "${virtual_host}" -a -z "${select_modules}" -a -z "${user_modules}" ]
en
cho "${ProgName}: use -e and/or -S option with -v option" >&2
xit 1


[ -z "${port}" -a ! -z "${port_default}" ]
en
ort=${port_default}


stname_exe="$(which hostname 2>/dev/null)"
[ -x "${hostname_exe}" ]
en
ull_name=$(hostname 2>/dev/null)
se
ull_name=${HOSTNAME:-}

[ -z "${full_name}" ]
en
ull_name="empty"			# same value as in scc-log and scc-collect.

r_name=${full_name%%.*}			# Erase domain.
[ -n "${virtual_host}" ]
en
ur_name="${virtual_host}"


se "${prog}" in
il|smtp)	which uuencode 2>/dev/null >/dev/null
if [ $? -ne 0 ]
then
	echo "${ProgName}: uuencode not found" >&2
	exit 2
fi
which mail 2>/dev/null >/dev/null
if [ $? -ne 0 ]
then
	echo "${ProgName}: mail not found" >&2
	exit 2
fi
;;
ac

[ "${user}" ]
en
f [ "$(id -u)" -ne 0 ]
hen
echo "${ProgName}: non-root users cannot use the -u option" >&2
exit 2
i

This feature has been suggested by Sven Weise.


The files should be retrieved by a non-root user.

hmod o+x ${SCC_DATA}/.. ${SCC_DATA}
hown "${user}" ${SCC_DATA}/transfer


il_dest=""
[ -z "${dest}" ]
en
ase "${prog}" in
p)	dest="${default_srv_dir}";;
ull)	dest="${SCC_DATA}/transfer";;				# Use default directory
)	echo "${ProgName}: missing destination for method ${prog}" >&2
exit 2;;
sac
se
ase "${prog}" in
tp|rcp|scp)	if [ "${dest%:*}" = "${dest}" ]
	then
		# Without the separator ':', the directory is not specified, use the default directory:
		dest="${dest}:${default_srv_dir}"
	fi ;;
ull)	dest="${SCC_DATA}/transfer";;				# Override specified directory
ail)	mail_dest="${dest}";;
mtp)	# Determine the sender of the mail
if [ -z "${smtp_from}" ]
then
	sender="<root@${full_name}>"
else
	sender="${smtp_from}"
fi

# Determine the destination
if [ -z "${smtp_server}" ]
then
	# Split the email-address into host and account
	mail_dest=${dest%%@*}
	smtp_server=${dest##*@}
else
	mail_dest=${dest}
fi
;;
sac

f [ -n "${mail_dest}" ]
hen
# Check the format of the mail-destination.
case "${mail_dest}" in
\<*\>)		;;					# valid form: <adress>
\<*|*\>)	echo "${ProgName}: wrong format of mail-address: ${mail_dest}" >&2
		exit 1;;
*)		mail_dest="<${mail_dest}>"	# non-rfc compliant; add < and >
esac
i


[ "${dest}" ]
en
ase "${prog}" in
p)	if [ ! -d "${dest}" ]
then
	echo "${ProgName}: cannot access target directory: ${dest}" >&2
	exit 2
fi
;;
cp)	which scp 2>/dev/null >/dev/null
if [ $? -ne 0 ]
then
	echo "${ProgName}: scp not found" >&2
	exit 2
fi
;;
sac


IL_NAME=scc-transfer-data
SSPHRASE_FILE="passphrase"

ap 'rm -rf ${TMP_FILE} ${test_dir} 2>/dev/null' 0
ap "exit 2" 1 2 3 15

[ ${max_interval} -gt 1 ]
en
andom="$(get_RANDOM)"
leep $(( random % max_interval ))


[ ${empty_files} -gt 0 ]
en

Create the empty test-files.

kdir ${test_dir}
d ${test_dir}

ransfer_name="${SCC_HOST_ALIAS:-}"
f [ -z "${transfer_name}" ]
hen
transfer_name="${our_name}"
i
or s in cur log log.html html
o
touch scc.${transfer_name}.${s}
one
cc_pack ${transfer_name}
temporary directory and files are removed at the exit of the script.
d ${SCC_DATA}/transfer
se
f [ ${do_run} -eq 1 ]
hen
if [ -z "${alternate_dir}" ]
then
	# Produce new, real SCC-data
	nice ${SCC_BIN}/scc-log -c "${remark}" -e "${user_modules}" -S "${select_modules}" ${fqdn} -l "${label}" -m "${max_months}" ${restart} ${virtual_host_opt}
	if [ $? -ne 0 ]
	then
		exit 1
	fi
fi
lse
if [ -z "$(ls ${SCC_DATA}/transfer/*signal 2>/dev/null )" ]
then
	cd ${SCC_DATA}
	if [ "${SCC_HOST_ALIAS:-}" ]
	then
		for suffix in cur html log log.html
		do
			rm -f scc.${SCC_HOST_ALIAS}.${suffix}
			ln -s scc.${our_name}.${suffix} scc.${SCC_HOST_ALIAS}.${suffix}
		done
		scc_pack ${SCC_HOST_ALIAS}
		rm -f scc.${SCC_HOST_ALIAS}.*
	else
		scc_pack ${our_name}
	fi
fi
i

d ${SCC_DATA}/transfer


Only send the files when we have a destination.
[ -z "${dest}" ]
en
xit 0


[ "${alternate_dir}" ]
en
d "${alternate_dir}"

Check all snapshots.

or f in scc.*.cur
o
host="${f%.cur}"
scc_pack ${host#scc.}		# Ignore SCC_HOST_ALIAS from scc-localize

# Remove symbolic links, they need to be recreated 
# when collecting the data in the alternate directory.
for s in cur html log log.html
do
	if [ -h scc.${host}.${s} ]
	then
		rm -f scc.${host}.${s}
	fi
done

one


Transfer all files present in the current directory
-f ${TMP_FILE}
-tr					|
d	-n			\
e '/.signal$/d'	\
e '/^scc./p'			|
ile read REMOTE_NAME

f [ "${SCC_NEW_PACK}" ]
hen
REMOTE_SIGNAL=${REMOTE_NAME%.data}.signal
lse
REMOTE_SIGNAL=${REMOTE_NAME%.tar*}.signal
i

f [ ! -f ${REMOTE_NAME} -o ! -f ${REMOTE_SIGNAL} ]
hen
# When either of the data or the signal file is missing, we got a rogue filename starting with scc.
continue
i

ase "${prog}" in
ail|smtp)	suffix="${REMOTE_NAME#*tar}"
if [ "${SCC_NEW_PACK}" ]
then
	suffix=""
elif [ -n "${SCC_KEY_FILE}" ]
then
	e_exe="$(which openssl 2>/dev/null)"
	if [ ! -x "${e_exe}" ]
	then
		echo "${ProgName}: openssl not found" >&2
		exit 2
	fi

	if [ ! -f ${PASSPHRASE_FILE} ]
	then
		# Generate a random passphrase.
		# Replace \0 and \n to avoid short (possibly empty) passwords.
		openssl rand 40			|
		tr -s "\012\000" "n0" > ${PASSPHRASE_FILE}
	fi

	# Encrypt the scc-data with triple DES, using the random passphrase.
	rm -f ${MAIL_NAME}${suffix}.e
	openssl	des3				\
		-in ${REMOTE_NAME}		\
		-out ${MAIL_NAME}${suffix}.e	\
		-pass file:./${PASSPHRASE_FILE}	\
		-e				\
		-salt -S 83AF2E2D8BE716C2

	# Encrypt the passphrase with the public key.
	openssl	rsautl				\
		-in ${PASSPHRASE_FILE}		\
		-out ${PASSPHRASE_FILE}.e	\
		-inkey "${SCC_KEY_FILE}"	\
		-pubin				\
		-encrypt 2>/dev/null
	rm -f ${PASSPHRASE_FILE}

	# Combine the encrypted scc-data and the encrypted passphrase.
	# The scc-server has to:
	# - untar the combined, encrypted scc-data and passphrase
	# - decrypt the passphrase (using it's own private key)
	# - decrypt the scc-data with the decrypted passphrase
	tar cf ${REMOTE_NAME}.e.tar ${PASSPHRASE_FILE}.e ${MAIL_NAME}${suffix}.e
	rm -f ${PASSPHRASE_FILE}.e ${REMOTE_NAME} ${REMOTE_NAME}.e ${MAIL_NAME}${suffix}.e
	REMOTE_NAME=${REMOTE_NAME}.e.tar

	suffix="${suffix}.e.tar"

fi	# Encryption required?

if [ "${prog}" = "mail" ]
then
	uuencode ${MAIL_NAME}${suffix} <${REMOTE_NAME}		|
	mail "${mail_dest}"
else	# prog = smtp
	transfer_exe="$(which nc 2>/dev/null)"
	transfer_opt="-v"
	if [ ! -x "${transfer_exe}" ]
	then
		transfer_exe="$(which telnet 2>/dev/null)"
		transfer_opt=""
	fi
	if [ ! -x "${transfer_exe}" ]
	then
		echo "${ProgName}: cannot find nc and telnet to transfer data" >&2
		exit 2
	fi
	# Use smtp to transfer the data. 
	# Use sleep to avoid that our commands are sent too fast to the SMTP-server.
	(
		sleep 5
		echo "helo ${our_name}"
		sleep 5
		echo "mail from: ${sender}"
		sleep 5
		echo "rcpt to: ${mail_dest}"
		sleep 5
		echo "data"
		sleep 5
		echo "subject: SCC snapshot in ${REMOTE_NAME}"
		sleep 5
		echo "to: ${mail_dest}"
		echo ""
		sleep 5
		uuencode ${MAIL_NAME}${suffix} <${REMOTE_NAME}
		echo "."
		sleep 5
		echo "quit"
		sleep 5
	)	|
	"${transfer_exe}" ${transfer_opt} ${smtp_server} ${port} >${SCC_DATA}/smtp.log 2>&1
	# Inspect the file to find out about errors. No parsing of the logfile (yet).
	# Luc Capronnier suggests looking for values below 400 in the response.
fi
rm -f ${REMOTE_NAME} ${MAIL_NAME}${suffix}
;;

cp)	# Produce an empty signal-file to indicate that transfer is in progress.
>${REMOTE_SIGNAL}
rcp ${REMOTE_SIGNAL} ${dest}

# Transfer the packed files followed by the non-empty signal file to indicate completion of transfer.
echo "done" >${REMOTE_SIGNAL}
rcp ${REMOTE_NAME} ${REMOTE_SIGNAL} ${dest}
;;

ull)	# scc-log put the data and signal file in the correct place with correct ownership.
;;

cp)	# Produce an empty signal-file to indicate that transfer is in progress.
>${REMOTE_SIGNAL}
port_scp="-P ${port}"
quiet="-q"
connect_timeout="-o ConnectTimeout=30"
scp ${connect_timeout} ${quiet} ${port_scp} ${ssh_identity} ${strict_host_checking} ${REMOTE_SIGNAL} ${dest} >/dev/null 2>/dev/null
if [ $? -ne 0 ]
then
	# Some dropbear implementations of scp complain about the -q option and do
	# not show the progress without the -q option.
	# Do not use the -q option when a dropbear implementation results in an error.
	exe="$(ls -l "$(which scp 2>/dev/null)" | sed -e 's@.*/@@')"
	if [ "${exe}" = "dropbear" ]
	then
		quiet=""
	else
		connect_timeout=""	# ignore, might be an unknown option for this scp
	fi
	scp ${connect_timeout} ${quiet} ${port_scp} ${ssh_identity} ${strict_host_checking} ${REMOTE_SIGNAL} ${dest} >/dev/null 2>/dev/null
fi

# Transfer the packed files followed by the non-empty signal file to indicate completion of transfer.
echo "done" >${REMOTE_SIGNAL}
scp ${connect_timeout} ${quiet} ${port_scp} ${ssh_identity} ${strict_host_checking} ${REMOTE_NAME} ${REMOTE_SIGNAL} ${dest} >/dev/null 2>/dev/null
;;

p)	# Produce an empty signal-file to indicate that transfer is in progress.
>${dest}/${REMOTE_SIGNAL}

# Move the packed files to the destination
mv -f ${REMOTE_NAME} ${dest}

# Replace the empty signal-file to indicate that transfer is complete.
echo "done" >>${dest}/${REMOTE_SIGNAL}
;;

tp)	# ${dest} is <host>:<dir>
host=${dest%:*}
dir=${dest#*:}

# Produce an empty signal-file to indicate that transfer is in progress.
>${REMOTE_SIGNAL}
ftp ${host} <<-_X_
	cd ${dir}
	bin
	put ${REMOTE_SIGNAL}
_X_

# Transfer the packed files followed by the non-empty signal file to indicate completion of transfer.
echo "done" >${REMOTE_SIGNAL}
ftp ${host} <<-_X_
	cd ${dir}
	bin
	put ${REMOTE_NAME}
	put ${REMOTE_SIGNAL}
_X_
;;
sac

f [ "${prog}" != "pull" ]
hen
rm -f ${REMOTE_SIGNAL} ${REMOTE_NAME}
i

ouch ${TMP_FILE}
ne

[ ! -f ${TMP_FILE} ]
en
cho "${ProgName}: no data to transfer via ${prog}, run scc without -n option" >&2
xit 2


it 0