- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How can I do this with Unix?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 11:04 AM
06-06-2005 11:04 AM
The strings are something like:
1) aaa authentication + I don't remember the rest.
2) aaa authentication + I don't remember the rest + more text.
3) set authentication + I don't remember the rest.
4) set authentication + I don't remember the rest + more.
5) there may even be a couple of more strings of text.
P.S. I'm not very good with the Unix shell.
Thanks for any input on how I can do this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 11:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 11:29 AM
06-06-2005 11:29 AM
Re: How can I do this with Unix?
First create this command to test each file, call it scanit.sh:
--------------------------------------
#!/usr/bin/sh
FNAME=${1}
# first make sure this is some form of text
# file
file ${FNAME} | grep -i "text"
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then # okay, it is a text file
grep -q -e "aaa auth xxxx" \
-e "bbb auth yyyy" \
-e "I'm not very good"
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "${FNAME}" # no patterns match
fi
else
echo "${FNAME} ain't no text file!!" >&2
fi
exit 0
----------------------------------
Save scanit.sh and chmod 755 scanit.sh
Now cd to your desired starting directory:
find . -type f -exec scanit.sh {} \;
Man file, find, and grep to see how this works. ${?} is the status of the last command executed and 0 means that grep matched at least 1 of the patterns otherwise there were no matches. I haven't tested this but it should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 11:54 AM
06-06-2005 11:54 AM
Re: How can I do this with Unix?
Question on the firt response?
# find
Where in the command could I put the different strings of text to search for? Also, I'm looking for files that don't contain the text. How would I know which ones don't?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 03:27 PM
06-06-2005 03:27 PM
Re: How can I do this with Unix?
the "egrep" section of the find command contains the search strings. man egrep
Option "-v" to egrep excludes all files that don't contain the search strings.
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 04:46 PM
06-06-2005 04:46 PM
Re: How can I do this with Unix?
You can -exec option with find command. There is some limitation in that usage. In stead of that you can use xargs for that as,
find
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 04:49 PM
06-06-2005 04:49 PM
Re: How can I do this with Unix?
find
It will do grep with all pattens available.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 05:07 PM
06-06-2005 05:07 PM
Re: How can I do this with Unix?
grep -v simply means that display all the lines that do not match the pattern. It does not tell you whether the pattern matched any line or not. Rob wants to list the files that do not contain the pattern.
I would agree with Clay's script. You need to do positive grep and then check the return value to see whether any pattern matched or not. Similar script would be
for i in `ls -R`
do
if [ -f $i ]
then
grep -q -e
if [ $? -ne 0 ]
then
echo $i
fi
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 05:11 PM
06-06-2005 05:11 PM
Re: How can I do this with Unix?
grep -ev '
It will do the same to,
egrep -v '
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 11:45 PM
06-06-2005 11:45 PM
Re: How can I do this with Unix?
1)aaa authentication login default group tacacs+ local
2)aaa authentication login default tacacs+ local
3)aaa authentication login default local tacacs+
4)aaa authentication login default local group tacacs+
5)set authentication login tacacs enable telnet primary
6)set authentication login local enable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 12:52 AM
06-07-2005 12:52 AM
Re: How can I do this with Unix?
find . -type f -exec grep -lv -e "string1" -e "string2" -e "string3" {} \;
eg: -
find . -type f -exec grep -lv -e "aaa authentication + I don't remember the rest" -e "aaa authentication + I don't remember the rest + more text" -e "set authentication + I don't remember the rest" -e "set authentication + I don't remember the rest + more" -e "there may even be a couple of more strings of text" {} \;
This will execute a find from the current directory on all files (not directories), and for each execute a grep -v (-v means DOESN'T include), specifying a -e for each option you want to search for. The -l makes the grep simply display the name of the file that matches the (not found due to -v) files. See?
Therefore running this will provide a list of all files from the current directory that contain none of your strings. This is what you want?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 01:14 AM
06-07-2005 01:14 AM
Re: How can I do this with Unix?
As has correctly been said earlier the -v will show every file that contains at least one line without every clause you want so it's not correct.
An easy alternative may be: -
for file in `find . -type f`
do
grep -ql -e "string1" -e "string2" -e "string3" $file
if [ $? -ne 0 ]; then
echo $file
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 01:26 AM
06-07-2005 01:26 AM
Re: How can I do this with Unix?
find . -type f -exec grep -lv -e "aaa" -e "local" {} \;
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- e
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- e
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- e
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 01:31 AM
06-07-2005 01:31 AM
Re: How can I do this with Unix?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 01:34 AM
06-07-2005 01:34 AM
Re: How can I do this with Unix?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 01:38 AM
06-07-2005 01:38 AM
Re: How can I do this with Unix?
find . -type f -exec egrep -lv "aaa|local" {} \;
I don't have a Sun box to test it so it's a guess...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 03:56 AM
06-07-2005 03:56 AM
Re: How can I do this with Unix?
Any ideas?
#!/usr/bin/ksh
for files in `find /var/adm/CSCOpx/files/archive/shadow/Cisco_Router -type f`
do
egrep -l -e "aaa authentication login default group tacacs+ local" -e "aaa authentication login d
efault tacacs+ local" -e "aaa authentication login default local tacacs+" -e "aaa authentication
login default local group tacacs+" $files
if [ $? -ne 0 ]; then
echo $file
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 04:16 AM
06-07-2005 04:16 AM
Re: How can I do this with Unix?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 04:29 AM
06-07-2005 04:29 AM
Re: How can I do this with Unix?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 04:57 AM
06-07-2005 04:57 AM
Re: How can I do this with Unix?
find
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 05:43 AM
06-07-2005 05:43 AM
Re: How can I do this with Unix?
The script I'm using is this. I'm saying to return files not equal to zero but it's still displaying all the files that do have a match.
I'm going nuts over this!!!
#!/usr/bin/ksh
for files in `find /var/adm/CSCOpx/files/archive/shadow/Cisco_Router -type f`
do
egrep -e "aaa authentication login default group tacacs+ local" -e "aaa authentication login default tacacs+ local" -e "aaa authentication login default local tacacs+" -e "aaa authentication login default local group tacacs+" $files
if [ $? -ne 0 ]; then
echo $files
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 06:42 AM
06-07-2005 06:42 AM
Re: How can I do this with Unix?
You need to add "-v" as an option to your egrep command for excluding files that match the strings you'ave specified. See below:
=============================================
#!/usr/bin/ksh
for files in `find /var/adm/CSCOpx/files/archive/shadow/Cisco_Router -type f`
do
egrep -v -e "aaa authentication login default group tacacs+ local" -e "aaa authentication login default tacacs+ local" -e "aaa authentication login default local tacacs+" -e "aaa authentication login default local group tacacs+" $files
if [ $? -ne 0 ]; then
echo $files
fi
done
=============================================
best of luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 02:13 PM
06-07-2005 02:13 PM
Re: How can I do this with Unix?
I am also a bit of a stranger in Unix land, but since my boss requires me to aquire Unix skills, I decide that following this forum would not be the worst option.
Following this thread set me to thinking.
Reading the various answers, I slowly grew an idea about what __I__ would do in this situation, if no immediate *X solution would transpire:
1. Export the directory as an NFS mount point.
2. On a VMS system, MOUNT that point (which thereby on VMS becomes a DNFS type disk)
3. SET DEFAULT DNFSxxx:[000000]
( xxx is whatever the previous MOUNT generated as the next unit number; SET DEFAULT is more or less equivalent to cd).
(any coming wrappings to be attributed to ITRC, they are NOT part of the command)
$ SEARCH [...]*.*
"
Explanation:
FIND [...] :operate on all files in this directory and all subdirectories
*.* : operate on all file names of all file types
(in VMS one could add another ".*" to also search all previous versions, but since they are deleted in Unix anyway, that is not applicable)
^searchtext","searchtext2"
search all specified files for any of the comma-separated list of quoted string.
,... : not part of the command syntax per se. Just a placeholder for any amount of next elements of the list of strings to be searched for.
/MATCH=NOR: EXclude if found
/LIMIT=1: stop searching this file after first find
/SILENT : do not echo records that are selected (otherwise any record NOT containing a search string would be echoed!)
/HEADER (this one just for clarity: it is the default anyway) : echo names of files that meet search criteria
/OUTPUT= : any filename you want to hold the resulting output, being the filenames that do NOT contain any of those strings.
No special file naming, so placed in the default (Unix, say work:) directory, ie, on the *X system.
4. behave, so DISMOUNT DNFS.
----
Okay, I do admit that all details of the command made me thinking for a while, but I thought it was a nice challenge.
Caveat: you need a VMS system for this, that can reach your Unix, and you need to be allowed to export on your Unix (or Linux) box, and you need (assistence of someone with) sufficient privileges on VMS for the MOUNT and DISMOUNT
Nevertheless: I enjoyed the challenge!
Proost.
Have one on me.
jpe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2005 09:45 PM
06-07-2005 09:45 PM
Re: How can I do this with Unix?
The optioans turns on the quiet mode of egrep facility. Do not use '-v' option.