I have the following script which check the users in my server & set them from { 0:0:1 } to { 0:0:0 } which mean their subscription expire. I made it with respect to date that on due date it expire the clients.
format of the clients line is like this.
F: test test 0 0 1 { 0:0:1 } ##19-03-2011
My script is working 100% but i want it to give me a reminder as well that before a user expire I get the alert 7 days ago before it expire in the form of a text file in Var/Config. any help will be appreciated a lot. I am confuse how to -7 days from the script so it work for me. Plz edit my script & help me
#!/bin/sh
#Automated clients expire check script.
#Purpose: checks if a clients date is expired.
## ## ## written by David Tan ## ## ## ##
USER=taree65
TEMP=/tmp
JOB=/check-expire
TARGET1=/var/etc
TARGET2=/var/config
FILE1=CCcam.cfg
FILE2=all_expired_clients.txt
FILE3=expired_clients.txt
TARGET2=/var/config
TARGET1=/var/etc
BACKUPDIR=/var/backup
CONFIGOLD=CCcam.old
if test -f $TARGET2/$FILE1 ; then
echo "New Config Present for 3AXES"
if test -d $BACKUPDIR ; then
if test -f $BACKUPDIR/$CONFIGOLD ; then
echo "Removing OLD config file from backup directory"
rm $BACKUPDIR/$CONFIGOLD
else
echo "No OLD config to remove."
fi
if test -f $BACKUPDIR/$FILE1 ; then
echo "Renaming Backup to old config"
cp $BACKUPDIR/$FILE1 $BACKUPDIR/$CONFIGOLD
rm $BACKUPDIR/$FILE1
else
echo "No Backupfile present yet"
fi
if test -f $TARGET1/$FILE1 ; then
echo "Copying Original config to Backup directory"
cp $TARGET1/$FILE1 $BACKUPDIR
rm $TARGET1/$FILE1
else
echo "No Original Config File Present!?!?"
fi
else
echo "Backup directory does not exist."
echo "making new directory"
mkdir $BACKUPDIR
if test -f $TARGET1/$FILE1 ; then
echo "Copying Original config to Backup directory"
cp $TARGET1/$FILE1 $BACKUPDIR
else
echo "No Original Config File Present!?!?"
fi
fi
echo "Moving New config file to "$TARGET1
cp $TARGET2/$FILE1 $TARGET1
rm $TARGET2/$FILE1
else
echo "No New Config present, Nothing to process"
fi
sleep 5
echo "read the config for expired clients"
grep $(date +%d-%m-%Y) $TARGET1/$FILE1 >>$TARGET1/$FILE3
sleep 1
echo "sed -i '/$(date +%d-%m-%Y)/d' /var/etc/CCcam.cfg" > $TEMP/$JOB
chmod 755 $TEMP/$JOB
$TEMP/$JOB
rm $TEMP/$JOB
echo "set expired clients to no share !!"
sleep 1
sed 's/{ 0:0:1 }/{ 0:0:0 } ## expired !!/g' $TARGET1/$FILE3 >> $TARGET2/$FILE1
sleep 1
cat $TARGET1/$FILE3 >> $TARGET2/$FILE2
sleep 2
echo "adding old clients and settings to config"
sleep 1
cat $TARGET1/$FILE1 >> $TARGET2/$FILE1
sleep 1
echo "removing old files"
rm $TARGET1/$FILE3
rm $TARGET1/$FILE1
sleep 2
echo "Moving New config file to /var/etc"
cp $TARGET2/$FILE1 $TARGET1
chown $USER $TARGET2/$FILE2
chown $USER $TARGET2/$FILE1
chmod 777 $TARGET2/$FILE1
exit
What Operating System and version are you using?
Do you have the GNU version of the date command?
No changes, just a re-post of your script with indentation which I can follow:
#!/bin/sh
#Automated clients expire check script.
#Purpose: checks if a clients date is expired.
## ## ## written by David Tan ## ## ## ##
USER=taree65
TEMP=/tmp
JOB=/check-expire
TARGET1=/var/etc
TARGET2=/var/config
FILE1=CCcam.cfg
FILE2=all_expired_clients.txt
FILE3=expired_clients.txt
TARGET2=/var/config
TARGET1=/var/etc
BACKUPDIR=/var/backup
CONFIGOLD=CCcam.old
if test -f $TARGET2/$FILE1 ; then
echo "New Config Present for 3AXES"
if test -d $BACKUPDIR ; then
if test -f $BACKUPDIR/$CONFIGOLD ; then
echo "Removing OLD config file from backup directory"
rm $BACKUPDIR/$CONFIGOLD
else
echo "No OLD config to remove."
fi
if test -f $BACKUPDIR/$FILE1 ; then
echo "Renaming Backup to old config"
cp $BACKUPDIR/$FILE1 $BACKUPDIR/$CONFIGOLD
rm $BACKUPDIR/$FILE1
else
echo "No Backupfile present yet"
fi
if test -f $TARGET1/$FILE1 ; then
echo "Copying Original config to Backup directory"
cp $TARGET1/$FILE1 $BACKUPDIR
rm $TARGET1/$FILE1
else
echo "No Original Config File Present!?!?"
fi
else
echo "Backup directory does not exist."
echo "making new directory"
mkdir $BACKUPDIR
if test -f $TARGET1/$FILE1 ; then
echo "Copying Original config to Backup directory"
cp $TARGET1/$FILE1 $BACKUPDIR
else
echo "No Original Config File Present!?!?"
fi
fi
echo "Moving New config file to "$TARGET1
cp $TARGET2/$FILE1 $TARGET1
rm $TARGET2/$FILE1
else
echo "No New Config present, Nothing to process"
fi
sleep 5
echo "read the config for expired clients"
grep $(date +%d-%m-%Y) $TARGET1/$FILE1 >>$TARGET1/$FILE3
sleep 1
echo "sed -i '/$(date +%d-%m-%Y)/d' /var/etc/CCcam.cfg" > $TEMP/$JOB
chmod 755 $TEMP/$JOB
$TEMP/$JOB
rm $TEMP/$JOB
echo "set expired clients to no share !!"
sleep 1
sed 's/{ 0:0:1 }/{ 0:0:0 } ## expired !!/g' $TARGET1/$FILE3 >> $TARGET2/$FILE1
sleep 1
cat $TARGET1/$FILE3 >> $TARGET2/$FILE2
sleep 2
echo "adding old clients and settings to config"
sleep 1
cat $TARGET1/$FILE1 >> $TARGET2/$FILE1
sleep 1
echo "removing old files"
rm $TARGET1/$FILE3
rm $TARGET1/$FILE1
sleep 2
echo "Moving New config file to /var/etc"
cp $TARGET2/$FILE1 $TARGET1
chown $USER $TARGET2/$FILE2
chown $USER $TARGET2/$FILE1
chmod 777 $TARGET2/$FILE1
exit
d=$(date -d +7days +%d-%m-%Y)
fgrep "##$d" $TARGET1/$FILE1 | while read f client rest
do
echo "Warning client $client will expire on $d" >> $TARGET2/expire_soon.txt
done
Can u change the whole script for me add this thing in the script so that i need to change only date in servers for my clients nothing else need to be changed
Not quite sure if this is what you were asking for (added code in green):
#!/bin/sh
#Automated clients expire check script.
#Purpose: checks if a clients date is expired.
## ## ## written by David Tan ## ## ## ##
USER=taree65
TEMP=/tmp
JOB=/check-expire
TARGET1=/var/etc
TARGET2=/var/config
FILE1=CCcam.cfg
FILE2=all_expired_clients.txt
FILE3=expired_clients.txt
TARGET2=/var/config
TARGET1=/var/etc
BACKUPDIR=/var/backup
CONFIGOLD=CCcam.old
if test -f $TARGET2/$FILE1 ; then
echo "New Config Present for 3AXES"
if test -d $BACKUPDIR ; then
if test -f $BACKUPDIR/$CONFIGOLD ; then
echo "Removing OLD config file from backup directory"
rm $BACKUPDIR/$CONFIGOLD
else
echo "No OLD config to remove."
fi
if test -f $BACKUPDIR/$FILE1 ; then
echo "Renaming Backup to old config"
cp $BACKUPDIR/$FILE1 $BACKUPDIR/$CONFIGOLD
rm $BACKUPDIR/$FILE1
else
echo "No Backupfile present yet"
fi
if test -f $TARGET1/$FILE1 ; then
echo "Copying Original config to Backup directory"
cp $TARGET1/$FILE1 $BACKUPDIR
rm $TARGET1/$FILE1
else
echo "No Original Config File Present!?!?"
fi
else
echo "Backup directory does not exist."
echo "making new directory"
mkdir $BACKUPDIR
if test -f $TARGET1/$FILE1 ; then
echo "Copying Original config to Backup directory"
cp $TARGET1/$FILE1 $BACKUPDIR
else
echo "No Original Config File Present!?!?"
fi
fi
echo "Moving New config file to "$TARGET1
cp $TARGET2/$FILE1 $TARGET1
rm $TARGET2/$FILE1
else
echo "No New Config present, Nothing to process"
fi
sleep 5
echo "read the config for soon-to expire clients"
d=$(date -d +7days +%d-%m-%Y)
fgrep "##$d" $TARGET1/$FILE1 | while read f client rest
do
echo "Warning client $client will expire on $d" >> $TARGET2/expire_soon.txt
done
sleep 5
echo "read the config for expired clients"
grep $(date +%d-%m-%Y) $TARGET1/$FILE1 >>$TARGET1/$FILE3
sleep 1
echo "sed -i '/$(date +%d-%m-%Y)/d' /var/etc/CCcam.cfg" > $TEMP/$JOB
chmod 755 $TEMP/$JOB
$TEMP/$JOB
rm $TEMP/$JOB
echo "set expired clients to no share !!"
sleep 1
sed 's/{ 0:0:1 }/{ 0:0:0 } ## expired !!/g' $TARGET1/$FILE3 >> $TARGET2/$FILE1
sleep 1
cat $TARGET1/$FILE3 >> $TARGET2/$FILE2
sleep 2
echo "adding old clients and settings to config"
sleep 1
cat $TARGET1/$FILE1 >> $TARGET2/$FILE1
sleep 1
echo "removing old files"
rm $TARGET1/$FILE3
rm $TARGET1/$FILE1
sleep 2
echo "Moving New config file to /var/etc"
cp $TARGET2/$FILE1 $TARGET1
chown $USER $TARGET2/$FILE2
chown $USER $TARGET2/$FILE1
chmod 777 $TARGET2/$FILE1
exit