1828040 Members
2031 Online
109973 Solutions
New Discussion

Re: Script ISSUE

 
SOLVED
Go to solution
Karthick K S
Frequent Advisor

Script ISSUE

Hi,

I am facing some problem on script,
i want to assign output(i.e some file) to some variable its given below, after that i want rename this filename.

gmfile=$(/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER})

mv gmfile xxtest.txt

but its not working pls help me on this

21 REPLIES 21
RAC_1
Honored Contributor

Re: Script ISSUE

Can you run the command manually??

Have you set all required variables??

set -vx, now do gmfile=$(/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER})

Does complain about anything??
There is no substitute to HARDWORK
Karthick K S
Frequent Advisor

Re: Script ISSUE

Hi RAC,

I set all varibales

i runned the same but its same problem file received on filesystem but not assign to variable

Muthukumar_5
Honored Contributor

Re: Script ISSUE

Can you post what you are getting for?

/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER}

gmfile="$(/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER})"
echo ${gmfile}

post this information.!

hth.
Easy to suggest when don't know about the problem!
Karthick K S
Frequent Advisor

Re: Script ISSUE


/opt/mqm/scripts/mqigetfn CREATE /usr/ ${QNAME} ${QMANAGER}
For this output is,
file will copied on filesystem /usr/

gmfile="$(/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER})"
echo ${gmfile}

for this output is,
null there is no output but file copied to filesystem

Actually what my problem i receive file containing ^M containing i want to remove ^M character then copied to that samefilename
Muthukumar_5
Honored Contributor

Re: Script ISSUE

^M characters will be added when you transfer a file from dos.

Change it as,

dos2ux filename > newfile

strings filename > newfile

It will be changed.

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Script ISSUE

Refer this to remove ^M characters more,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=972302

If you want to change into the same file then,

perl -pi -e 's/\^M//g' filename

hth.
Easy to suggest when don't know about the problem!
Karthick K S
Frequent Advisor

Re: Script ISSUE

I know that dos2ux but for eg.

my file name is hptest.txt

opt/mqm/scripts/mqigetfn CREATE /usr/ ${QNAME} ${QMANAGER

after i runned this one

/usr/hptest.txt but containing ^M character

i want to remove ^M character then filename should be /usr/hptest.txt


RAC_1
Honored Contributor

Re: Script ISSUE

does following work??

gmfile=$(/opt/mqm/scripts/mqigetfn CREATE "${DIRECTORY}/ ${QNAME} ${QMANAGER}")

echo ${gmfile}
There is no substitute to HARDWORK
Muthukumar_5
Honored Contributor

Re: Script ISSUE

Do like,

/opt/mqm/scripts/mqigetfn CREATE /usr/ ${QNAME} ${QMANAGER}
perl -pi -e 's/\^M//g' /usr/hptest.txt

It will do it.

hth.

Easy to suggest when don't know about the problem!
Orhan Biyiklioglu
Respected Contributor

Re: Script ISSUE

perl -ni.bak -e 's/\r\n/\n/s;s/\032//s;print' /usr/hptest.txt

This will remove ^M characters from /usr/hptest.txt file and also make a backup copy with .bak extension (ie. hptest.txt.bak)

hth
Karthick K S
Frequent Advisor

Re: Script ISSUE

perl -pi -e 's/\^M//g' /usr/hptest.txt

its not removing ^M character
RAC_1
Honored Contributor

Re: Script ISSUE

/opt/mqm/scripts/mqigetfn CREATE /usr/ ${QNAME} ${QMANAGER}|dos2ux
There is no substitute to HARDWORK
Muthukumar_5
Honored Contributor

Re: Script ISSUE

sorry. Just use as,

perl -pi -e 's/\r\n/\n/g' /usr/hptest.txt

Example:
# cat -v test.txt
hi^M
bye # perl -pi -e 's/\r\n/\n/' test.txt
# cat -v test.txt
hi
bye#

Steps:

/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER}
perl -pi -e 's/\r\n/\n/g' /usr/hptest.txt

hth
Easy to suggest when don't know about the problem!
Karthick K S
Frequent Advisor

Re: Script ISSUE

/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER}
perl -pi -e 's/\r\n/\n/g' /usr/hptest.txt


this is working but

that filename i dont know this are through script that time how should i get the filename

from ls -tr how i should i take last row filename i.e latest file.
Orhan Biyiklioglu
Respected Contributor

Re: Script ISSUE

ll -tr | tail -1 | awk '{print $9}'

will give you the name of the last modified file.

hth
Muthukumar_5
Honored Contributor

Re: Script ISSUE

Please elaborate this action first:

Question 1:
/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER}

what is ${DIRECTORY}, ${QNAME} and ${QMANAGER} variable contents.

--

We can get latest file in /usr directory as,

cd /usr
ls -lt | head -2 | tail -1 | awk '{ print $9 }'

It will not work all the times. If some body update the file contents then hpuxtest.txt will not come anyway.

Question 2:
Is the new file creation will be with hpuxtest.txt only or with some other specific name.
--

Question 3:
Is /opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER} copying file to /usr directory? Is there any verbose information which saying that specific file is copied to location?

--

Post all relavent informations to answer.

hth.
Easy to suggest when don't know about the problem!
Karthick K S
Frequent Advisor

Re: Script ISSUE

Question 1:
/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER}

${DIRECTORY} is /usr/received/

&{QNAME}-Qeuenname

${QMANAGER}-QueueManager Name

I will receive file from some other place i.e Singapore



Question 2:
Is the new file creation will be with hpuxtest.txt only or with some other specific name.

No filename would be differenct at each time
--

Question 3:
Is /opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER} copying file to /usr directory?
No Verbose information

last question

we can use perl command on shell script

--
Muthukumar_5
Honored Contributor

Re: Script ISSUE

Do you meant to ask "can we use perl command on shell script?"

Yes. Surely. You can use all shell actions with shell scripts.

The only problem you are having now is the filename which you are getting from singapore. /opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER} action is not returning any filename information. How do you know that it will create in /usr/ location? Collect the location where exactly that application copies the file.

Can you post the execution details of,

/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER}

in shell to help you out with suitable shell code(s).

hth.
Easy to suggest when don't know about the problem!
Karthick K S
Frequent Advisor

Re: Script ISSUE

file exactly copies under $DIRECTORY i.e /usr/received/

Muthukumar_5
Honored Contributor
Solution

Re: Script ISSUE

To get the new file information use this script:

#!/bin/ksh
PATH=$PATH:/usr/bin:/usr/sbin
rm -f /tmp/old.log /tmp/new.log
ls -l ${DIRECTORY} > /tmp/old.log
/opt/mqm/scripts/mqigetfn CREATE ${DIRECTORY}/ ${QNAME} ${QMANAGER}
ls -l ${DIRECTORY} > /tmp/new.log
FILENAME=$(grep -vf /tmp/old.log /tmp/new.log | awk '{ print $9}')
echo "New filename --> ${FILENAME}"
perl -pi -e 's/\r\n/\n/' ${FILENAME}
# end
exit 0
###

hth.
Easy to suggest when don't know about the problem!
Karthick K S
Frequent Advisor

Re: Script ISSUE

Thanks all guys for helping to develop my script,
now my script is working fine.