- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script from scratch with problems
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-06-2004 04:17 AM
02-06-2004 04:17 AM
I have a IP file
server@ ~/scripts$ more sw_ip.txt |sort
142.160.179.200
123.456.101.20
123.456.102.20
123.456.102.21
123.456.103.20
123.456.104.20
123.456.105.20
123.456.106.20
123.456.109.20
123.456.113.20
I need to run a for loop that takes that IP and then greps a file, that was created from an expect script that logs into a machine and changes passwd. The reason I am doing it this way instead of what was in my question before of, awk the created file sort| uniq, then grep for ip. Is that I now for sure these are the IP that I HAVE to have checked. The created script may not have all logged IP's in it for what ever reason. So if it is missing, the grep will still output that IP as not having "changed passwd"
Now here is the problem...
I have attached my script with comments, but is in short words...
for D_IP in $(awk '{print $1}' sw_ip.txt |sort
do
echo $D_IP
LOGIN=/tmp/login.txt
grep $D_IP $LOGIN |grep -q "changed passwd"
if [ $?! = 0 ]
then echo "$D_IP 'grep'"echo $D_IP >>/tmp/host.not
fi
done
Does not work.
The grep returns a value of 1 but for each line in the login.txt AND NOTHING IN MY HOST.NOT FILE!
This is my login.txt parred down..
123.456.101.20 changed passwd.
123.456.101.20 logged in.
123.456.102.20 changed passwd.
123.456.102.20 logged in.
123.456.102.21 changed passwd.
123.456.102.21 logged in.
123.456.103.20 changed passwd.
123.456.103.20 logged in.
123.456.104.20 changed passwd.
123.456.104.20 logged in.
123.456.105.20 logged in.
123.456.106.20 logged in.
123.456.109.20 logged in.
I should only be getting 3 lines retured in the host.not file
Right now I get nothing!
I really appreciate all the help that was given before, and have filed that for furture use. But, I have been working on this for a day in a half.
Laura
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 04:22 AM
02-06-2004 04:22 AM
Re: script from scratch with problems
What three lines are you expecting to get back ?
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 04:25 AM
02-06-2004 04:25 AM
Re: script from scratch with problems
So I should get
123.456.105.20
123.456.106.20
123.456.109.20
Or as you see in my login.txt file the bottom 3 IP'S.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 04:31 AM
02-06-2004 04:31 AM
SolutionI always use rcs to keep track of my versions. Atleast you can save the script as script.1, script.2 etc., whenver you make changes.
The problem is if [ $?! = 0 ]. This should be $? != 0. First like should have closed ")".
This time instead of correcting your script, I will try to put down what I wrote. Replace IPLISt and LOG to wherever they are.
IPLIST=sw_ip.txt
LOGIN=login.txt
RESULT=host.not
for IP in $(cat $IPLIST)
do
grep -q -x "$IP changed passwd." $LOGIN
if [ $? != 0 ]
then
echo $IP >> $RESULT
fi
done
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 05:24 AM
02-06-2004 05:24 AM
Re: script from scratch with problems
[ $? [space] != 0 ]
But, I am still haveing a problem, it still out puts the whole list.
I even checked for hidden characters in my $LOGIN_ENTRY_FILE_4 and in my $IPLIST, nothing but the return character at the end.
Even if I grep without the -x still same problem!
This is my $LOGIN_ENTRY_FILE_4
123.456.101.20, logged in.
123.456.101.20, changed passwd.
123.456.102.20, logged in.
123.456.102.20, changed passwd.
123.456.102.21, logged in.
123.456.102.21, changed passwd.
123.456.103.20, logged in.
123.456.104.20, logged in.
123.456.104.20, changed passwd.
123.456.105.20, logged in.
123.456.105.20, changed passwd.
My host.not file still outputs all of the IPs
rm /tmp/host.not
IPLIST=$SCRIPTS_DIR/sw_ip.txt
for IP in `cat $IPLIST`
do
echo $IP
grep -q -x "$IP, changed passwd." $LOGIN_ENTRY_FILE_4
if [ $? != 0 ]
then
echo $IP >>/tmp/host.not
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 05:36 AM
02-06-2004 05:36 AM
Re: script from scratch with problems
touch .use1 .use2
rm .use1 .use2
awk '{print "grep ",$1,"login.txt >> .use2"}' < sw_ip.txt > .use1
chmod 755 .use1
./.use1
awk 'BEGIN{useip=0;} /changed passwd/ {useip=$1;next} /logged in/ {if (useip!=$1
) {print $0};useip=0;}' .use2
Explanation:
touch touchs the files we'll use and then rms them on the next line (so we can use >> without picking up old data).
first awk creates the greps instead of doing it inline.
chmod makes the script executable
./.use1 creates ./.use2
then the last awk script sets the useip value when it finds a "changed passwd" line.
If it finds a logged in line that doesnt have a matching "changed passwd" line then it prints it.
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 05:47 AM
02-06-2004 05:47 AM
Re: script from scratch with problems
$cat sw_ip.txt
142.160.179.200
123.456.101.20
123.456.102.20
123.456.102.21
123.456.103.20
123.456.104.20
123.456.105.20
123.456.106.20
123.456.109.20
123.456.113.20
123.456.104.2
$cat login_txt
123.456.101.20, logged in.
123.456.101.20, changed passwd.
123.456.102.20, logged in.
123.456.102.20, changed passwd.
123.456.102.21, logged in.
123.456.102.21, changed passwd.
123.456.103.20, logged in.
123.456.104.20, logged in.
123.456.104.20, changed passwd.
123.456.105.20, logged in.
123.456.105.20, changed passwd.
$cat scr
IPLIST=sw_ip.txt
LOGIN=login.txt
for IP in $(cat $IPLIST)
do
grep "${IP}," $LOGIN |grep -q "changed passwd."
if [ $? != 0 ]
then
echo $IP >> host.not
fi
done
$./scr
$cat host.not
142.160.179.200
123.456.103.20
123.456.106.20
123.456.109.20
123.456.113.20
123.456.104.2
Also, unless we see the actual files, it's difficult to carve a 100% solution for you. Please attach them instead of posting them.
-Sri
PS: Please do not assign points until your problem is completely solved atleast to me. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 05:50 AM
02-06-2004 05:50 AM
Re: script from scratch with problems
echo "${IP}, changed passwd."
I get
, changed passwd.
I do not get the IP, so I am having problems with that variable!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 05:53 AM
02-06-2004 05:53 AM
Re: script from scratch with problems
IPLIST=$SCRIPTS_DIR/sw_ip.txt
for IP in $(cat $IPLIST)
do
echo ${IP}
done
Did you have your SCRIPTS_DIR defined properly?.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 06:30 AM
02-06-2004 06:30 AM
Re: script from scratch with problems
rm /tmp/host.not
IPLIST=$SCRIPTS_DIR/sw_ip.txt
for IP in `cat $IPLIST`
do
echo $IP
echo "${IP}, changed passwd."
grep -q -x "$IP, changed passwd." $LOGIN_ENTRY_FILE_4
if [ $? != 0 ]
then
echo $IP >>/tmp/host.not
fi
done
This is my output...
123.456.101.20
, changed passwd.
123.456.102.20
, changed passwd.
123.456.102.21
, changed passwd.
123.456.103.20
, changed passwd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 06:54 AM
02-06-2004 06:54 AM
Re: script from scratch with problems
IPLIST=/the/correct/path/sw_ip.txt
for IP in $(cat $IPLIST)
do
echo $IP
echo $IP
echo "$IP"
echo "$IP, changed passwd."
echo "$IP changed passwd."
echo $IP", changed passwd."
done
Output (parred down)
123.456.80.48
123.456.80.48
123.456.80.48
, changed passwd.
changed passwd.
, changed passwd.
123.456.35.48
123.456.35.48
123.456.35.48
, changed passwd.
changed passwd.
, changed passwd.
123.456.20.50
123.456.20.50
123.456.20.50
, changed passwd.
changed passwd.
, changed passwd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 07:01 AM
02-06-2004 07:01 AM
Re: script from scratch with problems
IPLIST=/the/correct/path/sw_ip.txt
for IP in $(cat $IPLIST)
do
echo $IP
echo $IP
echo "$IP"
echo $IP ","
echo "$IP ,"
echo "$IP, changed passwd."
echo "$IP changed passwd."
echo $IP", changed passwd."
done
Output:
123.456.20.50
123.456.20.50
123.456.20.50
,3.17.20.50
,3.17.20.50
, changed passwd.
changed passwd.
, changed passwd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 07:37 AM
02-06-2004 07:37 AM
Re: script from scratch with problems
The last thing you did, gives me this:
123.456.101.20
123.456.101.20
123.456.101.20
123.456.101.20 ,
123.456.101.20 ,
123.456.101.20, changed passwd.
123.456.101.20 changed passwd.
123.456.101.20, changed passwd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 09:30 AM
02-06-2004 09:30 AM
Re: script from scratch with problems
there is one more problem:
$? != 0
two errors, $? is numeric and grep returns 0 when it finds something so it must be:
$? -eq 0
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2004 11:08 AM
02-07-2004 11:08 AM
Re: script from scratch with problems
Thanks everyone for there help!