[plug] script error

Mr E_T troll at arach.net.au
Thu Jan 12 16:16:03 WST 2006


On Thursday 12 January 2006 15:40, Jon Miller wrote:
> Any idea how to append 1 file to another?  using cat file1 >> file2 does not work in a script.
> 
Why are you using $fileA $fileB $fileC as commands ?
if they are comments then they need # in front
also to get the perm right use 
chmod --reference=${tmail}/{$1} ${cmail}/${1}
chown --reference=${tmail}/{$1} ${cmail}/${1}

also are the functions defined before they are called?

cat $omail/$1 > $cmail/$1
cat $tmail/$1 >> $cmail/$1

Notice the first cat is a single > this creates or zreos the file first.
>> appends to an already existing file.

> > 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

-- 
regs MR E_T
_______________________
\                      \
  \   OOHH I hate TYPOS  \
    \                      \
      ~~~~~~~~~~~~~~~~~~~~~~~



More information about the plug mailing list