This is an AIX scripting question but I'm hoping somene can help
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.