| #!/bin/sh |
| #********************************************************************* |
| # Copyright (c) International Business Machines Corp., 2000 |
| # |
| # This program is free software; you can redistribute it and/or modify |
| # it under the terms of the GNU General Public License as published by |
| # the Free Software Foundation; either version 2 of the License, or |
| # (at your option) any later version. |
| # |
| # This program is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| # the GNU General Public License for more details. |
| # |
| # You should have received a copy of the GNU General Public License |
| # along with this program; if not, write to the Free Software |
| # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| # |
| # FILE : cron02 |
| # |
| # PURPOSE: Test a postive cron job |
| # - add new job |
| # - check correct execution of job |
| # - delete job |
| # |
| # HISTORY: |
| # SUSE |
| # |
| |
| TEST_USER="c01_user" |
| TEST_USER_GROUP="users" |
| TEST_USER_HOMEDIR="/home/$TEST_USER" |
| |
| #----------------------------------------------------------------------- |
| # FUNCTION: do_setup |
| #----------------------------------------------------------------------- |
| |
| do_setup(){ |
| #erase any data from potential defunt cron test |
| rm -rf /tmp/crontest > /dev/null 2>&1 |
| |
| #erase user if he may exist , so we can have a clean env |
| rm -rf /home/$TEST_USER |
| userdel $TEST_USER |
| sleep 1 |
| |
| useradd -m -g $TEST_USER_GROUP $TEST_USER |
| if [ $? != 0 ] |
| then { |
| echo "Could not add test user $TEST_USER to system $RHOST." |
| exit 1 |
| } |
| fi |
| |
| # running under systemd? |
| if command -v systemctl >/dev/null 2>&1; then |
| HAVE_SYSTEMCTL=true |
| else |
| HAVE_SYSTEMCTL=false |
| fi |
| |
| # restart cron daemon |
| # Red Hat uses crond, SuSE/Other uses cron. |
| if [ -x /etc/init.d/crond ]; then |
| /etc/init.d/crond restart |
| elif [ -x /etc/init.d/cron ]; then |
| /etc/init.d/cron restart |
| elif $HAVE_SYSTEMCTL; then |
| for crond in "crond" "cron"; do |
| if systemctl is-enabled $crond.service >/dev/null 2>&1; then |
| systemctl restart $crond.service |
| break |
| fi |
| done |
| else |
| echo "Could not determine cron init.d script." |
| exit 1 |
| fi |
| } |
| |
| #----------------------------------------------------------------------- |
| # FUNCTION: do_cleanup |
| #----------------------------------------------------------------------- |
| |
| do_cleanup(){ |
| rm -rf /home/$TEST_USER |
| userdel $TEST_USER |
| } |
| |
| #----------------------------------------------------------------------- |
| # FUNCTION: MAIN |
| #----------------------------------------------------------------------- |
| do_setup |
| cron_pos_tests.sh $TEST_USER |
| EXIT_CODE=$? |
| do_cleanup |
| exit $EXIT_CODE |