Help migrating bash script to AIX machine


 
Thread Tools Search this Thread
Operating Systems AIX Help migrating bash script to AIX machine
# 1  
Old 03-28-2012
Help migrating bash script to AIX machine

hey frnds I am trying to migrate a bash script over the AIX machine , but was getting error with ps and read commands, so I make the few changes in script and have also chnaged the shell from bash to ksh [changes I made can be noticed in comments]

below is my script
-------------------------------------------------------------------------

Code:
#!/bin/ksh
DATA_DIR=/usr/apps/
CONTAINER=PROD

#ps -eflw --cols 2048 | grep startcontainer | grep -v grep | grep $CONTAINER$ | grep $DATA_DIR | while read -e line
ps -efl | grep startcontainer | grep -v grep | grep $CONTAINER$ | grep $DATA_DIR | while read -u line
do
#columns=( `echo $line` )
set -A columns $line
columnCount=${#columns[@]}
index=0

pid=${columns[3]}
echo $pid
#cmd=${columns[@]:15:$columnCount}
workingDir=${columns[$columnCount-1]}
container=${workingDir##*/}
installDir=`expr match $workingDir '.*/\([^/]*\)/[^/]*$'`

#echo Working Directory=$workingDir
#echo Container Name=$container
#echo Install Directory=$installDir

echo Found running container "$container" installed in "$installDir"

#ps -eflw --cols 2048 | grep $pid | grep -v startcontainer | grep -v grep | while read -e ctr
ps -efl | grep $pid | grep -v startcontainer | grep -v grep | while read -u ctr
do
#ctrCols=( `echo $ctr` )
set -A ctrCols $ctr
ctrColsCount=${#ctrCols[@]}

#ctrPid=${ctrCols[3]}
ctrPid=${ctrCols[4]}
#ctrCmd=${ctrCols[@]:15:$ctrColsCount}

#echo Child Process ID=$ctrPid
#echo Child Command=$ctrCmd

echo Stopping Process ID $ctrPid
kill $ctrPid
done

done

--------------------------------------------------------------

but now this script is not working as expected on AIX machine...it just get out without any response after run...and the process which I want to kill is seems running without any effect.

Please me in this problem......

Code:
running script wth -x trace options shows below result

+ DATA_DIR=/usr/apps/
+ CONTAINER=PROD
+ ps -efl
+ grep startcontainer
+ grep -v grep
+ grep PROD$
+ grep /usr/apps/
+ read -u line


Last edited by methyl; 03-28-2012 at 05:10 PM.. Reason: please use code tags
# 2  
Old 03-28-2012
Quote:
while read -u line
Lose the "-u" - ksh is trying to read from a file descriptor.
Code:
while read line


In anticipation of the next question, please post the output from:
Code:
ps -efl | grep "startcontainer"
# or if that gives syntax errors,
ps -ef | grep "startcontainer"


Please also post the exact version of AIX. There is much variation.
# 3  
Old 03-28-2012
read -u reads from a FD in BASH too, so I have my doubts that this script ever worked.

You can also lose the "grep -v grep" by making the first pattern not match itself.

Code:
 ... | grep '[s]tartcontainer' | ...

# 4  
Old 03-28-2012
@Corona688
Any idea what read -e was for ? (See the commented out line).
# 5  
Old 03-28-2012
I suspect someone was just using -e habitually since it's a complete no-op here -- it only works for terminals. It enables things like command-history for that particular read instance.
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 03-29-2012
On the Bash screen I was using commnented line code i.e
read -e line

here -e option is use to get the input from the terminal.

---------- Post updated at 12:28 PM ---------- Previous update was at 12:25 PM ----------

I was using read -e in the bash format becuase I was trying to read the output of ps -eflw from the terminal to any array
later from that array I was trying to get column [3] value that is PID value
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Upgrading to AIX 7 vs migrating

Hi all, I have this weird notion that upgrading the TL does not cause the machine to wipe, but upgrading a major version (from aix 6 to 7) means it's actually a fresh install and will wipe the date and i have to install the software again (TSM server, for instance). Trying to google it, i came... (3 Replies)
Discussion started by: tde3000
3 Replies

2. Red Hat

Migrating users from old machine to new machine

What is the best way to move all user, with permission etc... from a old linux redhat 5 to a new redhat 6 machine. It is as simple as coping the etc/passwd file etc.. ? (4 Replies)
Discussion started by: da2013
4 Replies

3. AIX

Migrating from HP Unix to IBM AIX 6.1

HI , We are in process to migrate from UNIX to AIX 6.1 version . I need to understand differences between commands that are used in UNIX and AIX. I want to make sure AIX has all command options avaliable from HP Unix.If any mismatch it should be addressed . Since many commands are used it... (2 Replies)
Discussion started by: Perlbaby
2 Replies

4. AIX

Migrating a NIM Server to AIX 6.1

Guys, We are planning to upgrade one of our NIM server to AIX 6.1 from 5.3... Since the server itself is a NIM Server we can't perform it via NIM & I'm choosing to do CD install.. The Install method would be Upgrade installation. Is there anything special that I need to consider before... (5 Replies)
Discussion started by: kkeng808
5 Replies

5. AIX

AIX Servers Ugrading or Migrating

:( Hi Grue, I am very new in AIX/UNIX environment. Please give me answer that during the upgrading or Migrating to 6.1 the AIX Server the applications of this server is accessible to Apps users or not? Thanks (2 Replies)
Discussion started by: Tahniet
2 Replies

6. AIX

Migrating C Application from AIX to Linux

Hi All, I am currently facing new problem of migrating C(c language) application from AIX machine to Linux machine. We are using GCC to compile the source code.. But facing with the compilation issues, with lot of GCC C libs differing between AIX box to Linux box... Pls help me... (3 Replies)
Discussion started by: karthikc
3 Replies

7. AIX

migrating easytrieve from Z/OS to AIX platform

Hi, my requirement is to migrate easytrieve running on Z/OS to AIX platform. can anyone let me know what changes should be made if we do such a migration. (0 Replies)
Discussion started by: rohit510
0 Replies

8. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

9. AIX

Migrating AIX users to Linux

Hi all, I was wondering if anyone out there knew if it was possible to migrate users from AIX to Linux. What we want to do is install OpenLDAP on a Linux machine and port all the users over to LDAP. I've googled around and could only find a few things, such as mrgpwd - but that only comes... (0 Replies)
Discussion started by: djcronos
0 Replies

10. AIX

Problem with migrating from AIX 5.1 to 5.3

I'am migrating from AIX 5.1 to 5.3 during migration installation a receive message enough space for dir /usr. My question is : how i can resolve this problem ? i can't reboot my server i hope that there is a command to obtain a spece without go out from installation procedure pannel... I'am... (0 Replies)
Discussion started by: tt155
0 Replies
Login or Register to Ask a Question