LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-19-2003, 11:30 AM   #1
XtremeDawg
LQ Newbie
 
Registered: Sep 2003
Posts: 20

Rep: Reputation: 0
This is an AIX scripting question but I'm hoping somene can help


We have a script that has the following lines:

case $1 in
t | "") grep LINE= */.profile|
awk -F"/|=| " '{printf "%.3s \t %s \n",$3,$1}'|
sort | more
exit 0 ;;


The grep portion pulls the following from a file:

EXAMPLE 1

felicia/.profile: then LINE=113; export LINE # TERMINAL_NUMBER set by

EXAMPLE 2

butch/.profile:LINE=47;export LINE

The output it gives looks like this:

felicia
47; butch

We want it to look like the second line of the output for all. WE think the problem is in the awk command but don't know how or if we can fix this.

Anyone that can help?
 
Old 12-19-2003, 12:58 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
It looks like felicia's LINE assignment is in an if/then statement. You can either change the if/then or the script.
Code:
OLD:
if [ whatever ]
then LINE=45; export LINE
fi

NEW:
if [ whatever ]; then
LINE=45; export LINE
fi
Or change the script. This one below can handle both cases. I usually don't mess with awk given it's complexity and I can never remember everything. Here I use cut.
Code:
#!/bin/ksh

HOMEDIR=/home

searchProfile()
{
   for i in `ls -l $HOMEDIR | grep ^d | awk ' { print $9 } '`; do
      PROFILE="$HOMEDIR/$i/.profile"
      if [ -x $PROFILE ]; then 
         ALL_LINE=`cat $PROFILE | grep "LINE="`
         if [ $? -ne 0 ]; then
            echo "No LINE for user $i"
         else
            NUM=`echo $ALL_LINE | cut -d '=' -f2 | cut -d ' ' -f1`
            echo "$NUM $i" 
         fi
      else
         echo "No profile exists for $i"
      fi
   done
}

case $1 in
   t | "") searchProfile;;

esac
 
Old 12-19-2003, 01:59 PM   #3
XtremeDawg
LQ Newbie
 
Registered: Sep 2003
Posts: 20

Original Poster
Rep: Reputation: 0
Perhaps I should have explain what we are tring to do. We have 100 plus users in AIX and there are times when we need to know if a line # has been used. The script gives us a list of users with their line # based on what is in their .profile.

So changing the .profile is not something we want to do but having a script to list this in a nice neat way is. This script was written a while back by someone esle and I am just not understanding why it won't list all the same.

I doubt it will ever work like we want without changing the .profile though.
 
Old 12-19-2003, 02:20 PM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
The script I posted does not suffice? It looks, from your requirements, like it should.

Gary
 
Old 12-19-2003, 03:10 PM   #5
XtremeDawg
LQ Newbie
 
Registered: Sep 2003
Posts: 20

Original Poster
Rep: Reputation: 0
I'll try it.
 
Old 12-19-2003, 03:36 PM   #6
XtremeDawg
LQ Newbie
 
Registered: Sep 2003
Posts: 20

Original Poster
Rep: Reputation: 0
Based on what I could tell the HOMEDIR=/home should be pointing to where the .profile files are in your script. Each user has their .profile in a subdirectory of /home/udd.

Example for Sonny the path would be /home/udd/sonny/.profile

Any way to work around that because I am getting

No profile exists for sonny

as the output if I change the HOMEDIR=/home/udd. If I leave it as HOMEDIR=/home I get a listing for all of my directories under the /home directory. I tried this with HOMEDIR=/home/udd/Sonny and it returned no output.
 
Old 12-19-2003, 03:49 PM   #7
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
It should work if you make HOMEDIR=/home/udd.

If not, try to put an 'echo $PROFILE' under the PROFILE= in the script. This will echo the location it is checking for the .profile file.

I tried a quick test with HOMEDIR=/home/udd and the file in /home/udd/user/.profile and the script still worked.
 
Old 12-19-2003, 03:56 PM   #8
XtremeDawg
LQ Newbie
 
Registered: Sep 2003
Posts: 20

Original Poster
Rep: Reputation: 0
So should it now look like this?

#!/bin/ksh

HOMEDIR=/home/udd

searchProfile()
{
for i in `ls -l $HOMEDIR | grep ^d | awk ' { print $9 } '`; do
PROFILE="$HOMEDIR/$i/.profile"
echo $PROFILE
if [ -x $PROFILE ]; then
ALL_LINE=`cat $PROFILE | grep "LINE="`
if [ $? -ne 0 ]; then
echo "No LINE for user $i"
else
NUM=`echo $ALL_LINE | cut -d '=' -f2 | cut -d ' ' -f1`
echo "$NUM $i"
fi
else
echo "No profile exists for $i"
fi
done
}
 
Old 12-19-2003, 03:57 PM   #9
XtremeDawg
LQ Newbie
 
Registered: Sep 2003
Posts: 20

Original Poster
Rep: Reputation: 0
If so then it is not working because this is the output I am getting now.

/home/udd/sonnyb/.profile
No profile exists for sonnyb
 
Old 12-19-2003, 04:00 PM   #10
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Sorry, my bad. Change the -x to a -f in the test.

-x tests to see if it is executable.
-f tests if it exists.
 
Old 12-19-2003, 04:04 PM   #11
XtremeDawg
LQ Newbie
 
Registered: Sep 2003
Posts: 20

Original Poster
Rep: Reputation: 0
Ok that works well. One last thing. Is there any QUICK way to have it ONLY list the

33;export trent

and not

/home/udd/trent/.profile

It list both now like the following

/home/udd/trent/.profile
33;export trent

I would like it neater but if not this is still good and will work.

Thanks!!
 
Old 12-19-2003, 04:24 PM   #12
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Yes, remove the echo you added below PROFILE=
 
Old 12-22-2003, 02:45 PM   #13
XtremeDawg
LQ Newbie
 
Registered: Sep 2003
Posts: 20

Original Poster
Rep: Reputation: 0
Talking

THANKS!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hoping this is a stupid video question kylere Linux - Newbie 2 07-28-2005 01:00 PM
RHL 7.2 with XP question(from an AIX admin) traindo1 Linux - Newbie 1 05-03-2005 10:30 AM
Case Statement With Aix Ksh Scripting ']['HeBroken AIX 2 02-09-2005 12:44 PM
yet somene else with wma problems.... beewhy Linux - Software 9 09-02-2004 06:48 PM
aix fortran question zepplin611 AIX 5 02-04-2004 03:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration