Sponsored Content
Full Discussion: ksh behavior change on RHEL5
Top Forums Shell Programming and Scripting ksh behavior change on RHEL5 Post 302416706 by bwhitehd on Tuesday 27th of April 2010 01:39:40 PM
Old 04-27-2010
Question ksh behavior change on RHEL5

I recently patched a RHEL5 host from 5.2 to 5.5. There are some scripts that simply do a ps and grep to check for itself before proceeding. I personally don't like the way the scripts are written and would have done it differently. Before I can proceed with patching the production servers, I need to determine why the behaviour changed with these scripts. I've provided a sample script that reproduces the issue and output from both the patched system and a none patched system. Running the script manually everything works as expected, but these run through cron and give different output.

A small oddity I just noticed too, when type 'cat /etc/redhat' and hitting tab on the patched system you can see below that it put a '\' before the '-', but on the unpatched system it does not.

Crontab:
Code:
* * * * * /app2/stage/aim/aim_ap_etl/test.ksh > /app2/stage/aim/aim_ap_etl/test.out 2>&1

Script:
Code:
#!/bin/ksh

echo $0
SCRIPT=${0##*/}
echo $SCRIPT
echo "IFS=xx${IFS}xx"
echo "PS=$(which ps)"
echo "GREP=$(which grep)"
echo "PGREP=$(which pgrep)"
echo "WC=$(which wc)"
echo "Running processes: "
/bin/ps -ef | /bin/grep -v grep | /bin/grep $SCRIPT
/bin/ps -ef | /bin/grep -v grep | /bin/grep -c $SCRIPT
/bin/ps -ef | /bin/grep -v grep | /bin/grep $SCRIPT | /usr/bin/wc -l
/usr/bin/pgrep $SCRIPT | /usr/bin/wc -l
echo "-----------"

proc1=`ps -ef | /bin/grep -v grep | /bin/grep -c $SCRIPT`
echo "proc1=$proc1"

proc2=$(ps -ef | /bin/grep -v grep | /bin/grep -c $SCRIPT)
echo "proc2=$proc2"

proc3=$(/usr/bin/pgrep $SCRIPT | /usr/bin/wc -l)
echo "proc3=$proc3"

echo "Exiting!"
exit

Non-patched
Code:
> uname -a
Linux xxx 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15 EDT 2008 x86_64

> cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.2 (Tikanga)

> echo ${.sh.version}
Version M 1993-12-28 r

Manual output with ksh:
Code:
> ./test.ksh
./test.ksh
test.ksh
IFS=xx 
xx
PS=/bin/ps
GREP=/bin/grep
PGREP=/usr/bin/pgrep
WC=/usr/bin/wc
Running processes: 
infa      2365 24775  0 12:28 pts/2    00:00:00 /bin/ksh ./test.ksh
1
1
1
-----------
proc1=1
proc2=1
proc3=1
Exiting!

Manual output with bash:
Code:
> ./test.bash
./test.bash
test.bash
IFS=xx 
xx
PS=/bin/ps
GREP=/bin/grep
PGREP=/usr/bin/pgrep
WC=/usr/bin/wc
Running processes: 
infa      2914 24775  0 12:30 pts/2    00:00:00 /bin/bash ./test.bash
1
1
1
-----------
proc1=2
proc2=2
proc3=2
Exiting!

Crontab output with ksh:
Code:
> cat test.out
/app2/stage/aim/aim_ap_etl/test.ksh
test.ksh
IFS=xx 
xx
PS=/bin/ps
GREP=/bin/grep
PGREP=/usr/bin/pgrep
WC=/usr/bin/wc
Running processes: 
infa      3823  3820  0 12:36 ?        00:00:00 /bin/sh -c /app2/stage/aim/aim_ap_etl/test.ksh > /app2/stage/aim/aim_ap_etl/test.out 2>&1
infa      3824  3823  0 12:36 ?        00:00:00 /bin/ksh /app2/stage/aim/aim_ap_etl/test.ksh
2
2
1
-----------
proc1=2
proc2=2
proc3=1
Exiting!

Patched
Code:
> uname -a
Linux xxx 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

> cat /etc/redhat\-release                                                                               
Red Hat Enterprise Linux Server release 5.5 (Tikanga)

> echo ${.sh.version}
Version AJM 93t+ 2010-02-02

Manual output with ksh:
Code:
> ./test.ksh
./test.ksh
test.ksh
IFS=xx 
xx
PS=/bin/ps
GREP=/bin/grep
PGREP=/usr/bin/pgrep
WC=/usr/bin/wc
Running processes: 
infa      3288 11352  0 12:27 pts/3    00:00:00 /bin/ksh ./test.ksh
1
1
1
-----------
proc1=2
proc2=2
proc3=2
Exiting!

Manual output with bash:
Code:
> ./test.bash
./test.bash
test.bash
IFS=xx 
xx
PS=/bin/ps
GREP=/bin/grep
PGREP=/usr/bin/pgrep
WC=/usr/bin/wc
Running processes: 
infa      3702 11352  0 12:28 pts/3    00:00:00 /bin/bash ./test.bash
1
1
1
-----------
proc1=2
proc2=2
proc3=2
Exiting!

Crontab output with ksh:
Code:
> cat test.out
/app2/stage/aim/aim_ap_etl/test.ksh
test.ksh
IFS=xx 
xx
PS=/bin/ps
GREP=/bin/grep
PGREP=/usr/bin/pgrep
WC=/usr/bin/wc
Running processes: 
infa      3962  3961  0 12:32 ?        00:00:00 /bin/sh -c /app2/stage/aim/aim_ap_etl/test.ksh > /app2/stage/aim/aim_ap_etl/test.out 2>&1
infa      3963  3962  0 12:32 ?        00:00:00 /bin/ksh /app2/stage/aim/aim_ap_etl/test.ksh
2
2
1
-----------
proc1=3
proc2=3
proc3=2
Exiting!

 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh parameter --- change

I am reading a file into a parameter in my program typeset nums_type if the contents of nums_type = asdfghbqwerty how do make a new paremeter eqaul to the 7th character of nums_type. like ${type} = b (2 Replies)
Discussion started by: frank
2 Replies

2. Shell Programming and Scripting

Strange behavior from 'read' statements. (ksh - but could be same on other shells)

I'm getting rather frustrated with an interactive script I'm writing. The script is divided up, with section for setting variable at the top, then functions (which make up most of the script) then basically a line at the end which calls the first function- the program moves between the... (5 Replies)
Discussion started by: alexop
5 Replies

3. UNIX for Dummies Questions & Answers

Change to ksh shell

Hi everyone: Mi default shell is sh, i need to set the TMOUT variable so i need to change the shell to ksh, I change the /etc/profile file as follows, but when i do an echo $0 stll sh been the shell: # more /etc/profile # # (c) Copyright 1990, OPEN SOFTWARE FOUNDATION, INC. # ALL RIGHTS... (2 Replies)
Discussion started by: irasela
2 Replies

4. UNIX for Dummies Questions & Answers

How can I change the behavior of the mouse in Terminal?

Hi, I hope I'm posting in the correct forum, so here goes. I would like for the mouse right/left click to work in Terminal (OSX) as it does in Putty. For instance, when I double click 'log' in file.log.gz, only the log part is highlighted (in Terminal), while in Putty the entire file name is... (0 Replies)
Discussion started by: TheChemist
0 Replies

5. UNIX for Advanced & Expert Users

How to change the permissions of ksh?

Suppose, I want to execute unix commands. For that I have to go to ksh, but if I don't have execute permission to ksh itself then is there any way to change the permission of ksh? chmod command does not work for this because, I don't have permission to ksh itself... :) Let me know, if you have... (3 Replies)
Discussion started by: ponnuvel
3 Replies

6. Shell Programming and Scripting

ksh script to change passwd

Hello All, I am trying to change a user passwd (one time password): cat /tmp/passwd mnop1234 mnop1234 #passwd abcd < /tmp/passwd (for some reason, it is not able to input the password from /tmp/passwd and comes back with "New Password: ") Is there a work around except using "expect". ... (1 Reply)
Discussion started by: solaix14
1 Replies

7. Shell Programming and Scripting

change output format using ksh

I have a script that reaches out to several systems and pulls back infomation in serveral files. I would like to take the infomation returned and reformat it so I can export it to excel. Below is current output: File1:item1:abc=1 File1:item2:efg File2:item1:ab=1 File2:item2:efg... (3 Replies)
Discussion started by: oldman2
3 Replies

8. Shell Programming and Scripting

ksh behavior in scripts spawned w/nohup

I have a need to run any number of identical scripts simultaneously, so I've created a driver script which reads a template script, edits these appropriately and then submits them via nohup. The spawned scripts all check to see at some point how many of their number are running and once the count... (7 Replies)
Discussion started by: safedba
7 Replies
All times are GMT -4. The time now is 04:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy