Sponsored Content
Operating Systems AIX pgrep substitute for porting a linux script to AIX 5.x Post 302133381 by thebytegrill on Thursday 23rd of August 2007 06:50:09 AM
Old 08-23-2007
Smilie hi and thanks for that, it worked perfectly.
I have another question, can I get ps out put with --no-header option, I couldn't find it in the man pages, I'm doing this script for AIX 5.2 and 5.3
Thanks for the help.
Below is the script as its coming along.#!/bin/bash
# author siddharth.mody@gmail.com
#echo "===============START==============="
ROOT_UID=0 # only users with $UID 0 have root privilages.
E_NOROOT=67 # Non-root exit error.
BACKUPDATE=$(date +%m.%d.%Y-%H\:%M\:%S)","
FILENAME=$1-${BACKUPDATE}".csv"

#check if root user.
# Run as root:
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script"
exit $E_NOTROOT
fi

IsNumeric () {
case "${1}" in
*[!0-9,]*) return 1;; # invalid
*) return 0;; # valid
esac
}

strcmp ()# string == string
{
local _STRING1=$1 _STRING2=$2 _a _b
case $#.$3 in
2.) ;;
3.*:*) _a=${3%:*} _b=${3#*:}
set -- `python_to_shell_range "$_a" "$_b" ${#_STRING1}`
_STRING1=${_STRING1:$1:$2}
set -- `python_to_shell_range "$_a" "$_b" ${#_STRING2}`
_STRING2=${_STRING2:$1:$2}
;;
*) echo "Usage: strcmp string1 string2 [a:b]"
return 2
;;
esac
[ "$_STRING1" == "$_STRING2" ]
}
#initialize
cd /scripts
pid='pid'
pName='pName'

tokens=''

# get pairs of PID and processNames per line

# FOR EACH PROCESS TO BE WATCHED
# PROCESS A:

for procName in proc1 proc1
do
R=$(ps -ef | grep $procName | awk '{print $2} {print $8}')
tokens=$tokens' '$R
done




echo $tokens

echo +++++++++++++++++++++++++++++++++++++++++++++

read -r -a tokenArray <<< $tokens

# Seperate PID and pNames in tokens array.
for token in "${tokenArray[@]}"
do
# PID
if IsNumeric "$token"; then
pid=${token}
else
# PROCESS NAME
pName=$(ps --no-header --pid "${pid}" -o comm)
# LIVE DATA COLLECTION [START]
# METATAGS given: pid, pName
# ___CPU___
#echo "Collecting CPU related data for '"${pName}"'."
header_cpu='CPU_usage(%)'
data_cpu=$(ps -p ${pid} -o pcpu)
#___MEMORY___
#echo "Collecting MEMORY related data for '"${pName}"'."
header_memory='PhysicalMemory(%)'
# data_memory=$(ps --no-header --pid ${pid} -o pmem=PhysicalMemory\(\%\),sz=CoreImageSize,vsz=VirtualMemory,rss=ResidentSetSize,resident=ResidentPa ges,size=RequiredSize,share=Shared)
mt_memory_pmem=$(ps -p ${pid} -o pmem)
data_memory=${mt_memory_pmem}

# TTY output:
echo "${pName}"
# DATA LOGGING CODE [START]
mainHeader="DateAndTimeOfReading,"${header_cpu}","${header_memory}
logData=${data_cpu}","${data_memory}
# Create and inject header into file if it does not exist
if [ -f ${pName}"_"${pid}"_"${1}".csv" ]
then
:
# echo ${pName}"_"${pid}"_"${1}".csv :File already exists"
else
# echo "FileDoesNotExist: Updating header..."
echo "Memory Statistics for user: "${1} >> ${pName}"_"${pid}"_"${1}".csv"
echo "["$(uname -a)"]" >> ${pName}"_"${pid}"_"${1}".csv"
echo "${mainHeader}" >> ${pName}"_"${pid}"_"${1}".csv"
fi
# get memInfo
memInfo=${data_cpu}" "${data_memory}" "${data_time}" "${data_command}
# write timestamp with memInfo
echo ${BACKUPDATE}" ""${logData}" >> ${pName}"_"${pid}"_"${1}".csv"
#===============end=logging===============
fi
done
exit 0

 

9 More Discussions You Might Find Interesting

1. AIX

Porting C codes from HP-UX to AIX

Hi , Can someone help me get some support documents on the common issues/pitfalls and any other details with respect to porting the application running on C codes from HP-UX to AIX. Help will be valuable. Thanks a lot (0 Replies)
Discussion started by: Sinbad
0 Replies

2. Programming

Porting of Shell to AIX

Hi All, I would like to know of the steps needed for the implementation of a shell in AIX. This shell is written by one of our developers and is currently running in Solaris. This needs to be ported to AIX. Does any of you guys know the implementation steps to do this. If so please do let me... (5 Replies)
Discussion started by: dhanamurthy
5 Replies

3. UNIX for Advanced & Expert Users

Porting GNU FTPD daemon from Linux to AIX

Dear All, I want to port GNU ftpd daemon server from Linux to AIX. I want to download GNU ftpd daemon for linux. Please tell me from where I can download this code and which code will be most suitable for this porting? Please help in this regard. Thanks Siva (0 Replies)
Discussion started by: srksn
0 Replies

4. UNIX for Advanced & Expert Users

Porting linux ftpd code to Aix

Dear All, I have already ported the linux ftpd daemon to AIX earlier. When the ftp client does a "DIR" command, I have intercepted the call to the remote machine at the server code and added my code to browse IBM Message Queue, so that the client will see the files in the IBM Message... (2 Replies)
Discussion started by: srksn
2 Replies

5. AIX

Porting to AIX from Sun Solaris

Hi, When we tried to port our Pro*C programs from sun solaris to AIX, We get following error messages: The following library is not available... This library file is required for Pro*C Object Linking and Bin creation. /usr/lib/libnsl.so.1. Can anybody help us on this ? Regards rbs100 (1 Reply)
Discussion started by: rbs100
1 Replies

6. Shell Programming and Scripting

porting shell script from Linux to AIX.

Hi, I am porting one shell script from Linux to AIX. I had .ksh file and i have changed it to .sh file for aix. on linux this script is running fine but on aix it gives me "unexpected end of file" error. Could any one suggest me what to do to port this script error free? Thanks in... (6 Replies)
Discussion started by: joy_1
6 Replies

7. AIX

porting an application on 64-bit AIX version 5

Hi all, I am facing problem in porting to 64 bit AIX especially with compiling options to compile and run under 64 bit kernel.Can any one put some light on the issue thanks in advance vishal (14 Replies)
Discussion started by: vishalzone2002
14 Replies

8. AIX

Porting from HP-UX to AIX

I am orignally a VC++ programmer, this is the my post in UNIX form. I have an existing source code, that was developed in old HP-UX system, the objective is to make it work on new AIX system. It does'nt appear that AIX has the necessary libraries or even run the application if its... (0 Replies)
Discussion started by: maverick786us
0 Replies

9. Shell Programming and Scripting

Porting script from Solaris to Linux

I have a script which has commands that are located in different paths on my Linux o/s than on Solaris. For example, to make uname work, I need to do it this way in Solaris: my $host= `/usr/bin/uname -n` But in Linux it is: my $host = `/bin/uname -n`I have this issue with at least 5... (8 Replies)
Discussion started by: newbie2010
8 Replies
All times are GMT -4. The time now is 06:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy