By os2macEnvironment:
BASH version: GNU bash, version 3.2.51(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2007 Free Software Foundation, Inc.
OS: Oracle Solaris 10 9/10 s10s_u9wos_14a SPARC
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
Assembled 11 August 2010
Script:
Code:
#!/usr/bin/bash
#————————————————-
# This sftp’s the the remote server
#
DATE=`date +”%d%b%y,%T-“`
NEWER=/users/ACCOUNT/.newer
LOG=/users/ACCOUNT/aly_sftp.log
HOSTIS=`hostname`
EMAIL=account@email.com
SENT=0
if [ $HOSTIS = ‘hostname’ ]; then
TOHOST=’account@regular.host.com’
else
TOHOST=’account@test.host.com’
fi
TODOMAIN=`echo $TOHOST|cut -d @ -f2`
for i in `find /transfer -name ‘*.txt’ -newer $NEWER -print`
do
sftp $TOHOST $LOG
SENT=$((SENT+1))
RESULT
if [ $SENT == 0 ]
then
mailx -s “SFTP completed successfully” $EMAIL>$LOG
touch -a -m $NEWER
SENT=0
else
touch -a -m $NEWER
echo $DATE$NEWER “touched”>>$LOG
fi
done
So this has been giving me fits and I just can’t figure it out. I am sure it’s a rookie mistake but I have been staring at it too long and can’t find it. The bit I am having trouble with is the SENT variable increment and using to determine which part of the if statement to execute.
Doesn’t matter how I change it SENT=0 when it gets to the second if statement and it always executes the first condition rather than the second.
It has something to do with global vs local variables I think but I can’t figure out how to correctly configure it.
Any teaching would be appreciated.
Source: The UNIX and Linux Forums