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:
* * * * * /app2/stage/aim/aim_ap_etl/test.ksh > /app2/stage/aim/aim_ap_etl/test.out 2>&1
Script:
#!/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
> 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:
> ./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:
> ./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:
> 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
> 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:
> ./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:
> ./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:
> 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!
