LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices


Reply
  Search this Thread
Old 08-13-2019, 01:32 PM   #1
unix1adm
Member
 
Registered: Oct 2008
Posts: 688

Rep: Reputation: 32
building an array in sh on AIX


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.
 
Old 08-13-2019, 01:51 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,723

Rep: Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748
Quote:
Originally Posted by unix1adm View Post
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.
 
Old 08-13-2019, 02:22 PM   #3
unix1adm
Member
 
Registered: Oct 2008
Posts: 688

Original Poster
Rep: Reputation: 32
Sorry this is the whole script. I only forgot the #/bin/sh line.

#!/bin/sh
 
Old 08-13-2019, 02:44 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,723

Rep: Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748Reputation: 5748
Follow up in your DUPLICATE thread, thanks.
 
Old 08-13-2019, 02:53 PM   #5
unix1adm
Member
 
Registered: Oct 2008
Posts: 688

Original Poster
Rep: Reputation: 32
I sincerely apologizes for ruining your day and raising your blood pressure by my fopar in posting to this site wrongly.

Thank for your time.
 
Old 08-13-2019, 03:50 PM   #6
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,486

Rep: Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168
Your dup thread got closed. Please respond here to the questions I asked there...
 
Old 08-14-2019, 01:19 PM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,155

Rep: Reputation: 526Reputation: 526Reputation: 526Reputation: 526Reputation: 526Reputation: 526
The script needs bash. It only works with /bin/sh if /bin/sh is a link to bash.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
BASH-Adding array element: Naming issue using array[${#array[*]}]=5 calvarado777 Programming 8 07-26-2013 09:48 PM
Aix 5 Aix 5l ?! jamesps AIX 3 01-21-2005 11:55 AM
System hangs in update of AIX from 4.3.3 to AIX 5.2 jmurray67 AIX 2 07-25-2004 08:25 PM

LinuxQuestions.org > Forums > Other *NIX Forums > AIX

All times are GMT -5. The time now is 08:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration