Hi,
Please see the below information.
1. Read files one by one and run the script.
2. Check if the filename is CHARTER OR NUMBER
3. Run the case statement.
I have files in the folder. i will get 300 files in a single day.
Read the first file then check the filename having charter or number.
Source_file= source filename
If it is a CHARTER then
fname=`echo $Source_file |cut -d '_' -f1` # ex input:Abc_111111111111.csv output :Abc
else NUMBER
fname=`echo $Source_file |cut -d '_' -f2` # ex input:101010_kkk_bbbb.csv output :kkk
fi
case $fname in
Abc) echo "Abc found";
Mv $Source_file taget_path;;
kkkk) echo "CCCC found" ;
Mv $Source_file Backup directory;;
*) echo "INVALID filename!" ;;
esac
I have written the script. It is working fine.
On demand, I will receive files in the source directory [Each day I will receive 300 files]. Using control-m scheduler I am scheduling the below shell script every five mins.
But I am facing lot of problems to atomize for the following things also include in the script.
Filename passing as a parameter. But I want to atomize to read all the files in the directory execute the shell script one by one.
First it will check the starting with charter file [Ex: All_101010101010.csv] then it will execute script for only that file. After the completion of the script automatically zip the file and moved to back up directory.
Then execute the script for starting with number files[Ex: 101010_EMP_1200.csv]. After the completion of the script automatically zip the file and moved to back up directory.
And so on....
#!/bin/sh
####################################################################
# Check the input parameters
####################################################################
if [ $# -ne 1 ]
then
echo "parameter missing"
enit 1
fi
Source_file=$1
fname=`echo $Source_file|cut -d '_' -f1`
####################################################################
# Check the source file is a charter or number
####################################################################
case $fname in
[0-9]*) var=`echo $Source_file|cut -d '_' -f2` ;;
[a-zA-Z]*) var=`echo $Source_file|cut -d '_' -f1` ;;
*) echo "Invalid file name" ;;
esac
####################################################################
#Based on the type of file run the data stage job.
####################################################################
if [ $var = 'ALL']
then
dsjob -server :$SERVER_PORTID
-run
-mode NORMAL
-jobstatus
-param INPUT_GCDB_DIR=$InputFilePath
-param INTERIM_DIR=$SequentialFilePath
-param SCRIPT_DIR=$ShellScriptPath
-param CountryID=$CountryID
-warn 0 $ProjectName $JobName1.$CountryID
elseif [ $var = 'EMP']
then
dsjob -server :$SERVER_PORTID
-run
-mode NORMAL
-jobstatus
-param INPUT_GCDB_DIR=$InputFilePath
-param INTERIM_DIR=$SequentialFilePath
-param SCRIPT_DIR=$ShellScriptPath
-param CountryID=$CountryID
-warn 0 $ProjectName $JobName2.$CountryID
elseif [ $var = 'SALES']
then
dsjob -server :$SERVER_PORTID
-run
-mode NORMAL
-jobstatus
-param INPUT_GCDB_DIR=$InputFilePath
-param INTERIM_DIR=$SequentialFilePath
-param SCRIPT_DIR=$ShellScriptPath
-param CountryID=$CountryID
-warn 0 $ProjectName $JobName3.$CountryID
else
echo " not valid"
fi
#!/usr/bin/sh
for x in *.csv
do
x=`echo $x | tr [a-z] [A-Z]`
case $x in
ALL*) ## execute your job for "ALL" here
;;
*EMP*) ## execute your job for "EMP" here
;;
*SALES*) ## execute your job for "SALES" here
;;
*) echo "Invalid file name"
;;
esac
done
$
$
Hi,
When i run the below script i am getting the below error.
data2.sh[15]: 0403-057 Syntax error at line 23 : `;' is not expected.
#!/usr/bin/sh
#####################################
# Execute only for ALL filename
#####################################
for x in `ls /home_dir/ | egrep '^[a-zA-Z].*(csv$|cma$)'`
do
echo $x
y=`echo $x |cut -d '_' -f1`
case $y in
ALL ) echo "ALL found"
;;
*) echo "No map file found "
;;
esac
done
#####################################
# Execute only for CCCC filename
#####################################
for x in `ls /home_dir/ | egrep '^[0-9].*(csv$|cma$)'`
do
echo $x
y=`echo $x |cut -d '_' -f2`
case $y in
CCCC ) echo "Data file found" # adding some logic here.
z=$?
if [ $z -eq 0] then `gzip $x ; mv $x.gz /home_dir/bkp/abc.gz` else Exit 1 fi
;;
*) echo "No Data file found "
;;
esac
done
Hi,
I am using control-m to trigger the shell script every 5 mins.
time slot to trigger shell script
example:
10.00 - automatically trigger the shell script -in my source directory i have 2 files[101111_EMP_3333.csv,101011_SALES_2345.csv]. those two files are processed. this looks fine.
10.05 - automatically trigger the shell script - no files present in the source directory- it wont execute the script. this looks file.
10.10 - automatically trigger the script-i have 2 files in the source directory-[101010_EMP_2222.csv,101111_SALES_6789.csv]. started processing for the first file- it takes 6 mins to complete then next file completed 3 mins.- total execution time is 9 mins.
10.13. i have one more file[101015_EMP_6666.csv] in the source file directory. this file will not execute here until the above two files should complete.what is the condition i have to place in this situation.
10.15
#!/usr/bin/sh
if [ $# -ne 1 ]
then
exho "paramter missing"
exit 1
fi
Indir=$1
new()
{
for x in `ls $Indir | egrep '[0-9].*_'$flag'_.*(csv$|cma$)'`
do
y=`echo $x|cut -d '_' -f2`
case $y in
$y ) echo " souce file found" ; wc -l $x;mv $x /home/bkp/ # doing many calaculations here based on the file.
;;
* ) echo "source data file not found"
;;
esac
done
}
flag=EMP
new $Indir $flag &
flag=SALES
new $Indir $flag &
wait
echo "completed"