файл crontab удаленного пользователя

Я создал немного сценария, на основе ответов в этом потоке, который автоматически вытянет, проанализирует и установит текущий Gmail smtp сертификаты. Это должно смочь обработать его, если количество сертификатов изменяется снова.

Вот pastebin с подсветкой синтаксиса также

#!/bin/bash

# This script pulls ssl certs for using gmail smtp. Adapted from the following config explaination:
# https://serverfault.com/questions/498588/smtp-gmail-com-from-bash-gives-error-in-certificate-peers-certificate-issuer

certdirectory="/home/user/.certs"

# Functions

fail() {
    ec=$?
    [ "${ec}" == "0" ] && ec=1
    echo -e "FAILED[code=$ec]: $@"
    exit $ec
}

warn(){
echo -e "WARNING $@"
}

cleanup() {
  rm allgcert* || warn "Cleanup of files errored"
  rm gcert* || warn "Cleanup of files errored"
}

failclean() {
  cleanup
  fail "$@"
}

# Count number of certs currently being used (can change from time to time)
numcerts=$(echo -n | openssl s_client -showcerts -connect smtp.gmail.com:465 | grep -c "i:")

# Create the certs directory if it does not exist
mkdir -p $certdirectory || fail "Unable to create certificates directory"

# Pull certs to a local file for parsing
echo -n | openssl s_client -showcerts -connect smtp.gmail.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > allgcert || failclean "Unable to pull certs from smtp.gmail.com"

# Parses certs output based on the number of certs, and outputs to individual files
if (($numcerts > 1)) ; then
  # Pulls the first cert out as it needs one extra line
  sed '1,27!d' allgcert > gcert1
  # For subsequent certs, it multiplies the cert number by the number of lines in the file where it should exist
  for i in $(seq 2 $numcerts) ; do
    sed "$((2 + (((($i - 1)) * 26))))"','"$((1 + (($i * 26))))"'!d' allgcert > gcert${i}
  done
fi

# Parses out certificate issuer names for installation
echo -n | openssl s_client -showcerts -connect smtp.gmail.com:465 | grep i: | sed -e 's,.*=,,' > allgcertnames || failclean "Unable to output parsed names for certificates"

for i in $(seq 1 $numcerts) ; do
  certutil -A -n "$(sed -n ${i}p allgcertnames)" -t "TC,," -d $certdirectory -i gcert${i} || failclean "Unable to import certificates to database"
done

cleanup

6
задан 3 October 2011 в 07:47
1 ответ

По умолчанию userdel не удаляет cron пользователя, в и задания печати. Для этого раскомментируйте следующую строку в /etc/login.defs :

USERDEL_CMD /usr/sbin/userdel_local 

Вот пример сценария userdel_local :

#! /bin/sh

if [ $# != 1 ]; then
    echo "Usage: $0 username"
    exit 1
fi

crontab -r -u $1

Итак, всякий раз, когда вы выполняете userdel , все задания cron, принадлежащие пользователю, будут удалены.

10
ответ дан 3 December 2019 в 00:16

Теги

Похожие вопросы