- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: scripting problem for repeat lines
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
02-04-2004 04:02 AM
02-04-2004 04:02 AM
This is what I have it doing... in big picture...
I have a file of 14 ip's that I have an expect script uses to telent and change passwd.
The only way I can make sure that all of them are accessed is, on login I "put" a comment in a file $IP, logged in.
Then if it actually makes its way and changes the passwd, it puts another line $IP, changed passwd.
Now at the end the whole file should be wc -l =30. If not it emails the file.
What I would like it to do is send me the IP that did not sucessfully do a logged in, and I passwd change.
This is a snipit of the file...
**** LOGIN ENTRIES for Wed Feb 4 10:25:03 CST 2004 ****
xxx.xxx.xxx.20, logged in.
xxx.xxx.xxx.20, changed passwd.
xxx.xxx.xxx.21, logged in.
xxx.xxx.xxx.21, changed passwd.
xxx.xxx.xxx.22, logged in.
xxx.xxx.xxx.22, changed passwd.
xxx.xxx.xxx.23, logged in.
xxx.xxx.xxx.24, logged in.
xxx.xxx.xxx.24, changed passwd.
So as you can see, I had an error with xxx.xxx.xxx.23
How can I just parse that out, and send in am email, instead of the whole file and I have to search for it...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 04:05 AM
02-04-2004 04:05 AM
Re: scripting problem for repeat lines
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 04:10 AM
02-04-2004 04:10 AM
SolutionA simple script would be to get the list of the IP addresses and grep for "changed passwd" for that IP address. If it returns 1, then the script failed for that IP. For ex.,
#!/usr/bin/ksh
EMAIL=yourid@yourdomain.com
STAMP=0
trap 'rm -f /tmp/host$$' 0 1 2
for HOST in $(awk '{FS=",";print $1}' data1 |sort|uniq)
do
grep $HOST data1 |grep -q "changed passwd"
if [ $? != 0 ]
then
echo $HOST >> /tmp/host$$
STAMP=1
fi
done
Modify EMAIL in the script to point to yours.
-Sri
if [ $STAMP = 1 ]
then
mailx -s "List of failed hosts" $EMAIL < /tmp/host$$
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 05:57 AM
02-04-2004 05:57 AM
Re: scripting problem for repeat lines
rm -r /tmp/host.not
for HOST in $(awk '{print $1}' /tmp/host |sort|uniq)
do
grep $HOST /tmp/host |grep -q "changed passwd"
if [ $?!=1 ]
then
echo $HOST >>/tmp/host.not
fi
done
It still puts every line in host.not
I have taken out the comma to awk the file better.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 06:01 AM
02-04-2004 06:01 AM
Re: scripting problem for repeat lines
Based on your input file as given in the example, the seperator is , so you will need to use 'awk '{FS=",";print $1}'' to get the IP addresses.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 06:06 AM
02-04-2004 06:06 AM
Re: scripting problem for repeat lines
You are right. You don't need to use FS=",".
The problem is grep -q "chaged password" will return 0 if it is found. So, the test would be
if [ $? != 0 ] # <====
then
echo $HOST >>/tmp/host.not
fi
as per your script.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 06:29 AM
02-04-2004 06:29 AM
Re: scripting problem for repeat lines
And that is what I want entered into the host.not file.
I want all the IP addresses that do not have "changed passwd" in the host.not file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 06:46 AM
02-04-2004 06:46 AM
Re: scripting problem for repeat lines
1. I used FS="," otherwise you will get hostnames with a ',' with them. So, your output will look better.
2. To clarify the last post -
grep xxx.xxx.xxx.24 myhost|grep -q "changed passwd"
This will return 0 ($? variable)
grep xxx.xxx.xxx.23 myhost |grep -q "changed passwd"
This will return 1 ($? variable)
You can do it in multiple ways
if [ $? != 1 ]
This means "changed passwd" string may be associated with the host. This is what you had not what you want.
if [ $? = 1 ]
This will work for this situation. However, there is no guarantee that $? is always going to be 1 for failures.
if [ $? != 0 ]
This means unsuccessful. This means "changed passwd" string is not associated with the host. This is what you want.
Try it and see.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 07:14 AM
02-04-2004 07:14 AM
Re: scripting problem for repeat lines
but, it still errors at at...
if [ $?=1 ]
then
echo $HOST >>/tmp/host.not
fi
I still get the same answer if I do...
if [ $?!=0 ]
The exact same. I must be doing something wrong.
I modified the host file and took out all the comma's so now it is just XXX.XXX.XXX.21 logged in
and so on..
rm -r /tmp/host.not
for HOST in $(awk '{print $1}' /tmp/host |sort|uniq)
do
grep $HOST /tmp/host |grep -q "changed passwd"
if [ $?=1 ]
then
echo $HOST >>/tmp/host.not
fi
done
I appreciate your help!
Laura
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 07:19 AM
02-04-2004 07:19 AM
Re: scripting problem for repeat lines
$?=1 make sure there are spaces between $? and 1
[ $? = 1 ]
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2004 03:10 PM
02-04-2004 03:10 PM
Re: scripting problem for repeat lines
grep -Fv "$(grep -v logged test.txt | cut -f1 -d,)" test.txt
It assumes your results are in test.txt.
This returns "xxx.xxx.xxx.23, logged in."
If you just want the IP address, tack on another " | cut -f1 -d," at the end and you'll get "xxx.xxx.xxx.23"
Regards,
Seth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2004 02:55 AM
02-05-2004 02:55 AM
Re: scripting problem for repeat lines
grep -Fv "$(grep changed test.txt | cut -f1 -d,)" test.txt
Regards,
Seth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 03:05 AM
02-06-2004 03:05 AM
Re: scripting problem for repeat lines
xxx.xxx.xxx.2, logged in.
xxx.xxx.xxx.2, changed passwd.
xxx.xxx.xxx.20, logged in.
xxx.xxx.xxx.20, changed passwd.
xxx.xxx.xxx.21, logged in.
xxx.xxx.xxx.21, changed passwd.
xxx.xxx.xxx.22, logged in.
xxx.xxx.xxx.22, changed passwd.
xxx.xxx.xxx.23, logged in.
xxx.xxx.xxx.24, logged in.
xxx.xxx.xxx.24, changed passwd.
Here is an awk one-liner that uses exact comparisons. It won't have the subset pattern problem.
awk -F, '/logged in/{l[$1]=1}/changed/{delete l[$1]}END{for(i in l){print i}}' test.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 03:20 AM
02-06-2004 03:20 AM
Re: scripting problem for repeat lines
Mike is absolutely correct. My stupid brain didn't think beyond your example. I guess you already thought of it by using the , in your script.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 03:41 AM
02-06-2004 03:41 AM
Re: scripting problem for repeat lines
The only way my command will work properly is if there is a comma in the file and it's part of the search. So, the command would be:
grep -Fv "$(grep changed test.txt | cut -f1 -d' ')" test.txt
That way the comma is part of the search as well, so "xxx.xxx.xxx.2," won't match "xxx.xxx.xxx.222,", etc.
Thanks for pointing that out, Mike. Hehe, I guess I was too happy with myself to notice that being a problem.
Regards,
Seth