Renaming a file use another file as a sequence calling a shl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming a file use another file as a sequence calling a shl
# 1  
Old 04-04-2010
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
#

Here is the shl pain
Code:
#! /bin/sh
file_seq=$( < /u02/sct/banner/bandev2/xxxxx/misc/EFTSQL.dat)
echo $file_seq "file_seq"
file2=eft$(expr $file_seq + 1).dat
echo $file2 "file2"
file3=eftsql$(expr $file_seq + 1).dat
echo $file3 "file3"

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..
# 2  
Old 04-04-2010
Quote:
Originally Posted by rechever
... but when I call the shl pain from the main one it does not work
...
How do you know it does not work ?
What's happening that should not happen ?
What's not happening that should happen ?

Code:
$ 
$ # show the content of EFTSQL.dat
$ cat -n EFTSQL.dat
     1  1234
$ 
$ # show the content of inner
$ cat -n inner
     1  file_seq=$( < EFTSQL.dat)
     2  echo $file_seq "file_seq"
     3  file2=eft$(expr $file_seq + 1).dat
     4  echo $file2 "file2"
     5  file3=eftsql$(expr $file_seq + 1).dat
     6  echo $file3 "file3"
$ 
$ # show the content of main
$ cat -n main
     1  echo "Lots and lots of irrelevant code here..."
     2  ./inner
$ 
$ # run main
$ ./main
Lots and lots of irrelevant code here...
1234 file_seq
eft1235.dat file2
eftsql1235.dat file3
$ 
$

tyler_durden
# 3  
Old 04-05-2010
using a file with a sequence to rename another one

Thank you this is helpful, but still not working this is what I got
the first part works the ftp I get the 04051000.DSB file,
now I want to rename that file with the result of
Code:
 
get $UpLoadFileName
cat -n inner
file_seq=$( < eftseq.dat)
echo $file_seq "file_seq"
file2=eft$(expr $file_seq + 1).dat
echo $file2 "file2"
file3=eftsql$(expr $file_seq + 1).dat
echo $file3 "file3"
quit
!EOF

Results

Code:
 
quote pass gvf1!3Mk
cd orgs
cd "Financial Aid"
cd MIIS
cd 0910
cd FTP
get 04051000.DSB
cat -n inner
file_seq=+ + No such file or directory
rzpeftf[143]: eftseq.dat: cannot open
rzpeftf[143]: eftseq.dat: cannot open
+ shl pain
rzpeftf[163]: shl: not found

when I ran these commands on the command line it works
Code:
 
file_seq=$( < eftseq.dat)
echo $file_seq "file_seq"
file2=eft$(expr $file_seq + 1).dat
echo $file2 "file2"
file3=eftsql$(expr $file_seq + 1).dat
echo $file3 "file3"

# 4  
Old 04-05-2010
Quote:
Originally Posted by rechever
...
when I ran these commands on the command line it works
Code:
 
file_seq=$( < eftseq.dat)
echo $file_seq "file_seq"
file2=eft$(expr $file_seq + 1).dat
echo $file2 "file2"
file3=eftsql$(expr $file_seq + 1).dat
echo $file3 "file3"

...
The commands work on your command line because the file "eftseq.dat" exists in your current directory.

Quote:
...
Code:
 
quote pass gvf1!3Mk
cd orgs
cd "Financial Aid"
cd MIIS
cd 0910
cd FTP
get 04051000.DSB
cat -n inner
file_seq=+ + No such file or directory
rzpeftf[143]: eftseq.dat: cannot open
rzpeftf[143]: eftseq.dat: cannot open
+ shl pain
rzpeftf[163]: shl: not found

...
They don't work here because the file "eftseq.dat" does not exist in the directory of your remote ftp server where you've logged on.

HTH,
tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming a file with sequence number

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)
Discussion started by: mfaizan40
10 Replies

2. Shell Programming and Scripting

Inserting IDs from a text file into a sequence alignment file

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)
Discussion started by: nans
7 Replies

3. Shell Programming and Scripting

Renaming file and check for the renamed file existence

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)
Discussion started by: Priya Amaresh
7 Replies

4. Shell Programming and Scripting

Problems coping a file in a shl script

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)
Discussion started by: rechever
10 Replies

5. Shell Programming and Scripting

Need to decrypt a file in a directory (SHL script)

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)
Discussion started by: rechever
7 Replies

6. Shell Programming and Scripting

last file in a directory in a shl script

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)
Discussion started by: rechever
2 Replies

7. Shell Programming and Scripting

File renaming from list of names contained in another file

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)
Discussion started by: netfreighter
7 Replies

8. Shell Programming and Scripting

Reading a file (one record) in a SHL script

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)
Discussion started by: rechever
2 Replies

9. UNIX for Dummies Questions & Answers

renaming file from text in a file

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)
Discussion started by: isonic1
6 Replies

10. Shell Programming and Scripting

shl script capture a file

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)
Discussion started by: rechever
1 Replies
Login or Register to Ask a Question