Operating System - HP-UX
1827296 Members
2629 Online
109961 Solutions
New Discussion

Re: How to locate this......?

 
SOLVED
Go to solution
Clarence J
Frequent Advisor

How to locate this......?

Hello All,

I have a question that may seem easy for most of you, but I'm still new to all this, so bear with me.

I'm looking for a particular script that is already written and contains the word "tar" in it. It is somewhere on the system but I don't exactly know where it is. How do I locate it?

Sorry, if this seems a bit too simple for this forum but I'd really appreciate if someone can point me in the right direction. BTW, any good shell script programming sites?

Thanks for your patience.
11 REPLIES 11
John Poff
Honored Contributor

Re: How to locate this......?

Hello,

To find a script with the name "tar" in it on your system, try this find command (as root):

find / -name "*tar*"

As for the web sites for scripts, I haven't found any. Maybe some of the other people here know of some.

JP
John Poff
Honored Contributor

Re: How to locate this......?

Also, don't worry about asking the simple questions. No question is too simple for this forum. The people here are great and are willing to help with any kind of question, so ask away! Besides, sometimes it is the easy questions that show me how much I really don't know.

JP
Clarence J
Frequent Advisor

Re: How to locate this......?

Hi John,

Thanks for your reply and encouraging words.

Well, your find command looks for files that start with the word "tar". What I'm actually looking for is the contents of the file(s) that may contain the word "tar".

Thanks again!
Michael Tully
Honored Contributor
Solution

Re: How to locate this......?

Hi,

If your looking for the word 'tar' in a script,
you need to use the 'grep' command to do this.
You will most likely find that scripts could
be found in directories such as /usr/local/bin
and the like, so look do something like this:

# cd /usr/local/bin
# grep -i tar *

And as John has mentioned, ask away help here
is in abundance, in fact it is sometimes quicker
to post a question here and get an
answer than to call HP response centre.

Another idea I had was to look for it in your
crontab file if it is being used for your
backups.

Good luck
Michael
Anyone for a Mutiny ?
John Poff
Honored Contributor

Re: How to locate this......?

Hello again,

Sorry! I didn't read your question closely enough. Here is an example from the find man page that should do what you want to do:

Search the two directories /example and /new/example for files containing the string Where are you and print the names of the files:

find /example /new/example -exec grep -l 'Where are you' {} \;


So you just need to replace 'Where are you' with 'tar', and replace the directories with where you suspect the script might be and go for it.

JP

Clarence J
Frequent Advisor

Re: How to locate this......?

That was fantastically fast answers!! Thanks for all the help guys! WOW! and real NEAT solutions.

Now this is what I call Value-Added Services!!!:-)
Magdi KAMAL
Respected Contributor

Re: How to locate this......?

Hi Clarence,

Other tip

lookStr="tar"
for i in `find /dir1 /dir2 -name ?*? -print`
do
foundStr=`grep $lookStr $i`
if [[ $foundStr != "" ]]
then
echo "-=> String '$lookStr' found in file '$i' "
fi
done
James R. Ferguson
Acclaimed Contributor

Re: How to locate this......?

Hi:

With regard to learning shell scripting, here are two threads with many suggested "favorite" sources for education. The best way, as always, is to simply write, write, write. Take a look at these:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0xb75e7e990647d4118fee0090279cd0f9,00.html

http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0xbb5e7e990647d4118fee0090279cd0f9,00.html

...JRF...
Mark Vollmers
Esteemed Contributor

Re: How to locate this......?

One more quick note about scripting- I'm not sure if you have programed with other langauges, but it's really just the same (actually, a little easier, I think). You really don't have as much syntax to worry about (compared with Fortran, for example). All the basic principles apply (if-then, while, etc.) I got freaked out when I started, cause I was trying to work with a huge script. My advice, start small. Make a script to find a file, move a log, etc, just to get familiar with it. Work your way up from there. Don't hesitate to throw a script up here as well, if you've got a problem with one. Eveyone's really good not only about finding errors, but with hints on how to make it better. Happy scripting!

Mark

ps. don't forget to make the script executable after you write it!
"We apologize for the inconvience" -God's last message to all creation, from Douglas Adams "So Long and Thanks for all the Fish"
Shannon Petry
Honored Contributor

Re: How to locate this......?

Another problem you will run into is that grep can find binary files too, and grab strings from them. If you are trying to find a text string, you may want to do something like...
#!/bin/sh
PATH=/usr/bin:/usr/sbin
export PATH
LOG='/tmp/files_that_contain_tar'
TMPLIST='/tmp/tmp_list.txt'
if [ -f ${LOG ] ; then
rm -f ${LOG}
fi
if [ -f ${TMPLIST} ] ; then
rm -f ${TMPLIST}
fi
touch ${LOG}
touch ${TMPLIST}
find / -type f -print >> ${TMPLIST}
for FILE in `cat ${TMPLIST}` ; do
TESTASCII=`file ${FILE}|grep -i text`
if [ "${TESTASCII}x" = "x" ] ; then
#DISCARD
echo "">>/dev/null
else
TEST4TAR=`grep tar ${FILE}`
if "${TEST4TAR}x" = "x" ] ; then
# it aint there...
echo "">>/dev/null
else
# It's there...put it into a log...
echo ${FILE} >>${LOG}
fi
fi

# END OF SCRIPT
I did not debug this, but it should be okay...

The beauty of UNIX is that there are millions of ways to attack and solve problems. There's lots of built in logic, if you know where it is, and how to use it....

Regards,
Shannon
Microsoft. When do you want a virus today?
Clarence J
Frequent Advisor

Re: How to locate this......?

Hello Everyone,

I'm truly encouraged with all the responses and help I got fr everyone! Thanks for the support! I'm really glad I found this forum. It's made my load much lighter.

THANKS FOR ALL THE SUPPORT!