AIXThis forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.
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.
I have a script that works fin in Linux Specifically Red hat.
However when i go to run it in AIX it gets an error
Not sure if this is an active forum or the correct place to put this question.
Any help is appreciated.
# Retrieve and format the system date/time appropriately
datetime=$(date "+%D %r")
# Enumerate users and non-empty groups on the system
for username in $(cat /etc/passwd | awk '/^#/{next}1' | cut -d: -f1); do
# Search for users in primary groups and append to array
userprimarygroupid=$(grep ^$username /etc/passwd | awk '/^#/{next}1' | cut -d: -f4)
userprimarygroupname=$(grep ":$userprimarygroupid:" /etc/group | awk '/^#/{next}1' | cut -d: -f1)
outputarr+=( ""$userprimarygroupname"",""$username"",""Local User"",""$datetime"")
# Search for users in secondary groups and append to array
for usersecondarygroupname in $(grep $username /etc/group | cut -d: -f1); do
outputarr+=( ""$usersecondarygroupname"",""$username"",""Local User"",""$datetime"")
done
done
# Write Results to stdout for mgmt systems to retrieve
printf '%s\n' "${outputarr[@]}" | sort -u
---------------------
error
./localgroup.sh[6]: 0403-057 Syntax error at line 10 : `(' is not expected.
I have a script that works fin in Linux Specifically Red hat.
However when i go to run it in AIX it gets an error Not sure if this is an active forum or the correct place to put this question. Any help is appreciated.
Code:
# Retrieve and format the system date/time appropriately
datetime=$(date "+%D %r")
# Enumerate users and non-empty groups on the system
for username in $(cat /etc/passwd | awk '/^#/{next}1' | cut -d: -f1); do
# Search for users in primary groups and append to array
userprimarygroupid=$(grep ^$username /etc/passwd | awk '/^#/{next}1' | cut -d: -f4)
userprimarygroupname=$(grep ":$userprimarygroupid:" /etc/group | awk '/^#/{next}1' | cut -d: -f1)
outputarr+=( ""$userprimarygroupname"",""$username"",""Local User"",""$datetime"")
# Search for users in secondary groups and append to array
for usersecondarygroupname in $(grep $username /etc/group | cut -d: -f1); do
outputarr+=( ""$usersecondarygroupname"",""$username"",""Local User"",""$datetime"")
done
done
# Write Results to stdout for mgmt systems to retrieve
printf '%s\n' "${outputarr[@]}" | sort -u
error
Code:
./localgroup.sh[6]: 0403-057 Syntax error at line 10 : `(' is not expected.
Since you didn't post the whole script, what shell does this run in? Bash? KSH? CSH? ZSH? ASH? Other?? What is on line 10, since it's telling you that's where the syntax error is? Have you tried to step through and run the commands in this script on the command line, to see what results you get? Output from things like the passwd file, grep, and other system-utilities may be different on AIX than they are on Linux. I'd start there.
for username in $(cat /etc/passwd | awk '/^#/{next}1' | cut -d: -f1); do
makes me cringe
you should re-write the whole script
no need to cat , awk will read the file just fine
cut the output of awk?
why not just get awk to process the input correctly?
you should re-write the whole script
no need to cat , awk will read the file just fine
cut the output of awk?
why not just get awk to process the input correctly?
Use a while loop for passwd and awk for group
Code:
while IFS=":" read username pw uid guserprimarygroupid rest
do
case $username in
(#*)
echo "skipping valid! username '$username'"
continue
;;
esac
userprimarygroupname=$(
awk -F":" -v gid="$userprimarygroupid" '$3==gid { print $1; exit }' /etc/group
)
...
done < /etc/passwd
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.