Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Can't find the bug in my code - bombing with rename Post 302986893 by SIMMS7400 on Thursday 1st of December 2016 12:29:58 PM
Old 12-01-2016
Can't find the bug in my code - bombing with rename

Hi Folks -

I'm encountering an issue:

Scenario:
We have automated GL data loads utilizing FDMEE. The problem is that some of our Locations could have multiple files. I think we are running into a situation where the script is trying to name the 2 files the same name and it is bombing out.

Question:
Have you ever had to deal with this? Do you have any ideas as to how I could modify the script to accommodate renaming multiple files?

The example file names that we are loading are below.

HYP_GL_EXT_Maurices_CA_Primary_Ledger_NOV-17
HYP_GL_EXT_Maurices_US_Primary_Ledger_NOV-17

Script is below:

Code:
#!/bin/bash
## OracleGL_ASC_MAU_Batch.sh: Load MAU OracleGL

source /u01/app/Automation/env.sh
source $MaxlExePath/setEnv.sh

export Location_Name=OracleGL_ASC_MAU
export Batch_Name=OracleGL_ASC_MAU
export LoadRule_Name=OracleGL_ASC_MAU_Actual
export outputlog=$SCENARIOMANAGEMENT_AUTOMATION_PATH/logs/$Location_Name"_"`date +%Y``date +%m``date +%d`"_"`date +%H``date +%M`.log

echo ------------------------------------------------------------------------- > $outputlog
# Generate 2 digit month, day and 4 digit year:
Day=`date +%d`
Month=`date +%m`
Year=`date +%Y`
All=$Year$Day$Month

# If the system date's day number is 15 or less, then use the prior month, (and prior year if month is January)
if [ $Day -le 15 ]
    then 
        if [ $Month == 01 ]; then
            Output_Month="12"
            Output_Year=$(date -d "-1 year" +%Y)
        else     
            Output_Month=$(date -d "-1 month" +%m)    
            Output_Year=`date +%Y`
        fi
    
fi


if [ $Day -gt 15 ]; then
    Output_Month=$Month
    Output_Year=`date +%Y`
fi

echo "$Output_Month"
echo $Output_Year


#Get the 3 character Month:
if [[ $Output_Month == 01 ]] 
    then MMM="Jan"
elif [[ $Output_Month == 02 ]] 
    then MMM="Feb"
elif [[ $Output_Month == 03 ]]  
    then MMM="Mar"
elif [[ $Output_Month == 04 ]]  
    then MMM="Apr"
elif [[ $Output_Month == 05 ]]  
    then MMM="May"
elif [[ $Output_Month == 06 ]] 
    then MMM="Jun"
elif [[ $Output_Month == 07 ]]  
    then MMM="Jul"
elif [[ $Output_Month == 08 ]]  
    then MMM="Aug"
elif [[ $Output_Month == 09 ]]  
    then MMM="Sep"
elif [[ $Output_Month == 10 ]]  
    then MMM="Oct"
elif [[ $Output_Month == 11 ]]  
    then MMM="Nov"
elif [[ $Output_Month == 12 ]]  
    then MMM="Dec"
fi

echo $MMM

#Rename the file:

cd $FDM_Inbox/$Location_Name/

if [[ -f *.* ]]
then
cat *.* > $FDM_Inbox/$Location_Name/"A~$LoadRule_Name~$MMM-$Output_Year~RR.txt"
#mv -f *.* $FDM_Inbox/$Location_Name/"A~$LoadRule_Name~$MMM-$Output_Year~RR.txt"
fi

LatestFile="A~$LoadRule_Name~$MMM-$Output_Year~RR.txt"

echo GL File Rename - $LatestFile Complete >> $outputlog

echo Start Processing file $LatestFile for FDM Rule $LoadRule_Name on $Date at `date +%H`:`date +%M` >> $outputlog
echo . >> $outputlog

#$FDM_INBOX$Location_Name
cp $LatestFile $FDM_Inbox/batches/openbatch

#Move the renamed file to the archive directory:
mv $LatestFile $FDM_ARCHIVE/$Location_Name/$LatestFile"_"`date +%Y``date +%m``date +%d`"_"`date +%H``date +%M`.txt

cd $Run_Batch_Location


./runbatch.sh admin welcome1 $Batch_Name

echo . >> $outputlog
echo Completed Processing file $LatestFile for FDM Location $Location_Name on $Date at $time >> $outputlog
echo ------------------------------------------------------------------------- >> $outputlog

Thank you for your help!
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Mail bombing

I have just recently had a look at this website and came across the following article: http://www.silkroad.com/papers/html/bomb/node5.html I'm referring to this as this is exactly what is happening to me at this moment in time, and has been going on for over a week now. So far I've had to... (2 Replies)
Discussion started by: Spiffy
2 Replies

2. Shell Programming and Scripting

Can anyone find a bug in this code?? shell script

I have done a script and IT WORKS JUST PERFECT from command line...but in cron it has problems executing... nawk -F"|" ' { s=substr($104,2,18)} {b ++s} END { for (i in b) print i, b } ' $1 > /path/to/files/TranId_w$2 q=`cat /path/to/files/TranId_w$2 | wc -l` echo $q >... (1 Reply)
Discussion started by: amon
1 Replies

