Renaming a file use another file as a sequence calling a shl
have this shl that will FTP a file from the a directory in windows to UNIX, It get the name of the file stored in this variable $UpLoadFileName then put in the local directory LocalDir="${MPATH}/xxxxx/dat_files" that part seems to be working, but then I need to take that file and rename, I am using another shl do do this, look at the end of the code when I call sh pain, I will put the code of that shl at the end also, if I run the two shls separately, it works but when I call the shl pain from the main one it does not work
Here is the code from I called the main shl
Code:
MPATH=$BANNER_HOME;
JOBNUM=$ONE_UP;
USER=$BANUID;
JOBNAME="RZPEFT";
AT_SIGN="@";
set -x
##set +x
LPATH="/u02/sct/banjobs/";
RemoteHost="xxxxxxxxxxxxxxx";
### look at this
RemoteUser="xxxxx_finaid";
RemotePass="xxxxx";
LocalDir="${MPATH}/xxxxx/dat_files";
##LocalDir = "${MPATH}/dataload/finaid"
##CDRemoteDir='cd \orgs\"Financial Aid"\"MIIS"\"0910"\"FTP" ';
var1='cd orgs\Financial'
var2='Aid\MIIS\0910\FTP'
CDRemoteDir=$var1$var2
## Grab the file
ScriptName="rzpeftf.shl";
## Grab the file
ScriptName= "rzpeftf.shl";
UpLoadFileName=`date "+%m%d%y"00.DSB`;
echo "UpLoadFileName" $UpLoadFileName
TMode="ascii"; # Transfer mode
EmailAddress="xxxxxx@xxxxx.edu";
LogFileName="rzpeftf_${USER}_${JOBNUM}.log";
LogFile="${LPATH}${LogFileName}";
TodayDate=`date`;
echo "\nActivities for "$TodayDate":" >> $LogFile;
LF1=${LPATH}${LogFileName};
LF2=${LPATH}${LogFileName};
SHL_SCRIPT_PATH="${MPATH}/xxxxx/shl/";
##set variables for Error testing and messages
ERROR_NAME="error_message_.rzpdsf_shl";
ERROR_RUN="${SHL_SCRIPT_PATH}${ERROR_NAME}";
ERROR_TEST_NAME="error_testing_routine.shl";
ERROR_TEST_ROUTINE="${SHL_SCRIPT_PATH}${ERROR_TEST_NAME}";
ERR_VAR="NO";
ERROR_USER="error_message_user.shl";
ERROR_RUN_USER="${SHL_SCRIPT_PATH}${ERROR_USER}";
#========================================================================#
# Error Handling Function
function ErrorHandle
{
# if type is 1, then the file does not exist or unreadable
if [ $type -eq 1 ]
then
echo "File "$UpLoadFileName" does not exist or unreadable" >> $LogFile;
echo "Subject: Error in Running Script\n Error in uploading file script "$ScriptName". File "$UpLoadFileName" does not exist or unreadable" > EmailMessage;
sendmail -F " File Upload" $EmailAddress < EmailMessage;
rm EmailMessage;
fi
# if type is 2, then the file has zero size
if [ $type -eq 2 ]
then
echo "File "$UpLoadFileName" has a zero size value" >>$LogFile;
echo " Subject: Error in Running Script\n Error in uploading file script "$ScriptName". File "$UpLoadFileName" has a zero size value" > EmailMessage;
sendmail -F "The $UpLoadFileName File Upload" $EmailAddress < EmailMessage;
rm EmailMessage;
fi
echo "End of activities\n" >> $LogFile
# Exit the program since error occurred
exit 1;
}
###here adding
# Before copying the file, we need to remove the same name file if exists
if test -a ${LocalDir} ${NewName}
then
echo " " >>${LF1} 2>>${LF2}
echo "Found ${LocalDir} ${NewName} file in the dir, will remove first" >>${LF1} 2>>${LF2}
rm ${LocalDir} ${NewName} >>${LF1} 2>>${LF2}
ERR_VAR=$($ERROR_TEST_ROUTINE $LogFileName);
if [ $ERR_VAR = 'NO' ]
then
echo "Successfully remove ${LocalDir}${NewName} " >>${LF1} 2>>${LF2}
else
echo "Error: could not remove ${LocalDir}${NewName} file" >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
sh ${ERROR_RUN} >>${LF1} 2>>${LF2}
echo "Warning Email message sent to tech staff. " >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
sh ${ERROR_RUN_USER} >>${LF1} 2>>${LF2}
echo "Warning Email message sent to user. " >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "Script Ended and no updating done." >>${LF1} 2>>${LF2}
exit 1
fi
fi
###here adding
#========================================================================#
# Change the directory to one contains the file to be transported
$CDRemoteDir;
#========================================================================#
# Change dir to where the ftp will place the uploaded file
cd ${LocalDir}
# Initiate the FTP process
ftp -n $RemoteHost <<!EOF
quote user $RemoteUser
quote pass $RemotePass
cd orgs
cd "Financial Aid"
cd MIIS
cd 0910
cd FTP
get $UpLoadFileName
sh pain
quit
!EOF
shl pain
# End of FTP Process
#
the idea is to read the file
1234 file_seq
then incremented by one
eft1235.dat file2
eftsql1235.dat file3
then take this name and rename $UpLoadFileName from the main shl eftsql1235.dat
then I have to increment the file in the following directory in by one
/u02/sct/banner/bandev2/xxxxxxx /misc/EFTSQL.dat)
so next time I run the process 1235 will be on that file (EFTSQL.dat)
so the new sequenc will be 1235 + 1
I am using the file in /u02/sct/banner/bandev2/xxxx/misc/EFTSQL.dat as a sequence..
need to be able to capture a file with the following conditions:
The filenames are, for example, 3526_332840.dat, where 3526 is constant, and 332840 is a sequential number which is always a couple hundred greater than the previous day's file.
I want to be able to change this script to acoomplish... (1 Reply)
Hello all,
I've read a couple different posts on this subject but couldn't quite get what I'm trying to do to work. I have a file and the last line always ends with the text below (without the "s), except the number 294 will be different each time. I want to rename this file to the number that... (6 Replies)
I am trying to read a file in a shl script (only one record) and stored in a variable file_number
I got the following
read -u $BANNER_HOME/xxxxxxx/misc/EFTSQL.dat file_number
file_number2 = $file_number + 1
echo $file_number2 > $BANNER_HOME/xxxxxx/misc/EFTSQL.dat
EOF
It is not working... (2 Replies)
I have to rename a large number of files so that the name of each file corresponds to a code number that is given side by side in a list (textfile).
The list contains in column A the filename of the actual files to be renamed and in column B the name (a client code, 9 digits) that has to be... (7 Replies)
I want to capture a last file in a directory in a shl scrip
Cd to the directory
$last ls -1 *the_bills.dat* | tail -1
This is not problem, but I need to copy that file to another directory, but in order to be able to copy to that directory, I need to su in unix, I am sure my sistem... (2 Replies)
I need to decrypt a file in a directory, I need to write a shl scrip & cron job
How I find the files in the directory:
the file is like this:
dailypayments_sfs_payment_201011151800.dat -d
The decrypt command:
gpg -o dailypayments_sfs_payment_201011151800.dat -d
20101115 (the date... (7 Replies)
I have the following in a shl script:
SCRIPT_PATH="/u01/app/banner/test/skid/plus/";
FILE_PATH="/nfs/mercury/u03/banner/test/skid/log";
LIST_FILE_PATH="/u01/banjobs/TEST";
SCRIPT_NAME="szpcal1.sql";
FILE_NAME='new_applicant_list';
I want to copy the file FILE_NAME to LIST_FILE_PATH
... (10 Replies)
Hi
Am trying to move a file from one name to another
When I do "ls" to check for the moved filename
I can see the file but when I try the same with a script am unable..
I think am doing some pretty silly error.. please help..
toMove=`ls | grep -E "partition.+"`
mv $toMove partition._org... (7 Replies)
Hi,
I have one file with one column and several hundred entries
File1:
NA1
NA2
NA3And now I need to run a command within a mapping aligner tool to insert these sample names into a sequence alignment file (SAM) such that they look like this
@RG ID:Library1 SM:NA1 PL:Illumina ... (7 Replies)
Hi team,
I need a script for renaming a file with sequence number. script get a file from one directory, /home/billing/Cmm/sms/sms_tmp, append sequence no at the end of file name and move a file to other directory, /home/billing/Cmm/sms/.
Actual file is cdr201508271527, and file after... (10 Replies)