Skip to content

Instantly share code, notes, and snippets.

@novoid
Created August 24, 2020 09:44
Show Gist options
  • Save novoid/eb553dd2e9ea9f78d182577ea98ccb3d to your computer and use it in GitHub Desktop.
Save novoid/eb553dd2e9ea9f78d182577ea98ccb3d to your computer and use it in GitHub Desktop.
vk-get-crontab-and-misc.sh
#!/bin/sh
## this script saves crontabs and misc things to a file
readonly SCRIPTNAME=$(basename $0)
readonly HOST=$(hostname)
OUTPUTDIR="${HOME}/archive/backup/"
[ "x$HOST" = "xHOSTX" ] && OUTPUTDIR="${HOME}/hosts/HOSTX/archive"
[ "x$HOST" = "xHOSTBUSINESS" ] && OUTPUTDIR="${HOME}/share/backup"
OUTPUTFILE="${OUTPUTDIR}/${SCRIPTNAME}_${HOST}.log"
readonly DATESTAMP=`/bin/date '+%Y-%m-%d_%H:%M:%S'`
readonly DELIMITER="======================================================================================="
heading() {
echo "===== ${@} ======" >> "${OUTPUTFILE}"
}
save_dpkg_list() {
heading 'dpkg --get-selections'
dpkg --get-selections >> "${OUTPUTFILE}"
}
save_installed_cygwin_packages() {
heading "cygcheck -c"
cygcheck -c >> "${OUTPUTFILE}"
echo "${DELIMITER}" >> "${OUTPUTFILE}"
}
save_installed_babun_packages() {
heading "pact show"
pact show >> "${OUTPUTFILE}"
echo "${DELIMITER}" >> "${OUTPUTFILE}"
}
save_unison_config() {
readonly UNISONBACKUPDIR="${OUTPUTDIR}/unison"
heading "... saving unison config to ${UNISONBACKUPDIR}"
ls -la .unison/*prf >> "${OUTPUTFILE}"
cp .unison/*prf "${UNISONBACKUPDIR}/"
echo "${DELIMITER}" >> "${OUTPUTFILE}"
}
save_file() {
local myfile="${1}"
if [ -f "${myfile}" ]; then
heading "... saving ${myfile} to ${OUTPUTDIR}"
cp "${myfile}" "${OUTPUTDIR}/"
else
echo "ERROR: \"${myfile}\" is not an existing file" | tee -a "${OUTPUTFILE}"
fi
echo "${DELIMITER}" >> "${OUTPUTFILE}"
}
cd $HOME
echo "${DELIMITER}" > "${OUTPUTFILE}"
echo ${DATESTAMP} >> "${OUTPUTFILE}"
echo "${DELIMITER}" >> "${OUTPUTFILE}"
heading "df -h"
df -h >> "${OUTPUTFILE}"
echo "${DELIMITER}" >> "${OUTPUTFILE}"
heading "crontab -l"
crontab -l >> "${OUTPUTFILE}"
echo "${DELIMITER}" >> "${OUTPUTFILE}"
heading "ls -la ${HOME}/bin/"
ls -la ${HOME}/bin/ >> "${OUTPUTFILE}"
echo "${DELIMITER}" >> "${OUTPUTFILE}"
heading "ls -la ${HOME}/"
ls -la ${HOME}/ >> "${OUTPUTFILE}"
echo "${DELIMITER}" >> "${OUTPUTFILE}"
[ "x$HOST" = "xHOSTX" ] && save_installed_babun_packages
[ "x$HOST" = "xHOSTX" ] && save_unison_config
[ "x$HOST" = "xHOSTX" ] && save_file ".gitconfig"
[ "x$HOST" = "xHOSTY" ] && save_dpkg_list
[ "x$HOST" = "xHOSTZ" ] && save_dpkg_list
[ "x$HOST" = "xHOSTBUSINESS" ] && save_dpkg_list
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment