LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 06-19-2015, 11:03 AM   #1
Cpare
Member
 
Registered: Aug 2001
Location: Magic City, USA
Distribution: Ubuntu
Posts: 73

Rep: Reputation: 15
AIX Shell Script Question


The script below is failing with the addition of ${arrUsers[i]} to the echo line, if I change this to ${arrUsers[1]} it works, but I need the variable - I also tried ${arrUsers[$i]} without success. This worked in a prior script I wrote, but it may have been an older version of AIX - is there a new/better approach?

For those that will ask - this tool will search through directories to find content owned by users that are scheduled to have their AIX account removed, chowning the item (directory / folder) to a generic ID and make the file available to all users in a group.

Code:
#!/usr/bin/ksh

set -A arrFolders /dir2 /dir1
set -A arrUsers User1 User2

############################################################################

if [ "$1" = "" ]
then
   echo USAGE:
   echo "   usercleanup.sh OldUser"
else
        # Loop through each RootFolder
        for i in ${arrFolders[@]}
        do
                echo "Searching $i for $1 and chowning to ${arrUsers[i]}"
                #find . -user $1 \( -exec echo {} \; -o -exec true \; \) -exec grep banana {} \;
                #find $i -user $1 -exec chown ${arrUsers[i]} {} \; -exec chmod 766{} \;

        done
fi

Last edited by Cpare; 06-19-2015 at 11:07 AM.
 
Old 06-19-2015, 12:38 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Here is a little example that might help:
Code:
#!/bin/ksh

set -A arrFolders /dir2 /dir1
set -A arrUsers User1 User2

N="${#arrFolders[@]}"
MAX=$(expr $N - 1)

for i in $(seq 0 $MAX); do
    printf 'd: "%s" vs "%s"\n' "$i" "${arrFolders[$i]}" "${arrUsers[$i]}"
done
 
1 members found this post helpful.
Old 06-22-2015, 07:29 AM   #3
Cpare
Member
 
Registered: Aug 2001
Location: Magic City, USA
Distribution: Ubuntu
Posts: 73

Original Poster
Rep: Reputation: 15
@NevemTeve - thanks for the assist, it's exactly what I needed - arrFolders wasn't an INT that could be used to locate the member in the other array, but the value of the array item (which explains why the echo line was showing the name). I used your approach and got the number of array values, then looped through them.
 
Old 06-25-2015, 01:02 PM   #4
bombino1
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Rep: Reputation: Disabled
This is a script that I am trying to use to monitor CPU and memory utilization in my server.

#!/bin/ksh

# --- Environment --- #
SERVER=$(uname -n)
MAILTO=[AIXMonitoringReports@ferc.gov]

# --- High Water Marks --- #
typeset -i CPUHWM=60
typeset -i PAGHWM=60
typeset -i TMHWM=60

# --- Vars --- #
typeset -i CPU PAG TM


CPU=$(vmstat 1 1 | tail -1 | awk '{print $14+$15}')
[ $CPU -gt $CPUHWM ] && echo "CPU exceeded $CPU us+sy percent on $SERVER" | mailx -s "CPU alert for $SERVER (${CPU})" $MAILTO

PAG=$(vmstat 1 1 | tail -1 | awk '{print $6+$7}')
[ $PAG -gt $PAGHWM ] && echo "PAGING exceeded $PAG pi+po pages on $SERVER" | mailx -s "Paging alert for $SERVER (${PAG}/s)" $MAILTO

for DISK in $(lspv | awk '{print $1}')
do
TM=$(iostat -d $DISK 1 1 | grep hdisk | awk '{print $2}')
[ $TM -gt $TMHWM ] && echo "Disk $DISK exceeded ${TM}% tm_act on $SERVER" | mailx -s "DiskIO alert for $SERVER ($DISK ${TM}%)" $MAILTO
done

exit
 
Old 06-25-2015, 01:03 PM   #5
bombino1
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Rep: Reputation: Disabled
But i am receiving the following error:

Syntax Error The source line is 1.
The error context is
{print >>> $2 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-540 There is a missing } character.
Syntax Error The source line is 1.
The error context is
{print >>> $2 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-540 There is a missing } character.
Syntax Error The source line is 1.
The error context is
{print >>> $2 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-540 There is a missing } character.
Syntax Error The source line is 1.
The error context is
{print >>> $2 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-540 There is a missing } character.
Syntax Error The source line is 1.
The error context is
{print >>> $2 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-540 There is a missing } character.
Syntax Error The source line is 1.
The error context is
{print >>> $2 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-540 There is a missing } character.
Syntax Error The source line is 1.
The error context is
{print >>> $2 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-540 There is a missing } character.
 
Old 06-25-2015, 01:34 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
I fail to see how it is related to the topic, but if it is, please use [code] and [/code] tags when you paste code. Also paste the actual code, not only the error message.
 
  


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
aix shell script to convert 5 csv files to single excelsheet rajachan Programming 3 02-27-2013 08:39 PM
AIX Shell script rajachan AIX 2 01-18-2013 08:06 AM
AIX shell script to get Hostname from Machine and linux098 Linux - Newbie 4 10-12-2012 09:21 AM
Remote Win Bat File execute Shell Script on AIX Server DriveMeCrazy AIX 5 05-26-2004 06:24 PM

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

All times are GMT -5. The time now is 03:14 PM.

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