Originally posted by: nagger
Other improvement:
Add as a second line
LOG=/home/azura/hrms.log
and then change every
>> /home/azura/hrms.log
to
>>$LOG
That will help readability, reduce the chance of typos and make changing the LOG file easier.
Actually you repeat the files names /home/elsag/cobol/RBS/DATASET/HRMS.txt and /home/azura/HRMS.txt again and again and again.
Perhaps they could be a variable too!
I assume you don't want error messages in the log file so problem become a mystery :-)
If not add a 2>> filename before each ">> filename" so both error and standard out go into the log.
Actually, a ksh function would help:
log()
{
$* 2>>/home/azura/hrms.log >> /home/azura/hrms.log
}
then change the script to
log echo
log date
log echo FILE BEFORE TRANSFERED
log ls -l /home/azura/HRMS.txt
log sudo chown elsag:staff /home/azura/HRMS.txt
etc.
This makes it much more understandable
and stop all that echo after some commands - the log will tell you when it failed your don't need to check.
You do realise you
chown elsag:staff
but output claiming to " FILE OWNERSHIP HAS BEEN CHANGED TO ELSAG:ELSAGRP "
Which is wrong in the upper/lower case AND wrong the group is different staff != elsagrp
So how about:
#!/usr/bin/ksh
LOG=/home/azura/hrms.log
SOURCE=/home/azura/HRMS.txt
TARGET=/home/elsag/cobol/RBS/DATASET/HRMS.txt
log()
{
$* 1>>/home/azura/hrms.log 2>>/home/azura/hrms.log
}
log echo "-------------------"
log date
if -f $TARGET
then
echo The file $TARGET already exists or some message like this outputs on the screen
else
log ls -l $SOURCE
log sudo chown elsag:staff $SOURCE
log sudo mv $TARGET $(TARGET)_`date +%d%m%Y_%H:%M:%S`
log sudo mv $SOURCE $TARGET
echo The file $TARGET has been saved
fi
Hope this helps, N
#AIX-Forum