Results 1 to 3 of 3
Hi,
I am trying to write a script in bash to find if a new domain has been added to our network.
I would like to be able to use ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-20-2005 #1Just Joined!
- Join Date
- Oct 2005
- Posts
- 1
Problem with date script
Hi,
I am trying to write a script in bash to find if a new domain has been added to our network.
I would like to be able to use an if stament to check the date on a log entry to see how long this has been happening.
e.g.
My out put looks like:
NEW Domain added at 11:36 on 20-10-05
WORKGROUP
NEW Domain added at 12:36 on 20-10-05
WORKGROUP
I want to be able to say the Workgroup WORKGROUP was added to the daomain on 20:10:05 at 11:36 and has been on for a total of 0 days 01:00
My script is as follows so far.
#!/bin/bash
HOME=/nt_domain
LOGS=$HOME/logs
DATA=$HOME/data
DOMAINLIST=$DATA/domain_list
DOMAINLOG=$LOGS/new_domain_list
DATE=`date +%H":"%M" on "%d"-"%m"-"%y`
smbtree --user=root[%password]|awk '{print $1 }'|grep -v 'knowndomain' > $DATA/domain_list
if [ -s $domainlist ]; then
echo "NEW Domain added at $DATE" >> $DOMAINLOG
cat $DOMAINLIST >> $DOMAINLOG
echo " " >> $DOMAINLOG
fi
If anyone can add any other enhancements that would be great.
- 10-20-2005 #2Linux Newbie
- Join Date
- Oct 2004
- Posts
- 158
date stuff in shell script is complicated - here are several very good scripts:
http://www.unix.com/showthread.php?t=13785
- 10-20-2005 #3Just Joined!
- Join Date
- Oct 2005
- Posts
- 10
This isn't really an enchancement, just another variation.
#!/bin/bash
HOME=/nt_domain
LOGS=$HOME/logs
DATA=$HOME/data
DOMAINLIST=$DATA/domain_list
DOMAINLOG=$LOGS/new_domain_list
DATE=`date +%H":"%M" on "%d"-"%m"-"%y`
if [ -f $DOMAINLIST ]; then
echo "$DOMAINLIST already exists"
else
echo "Created blank $DOMAINLIST"
echo touch $DOMAINLIST
fi
# Create new read time for test condition
cat $DOMAINLIST > /dev/null
# Connect to domain tree and find any domain except 'knowndomain'
smbtree --user=root[%password]|awk '{print $1 }'|grep -v 'knowndomain' > $DOMAINLIST
# Test if $DOMAINLIST has changed since last read
if [ -N $DOMAINLIST ]; then
echo "NEW Domain added at $DATE" > $DOMAINLOG.`date +%Y%m%d`
cat $DOMAINLIST >> $DOMAINLOG.`date +%Y%m%d`
fi


Reply With Quote