3. UNIX for Dummies Questions & Answers

Find and rename all folders with name X.

Is there a command I can use to rename all directories with a certain name to a new name. For instance from my root directory I want to change all folders named '123' to '321' that are in the root directory or any subdirectory. Thanks in advance! (6 Replies)
Discussion started by: mkingrey
6 Replies

4. Shell Programming and Scripting

top's exit code indicates error--is this a bug?

This single line of code in a sh script file top -b -n 1 -U $USER causes the script to prematurely exit with an exit code of 1 (i.e. an error) if the script is run with the -e option (e.g. if set -e is executed near the top of the script file). Alternatively, you can execute it like top... (8 Replies)
Discussion started by: fabulous2
8 Replies

5. Shell Programming and Scripting

Find and rename

Hi, I was wondering if there is a way to find a particular file and then give it as an input to a program and then dump it into another file. Something like this: find ./ -name '*.txt' -exec ~/processText {} > mod.<current_file> \; I've been trying all sorts of weird things but not... (2 Replies)
Discussion started by: Legend986
2 Replies

6. Shell Programming and Scripting

Find and Rename files using (find mv and sed)

In response to a closed thread for degraff63 at https://www.unix.com/shell-programming-scripting/108882-using-mv-find-exec.html the following command might do it as some shells spit it without the "exec bash -c " part: Find . -name "*.model" -exec bash -c "mv {} \`echo {} | sed -e 's//_/g'\`"... (0 Replies)
Discussion started by: rupert160
0 Replies

7. Programming

Algorthm bug of my code

Hello, This porblem bugged me for some time. It is to merge different files of hundred rows to have a union with the ID as key column (kind of similar to join!) and absence with 0. ID File1 A 1 C 3 D 4 M 6 ID File2 A 5 B 10 C 15 Z 26 ID File3 A 2 B 6 O 20 X 9 I want the output... (9 Replies)
Discussion started by: yifangt
9 Replies

8. UNIX for Advanced & Expert Users

Find Gzip rename and mv

Hi all, what i'm trying to configure its to the following, find all files older then 1 min,gzip them ,rename/move with date and extension .gz (example tes.log_2012-07-26.gz) and trying to move them to another folder (gzipped),the command i'm typing its this, find /home/charli/Desktop/test/ -type... (4 Replies)
Discussion started by: charli1
4 Replies
IDATE(3)								 1								  IDATE(3)

idate - Format a local time/date as integer

SYNOPSIS
int idate (string $format, [int $timestamp = time()]) DESCRIPTION
Returns a number formatted according to the given format string using the given integer $timestamp or the current local time if no time- stamp is given. In other words, $timestamp is optional and defaults to the value of time(3). Unlike the function date(3), idate(3) accepts just one char in the $format parameter. PARAMETERS
o $format - The following characters are recognized in the $format parameter string +------------------+---------------------------------------------------+ |$format character | | | | | | | Description | | | | +------------------+---------------------------------------------------+ | | | | B | | | | | | | Swatch Beat/Internet Time | | | | | | | | d | | | | | | | Day of the month | | | | | | | | h | | | | | | | Hour (12 hour format) | | | | | | | | H | | | | | | | Hour (24 hour format) | | | | | | | | i | | | | | | | Minutes | | | | | | | | I (uppercase i) | | | | | | | returns 1 if DST is activated, 0 otherwise | | | | | | | | L (uppercase l) | | | | | | | returns 1 for leap year, 0 otherwise | | | | | | | | m | | | | | | | Month number | | | | | | | | s | | | | | | | Seconds | | | | | | | | t | | | | | | | Days in current month | | | | | | | | U | | | | | | | Seconds since the Unix Epoch - January 1 1970 | | | 00:00:00 UTC - this is the same as time(3) | | | | | | | | w | | | | | | | Day of the week ( 0 on Sunday) | | | | | | | | W | | | | | | | ISO-8601 week number of year, weeks starting on | | | Monday | | | | | | | | y | | | | | | | Year (1 or 2 digits - check note below) | | | | | | | | Y | | | | | | | Year (4 digits) | | | | | | | | z | | | | | | | Day of the year | | | | | | | | Z | | | | | | | Timezone offset in seconds | | | | +------------------+---------------------------------------------------+ o $timestamp - The optional $timestamp parameter is an integer Unix timestamp that defaults to the current local time if a $timestamp is not given. In other words, it defaults to the value of time(3). RETURN VALUES
Returns an integer. As idate(3) always returns an integer and as they can't start with a "0", idate(3) may return fewer digits than you would expect. See the example below. ERRORS
/EXCEPTIONS Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the $TZ environment variable. See also date_default_timezone_set(3) CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.0 | | | | | | | Now issues the E_STRICT and E_NOTICE time zone | | | errors. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 idate(3) example <?php $timestamp = strtotime('1st January 2004'); //1072915200 // this prints the year in a two digit format // however, as this would start with a "0", it // only prints "4" echo idate('y', $timestamp); ?> SEE ALSO
date(3), getdate(3), time(3). PHP Documentation Group IDATE(3)
All times are GMT -4. The time now is 05:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy