Hello All,
Since i'm relatively new in shell script need your guidance.
I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder.
so if filename contains hyr
word and it has .md and .db extension; it will move to TUM/HYR
folder; if extension is .txt
it should convert using dd
command to edcdic
and move it to TUM/HYR
if filename contains par
word and it has .md
and .db
extension; it will move to TUM/par
folder; if extension is .txt
it should convert using dd
command to edcdic
and move it to TUM/par
if filename contains mar
word and it has .md
and .db
extension; it will move to TUM/mar
folder; if extension is .txt
it should convert using dd
command to edcdic
and move it to TUM/mar
I have a folder which contains multiple sub folder.
Main folder name is MUM
sub folders are (there are multiple folder, but just for testing i have mentioned few folders only; script should be for any numbers of folder)
HYR
PAR
MAR
SAR
Now i have few files in the above subfolder. File name are
ttt_hyr_20162010.md
ttt_hyr_20162010.db
ttt_hyr_20162010.txt
ttt_par_20162010.md
ttt_par_20162010.db
ttt_par_20162010.txt
ttt_mar_20162010.md
ttt_mar_20162010.db
ttt_mar_20162010.txt
ttt_sar_20162010.md
ttt_sar_20162010.db
ttt_sar_20162010.txt
so for example the folder structure and the files in it will look like below
MUM/HYR/ttt_hyr_20162010.md
MUM/HYR/ttt_hyr_20162010.db
MUM/HYR/ttt_hyr_20162010.txt
MUM/PAR/ttt_par_20162010.md
MUM/PAR/ttt_par_20162010.db
MUM/PAR/ttt_par_20162010.txt
and so on..
I simply want to create a shell script to copy files from MUM/HYR
to TUM/HYR
, MUM/PAR
to TUM/PAR
, MUM/MAR
to TUM/MAR
and MUM/SAR
to TUM/SAR
folders based on a word in a filename and its extension
-
The script will read the
MUM
folder and its subfolders(HYR
) and the file name and from that file name it will readhyr
word and copy that particular file which has particular wordhyr
and extension.md
and.db
and put it into the output folder(TUM/HYR
). -
Same things should happen for other subfolder. The script will read the
MUM
folder and its subfolders calledPAR
and the file name and from that file name it will readpar
word and copy that particular file which has particular wordpar
and extension.md
and.db
and put it into the output folder calledTUM/PAR
. -
For
.txt
file in those particular subfolder; the files should get converted fromascii
toebcdic
and then move to that particular output subfolder based on the particular word in a filehyr
and
put that in TUM/HYR
folder
- For
.txt
file in those particular subfolder; the files should get converted fromascii
toebcdic
and then move to that particular output subfolder based on the particular word in a filepar
and
put that in TUM/PAR
folder
After every file copy error and success log should be created
After the Script is executed the output folder will look like below
TUM/HYR/ttt_hyr_20162010.md
TUM/HYR/ttt_hyr_20162010.db
MUM/HYR/ttt_hyr_20162010.dat
TUM/PAR/ttt_par_20162010.md
TUM/PAR/ttt_par_20162010.db
TUM/HYR/ttt_hyr_20162010.dat
and so on..
below is the code im in need of
#!/bin/bash
DATESTMP="`date +%m%d%y%H%M`"
OGIT="/usr/local/testing/log.${DATESTMP}"
touch $OGIT
echo " SCRIPT STARTED AT `date` " >$OGIT
chmod 666 "$OGIT"
MRPT=/usr/local/resting
echo " ############# START OF AUTOMATION SCRIPT FOR MOVING FILES at `date` ################# "
cd MUM/HYR
if [filename contains hyr and has extension .md and db]; then
cp MUM/HYR/*.md TUM/HYR
cp MUM/HYR/*.db TUM/HYR
if [filename contains hyr and has extension .txt]; then
dd if=text.ascii of=text.ebcdic conv=ebcdic
cp MUM/HYR/*.txt TUM/HYR
cd MUM/PAR
if [filename contains hyr and has extension .md and db]; then
cp MUM/PAR/*.md TUM/HYR
cp MUM/PAR/*.db TUM/HYR
if [filename contains par and has extension .txt]; then
dd if=text.ascii of=text.ebcdic conv=ebcdic
cp TUM/PAR/*.txt TUM/PAR
echo " ############# END OF AUTOMATION SCRIPT FOR MOVING FILES at `date` ################# "
The script should look for all the sub folders and copy files of particular word in that file and its extension and put it into output or destination folder.