Results 1 to 3 of 3
Following is a script. Can anyone plz help me to document this. Since I am new to scripting, I cant understand the script. Plz go thru it just help me ...
- 12-30-2008 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 3
Documenting this script
Following is a script. Can anyone plz help me to document this. Since I am new to scripting, I cant understand the script. Plz go thru it just help me to document it in minimal words.
#!/bin/bash -x
oldtime="30m"
override="true"
email="false"
runjobs="false"
basedir="/ftp/nas2/ipm/vault"
intftp=$(cat /opt/ESPEspresso/ESPSystemAgent/internal)
filetmp=/tmp/vfmfile.$(date +%m%d%y%H%M%S).$$
accttmp=/tmp/vfmacct.$(date +%m%d%y%H%M%S).$$
if [ $# -gt 0 ]
then
for option in $*
do
case $option in
--email)
email=$2
shift ; shift
;;
-o|--old)
oldtime=$2 ;
shift ; shift
;;
-d|--d)
basedir=$2
shift ; shift
;;
--runjobs)
runjobs="true"
shift
;;
esac
done
fi
oldunit=$(echo $oldtime | cut -c${#oldtime})
oldtime=$(echo $oldtime | cut -c-$((${#oldtime} - 1)))
case $oldunit in
h) oldtime=$(($oldtime * 60))
;;
m) oldtime=$(($oldtime * 1))
;;
s) oldtime=$(($oldtime / 60))
;;
esac
for custdir in $(ls $basedir)
do
headers="false"
oldmins=$oldtime
finddir="$basedir/$custdir"
findpat=$(echo $basedir/$custdir | sed 's/\//\\\//g')
[ $runjobs == "true" ] && [ -f $finddir/.vfmo ] && oldmins=$(cat $finddir/.vfmo)
[ $runjobs == "true" ] && [ -f $basedir/.vfmo ] && oldmins=$(cat $basedir/.vfmo)
[ X$oldmins == "X" ] && oldmins=$oldtime
[ $oldmins -eq 0 ] && oldmins=$oldtime
if [ $custdir == "ftp.db" ]; then
continue
fi
if [ ! -d $finddir ]; then
continue
fi
logger "Running command find $finddir/ -type f -mmin +$oldmins "
# sleep 5
find $finddir/ -type f -mmin +$oldmins | awk -v p1="$findpat\/\\\.|$findpat\/archive\/|$findpat\/ftp\\\.db.*|$basedir/ftp.db.*" '$0 !~ p1' | while read -r filename
do
# sleep 5
if [ $runjobs == "true" ]
then
echo $custdir >>$accttmp
sleep 3
else
if [ $email != "false" ]
then
if [ $headers == "false" ]
then
echo " " >>$filetmp
echo "Files for customer $custdir older than $oldmins minutes:" >>$filetmp
echo " " >>$filetmp
headers="true"
fi
echo $filename >>$filetmp
else
echo $filename
fi
fi
done
logger "Finished command find $finddir/ -type f -mmin +$oldmins"
#sleep 4
#fi
done
if [ $email != "false" ] && [ -f $filetmp ]
then
cat $filetmp | mail -s "IPM files lingering on EFTP server" $email
rm $filetmp
fi
sleep 3
if [ $runjobs == "true" ] && [ -f $accttmp ]
then
for acct in $(cat $accttmp | sort -u)
do
#if [ $acct != "ipmtest" ]; then
# continue
#else
# echo $acct
# sleep 3
#/opt/ESPEspresso/ESPSystemAgent/cybTrigger -cmd TRIGGERADD -name VAULT_FTPJOBS.PUNIXVAULT_FILEMOVE_DLY_P1 -at now -user CYBTRIGGER -password cybtrigger -up2 $acct -up1 $intftp
/opt/ESPEspresso/ESPSystemAgent/cybTrigger -cmd TRIGGERADD -name VAULT_FTPJOBS.PUNIXVAULT_FILEMOVE_DLY_P1 -at now -user CYBTRIGGER -password cybtrigger -up2 $acct -up1 $intftp
logger "Created vault.scr job for $acct"
#fi
done
rm $accttmp
fi
exit 0
- 01-03-2009 #2
- 01-03-2009 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Like most people here, I have other things to do, and I don't plan on looking at this any farther, but here is an (automated) tidied list of your script. It may help you see the structure of it:
Good luck ... cheers, drlCode:#!/bin/bash -x oldtime="30m" override="true" email="false" runjobs="false" basedir="/ftp/nas2/ipm/vault" intftp=$(cat /opt/ESPEspresso/ESPSystemAgent/internal) filetmp=/tmp/vfmfile.$(date +%m0%y%H%M%S).$$ accttmp=/tmp/vfmacct.$(date +%m0%y%H%M%S).$$ if [ $# -gt 0 ] then for option in $* do case $option in --email) email=$2 shift shift ;; -o|--old) oldtime=$2 ; shift shift ;; -d|--d) basedir=$2 shift shift ;; --runjobs) runjobs="true" shift ;; esac done fi oldunit=$(echo $oldtime | cut -c${#oldtime}) oldtime=$(echo $oldtime | cut -c-$((${#oldtime} - 1))) case $oldunit in h) oldtime=$(($oldtime * 60)) ;; m) oldtime=$(($oldtime * 1)) ;; s) oldtime=$(($oldtime / 60)) ;; esac for custdir in $(ls $basedir) do headers="false" oldmins=$oldtime finddir="$basedir/$custdir" findpat=$(echo $basedir/$custdir | sed 's/\//\\\//g') [ $runjobs == "true" ] && [ -f $finddir/.vfmo ] && oldmins=$(cat $finddir/.vfmo) [ $runjobs == "true" ] && [ -f $basedir/.vfmo ] && oldmins=$(cat $basedir/.vfmo) [ X$oldmins == "X" ] && oldmins=$oldtime [ $oldmins -eq 0 ] && oldmins=$oldtime if [ $custdir == "ftp.db" ] then continue fi if [ ! -d $finddir ] then continue fi logger "Running command find $finddir/ -type f -mmin +$oldmins " # sleep 5 find $finddir/ -type f -mmin +$oldmins | awk -v p1="$findpat\/\\\.|$findpat\/archive\/|$findpat\/ftp\\\.db.*|$basedir/ftp.db.*" '$0 !~ p1' | while read -r filename do # sleep 5 if [ $runjobs == "true" ] then echo $custdir >>$accttmp sleep 3 else if [ $email != "false" ] then if [ $headers == "false" ] then echo " " >>$filetmp echo "Files for customer $custdir older than $oldmins minutes:" >>$filetmp echo " " >>$filetmp headers="true" fi echo $filename >>$filetmp else echo $filename fi fi done logger "Finished command find $finddir/ -type f -mmin +$oldmins" #sleep 4 #fi done if [ $email != "false" ] && [ -f $filetmp ] then cat $filetmp | mail -s "IPM files lingering on EFTP server" $email rm $filetmp fi sleep 3 if [ $runjobs == "true" ] && [ -f $accttmp ] then for acct in $(cat $accttmp | sort -u) do #if [ $acct != "ipmtest" ]; then # continue #else # echo $acct # sleep 3 #/opt/ESPEspresso/ESPSystemAgent/cybTrigger -cmd TRIGGERADD -name VAULT_FTPJOBS.PUNIXVAULT_FILEMOVE_DLY_P1 -at now -user CYBTRIGGER -password cybtrigger -up2 $acct -up1 $intftp /opt/ESPEspresso/ESPSystemAgent/cybTrigger -cmd TRIGGERADD -name VAULT_FTPJOBS.PUNIXVAULT_FILEMOVE_DLY_P1 -at now -user CYBTRIGGER -password cybtrigger -up2 $acct -up1 $intftp logger "Created vault.scr job for $acct" #fi done rm $accttmp fi exit 0Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote
