Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with ps -ef | grep defunct in KSH script

Status
Not open for further replies.

hg4372

Technical User
Feb 9, 2009
43
0
0
US
Here is my script. However it doesn't seem to capture any data. I tried the same script without the grep and it still doesn't seem to capture anything. I assume it doesn't like the - and the |. Please help.

#!/usr/bin/ksh
# echo "Enter switch: \c"
# read switch
# echo "Enter username: \c"
# read username
# echo "Enter password: \c"
# read password
switch=$1
dt=$(date +%m%d%y_%H%M)
username=user
password=password

for x in 1
do
{
echo $username
sleep 5
echo $password
sleep 10
echo 'ps -ef | grep defunct'
sleep 10
echo "exit;"

}|telnet $switch>/export/defunct/$switch.txt
 
Actually it does work. I use the same format for many other scripts, and it works fine.
 
hg4372,

I don't have any telnet-enabled boxes to test on, but what about this change:

#!/bin/ksh
# echo "Enter switch: \c"
# read switch
# echo "Enter username: \c"
# read username
# echo "Enter password: \c"
# read password
switch=$1
dt=$(date +%m%d%y_%H%M)
username=user
password=password

for x in 1
do
{
echo $username
sleep 5
echo $password
sleep 10
echo "ps -ef | grep defunct"
sleep 10
echo "exit;"

}|telnet $switch>/tmp/$switch.txt
done

Changing

echo 'ps -ef | grep defunct'

to

echo "ps -ef | grep defunct"

and adding "done" to the bottom.

Hope that helpds.

John
 
Actually it works, however I noticed that there is garbage on the first line of the output. It doesn't show up when I cat the file, but when I link to the file from a webpage it shows up as garbage. Any suggestions as to why ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top