- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- help in script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 03:13 AM
тАО02-13-2007 03:13 AM
I have posted below a section of script that checks changes in cron ....
The script checks for added or removed schedules and reports to the sysadmin however I cannot configure without it getting messy to run the check agains current crons then the check against removed crons:
ls $LIVE_CRON |grep -v "^d" |grep -v ".tar" |grep -v ".sav" |sort -n > $LIVELIST
ls $WORKCRON |grep -v "^d" |grep -v ".tar" |grep -v ".sav" |sort -n > $KNOWNLIST
DIFFCHK=`diff $LIVELIST $KNOWNLIST |tail +2 |wc -l`
if [ $DIFFCHK -gt 0 ] ; then
for a in `diff $LIVELIST $KNOWNLIST |tail +2|sed 's/ /:/g'`
do
DIFF=`echo $a |awk -F: '{print $1}'`
SCHED=`echo $a |awk -F: '{print $2}'`
if [ "$DIFF" = ">" ] ; then
echo "Cron schedules removed ...... \n$SCHED\n" >> $OUTFILE
rm -f $WORKCRON/$SCHED
cat $LIVELIST > $KNOWNLIST
echo "\n" >> $OUTFILE
elif [ "$DIFF" = "<" ] ; then
echo "Cron schedules that have been added ......\n$SCHED\n" >> $OUTFILE
cp $LIVE_CRON/$SCHED $WORKCRON
cat $LIVELIST > $KNOWNLIST
echo "\n" >> $OUTFILE
fi
done
fi
basically if I remove a cron then the first bit works but then doesn't run the second 'if' statement.
any idea's please?
Thanks
Solved! Go to Solution.
- Tags:
- diff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 03:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 03:41 AM
тАО02-13-2007 03:41 AM
Re: help in script
if [ $DIFFCHK -gt 0 ] ; then
etc
etc
if [ "$DIFF" = ">" ] ; then
echo "Cron schedules removed ...... \n$SCHED\n" >> $OUTFILE
rm -f $WORKCRON/$SCHED
cat $LIVELIST > $KNOWNLIST
echo "\n" >> $OUTFILE
works but wont contiue to elif ...
I am pretty sure the elif is the wrong statement so what else can I use?
many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 05:44 AM
тАО02-13-2007 05:44 AM
Re: help in script
what if you just change the elif to an if. For example:
if [ "$DIFF" = ">" ] ; then
echo "Cron schedules removed ...... \n$SCHED\n" >> $OUTFILE
rm -f $WORKCRON/$SCHED
cat $LIVELIST > $KNOWNLIST
echo "\n" >> $OUTFILE
fi
if [ "$DIFF" = "<" ] ; then
echo "Cron schedules that have been added ......\n$SCHED\n" >> $OUTFILE
cp $LIVE_CRON/$SCHED $WORKCRON
cat $LIVELIST > $KNOWNLIST
echo "\n" >> $OUTFILE
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 06:28 AM
тАО02-13-2007 06:28 AM
Re: help in script
note that you don't need the "tail" when creating the original list, as you are only processing those lines where "DIFF" is "<" or ">", the remainder of the diff output is read and tossed out.
the "cat"s are going to happen multiple times, which is probably an error.
the "<" and ">" are going to be interspersed in the output of the diff, it looks like (from the header echos) that you expect to get all of the adds and all of the removes grouped together.
I'd add set +x to your script, along w/ Peter's suggestion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 07:08 PM
тАО02-13-2007 07:08 PM
Re: help in script
Thanks for the suggestions chaps