[plug] script error
Jon Miller
jlmiller at mmtnetworks.com.au
Thu Jan 12 15:40:54 WST 2006
Any idea how to append 1 file to another? using cat file1 >> file2 does not work in a script.
Thanks
>>> troll at arach.net.au 12:28:51 pm 12/01/2006 >>>
On Thursday 12 January 2006 10:32, Lance Duivenbode wrote:
> From memory, don't the functions in BASH have to be declared before you
> use them (i.e. above them?)
>
> Lance
Yes they do
On another note - just because two files are the same size doesn't make them the same.
do a diff -q files
if diff -q $FileA $FileB
then
echo same
else
echo different
fi
>
> Jon Miller wrote:
>
> >I'm including the latest error and the code, what I'm not getting is while the function is not being called
> >gateway:/home/jlmiller# ./mailadd.sh test
> >du: `/db/mail/test': No such file or directory
> >FileA = test 4
> >FileB = test 64
> >FileA and FileB differ.
> >./mailadd.sh: line 36: chngacct: command not found
> >
> >Code----
> >#!/bin/sh
> ># mailadd.sh - jlmiller
> ># program to recreate mail accounts
> >#
> ># Changes record
> ># 11.01.2006 v.0.1
> ># Initial coding
> ># 12.01.2006 -first test run
> >#
> ># Procedure:
> ># read in file name from username file
> ># check if file exists in both /var/spool/mail and /db/mailtmp.
> ># check if the size of the files are the same or different.
> ># if same remove from /var/spool/mail if not move to /db/mail.
> ># recreate a mail file
> ># append old files to new files
> ># repeat with next name in file
> >#
> ># Variables
> >cmail=/var/spool/mail
> >omail=/db/mailtmp
> >tmail=/db/mail
> ># get the size of the file
> >fileA=`du -k $cmail/$1 | cut -f 1`
> >fileB=`du -k $omail/$1 | cut -f 1`
> >fileC=`du -k $tmail/$1 | cut -f 1`
> >
> ># show file and size
> >echo "FileA = $1 $fileA"
> >echo "FileB = $1 $fileB"
> >
> ># check if file A and fileB are the same or different
> ># if same recreate account
> ># if different move file to temp area
> >if [ $fileA == $fileB ]
> >then
> > echo "FileA and FileB are identical."
> > recreate # function call
> >else
> > echo "FileA and FileB differ."
> > chngacct # function call
> >fi
> >exit 0
> >############ FUNCTION PROCEDURE ##############
> >
> >function recreate()
> >{
> ># identical files - recreate mail file
> >rm $cmail/$fileA
> >mail $1 -s "testing" </dev/null
> >cat $omail/$1 >> $cmail/$1
> >$fileA
> >echo "Finish $fileA"
> >}
> >
> >
> >function chngacct()
> >{
> ># different files - move to temp area, recreate and append old mail to new mail
> >$fileA
> >mv $cmail/$fileA $tmail
> >$fileC
> >rm $cmail/$fileA
> >mail $1 -s "testing" </dev/null
> >cat $omail/$1 >> $cmail/$1
> >cat $tmail/$1 >> $cmail/$1
> >$fileA
> >echo " Finish $fileA"
> >}
> >
> >
> >
> >Thanks
> >
> >
> >
> >>>>troll at arach.net.au 9:32:28 am 12/01/2006 >>>
> >>>>
> >>>>
> >On Thursday 12 January 2006 09:39, Jon Miller wrote:
> >
> >
> >>Did that a few minutes ago and still same error.
> >>
> >>Jon
> >>
> >>
> >>
> >>>>>troll at arach.net.au 9:22:57 am 12/01/2006 >>>
> >>>>>
> >>>>>
> >>On Thursday 12 January 2006 08:06, Jon Miller wrote:
> >>
> >>
> >>>I've tried looking how to construct this and I keep getting the same error
> >>>
> >>>syntax error near unexpected token `else'
> >>>
> >>>if [ $fileA == $fileB ]; then # compare files
> >>>
> >>>
> >try
> >if [ "$fileA" == "$fileB" ]
> > then
> >
> >
> >>> echo "FileA and FileB are identical."
> >>> recreate() # run function
> >>> else
> >>> echo "FileA and FileB differ."
> >>> chngacct() # run function
> >>>fi
> >>>
> >>>
> >
> >
> >
>
> _______________________________________________
> PLUG discussion list: plug at plug.org.au
> http://www.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au
>
>
--
regs MR E_T
_______________________
\ \
\ OOHH I hate TYPOS \
\ \
~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
PLUG discussion list: plug at plug.org.au
http://www.plug.org.au/mailman/listinfo/plug
Committee e-mail: committee at plug.linux.org.au
More information about the plug
mailing list