Hello I wonder if someone could help me with a korn script.
I am new to Unix Shell scripting and have only been doing it for about a week.
I want to tidy up a menu script and looking at functions.
Could anyone give me any pointers.
regards
Ian.
#!/bin/ksh
# Set system variables
AgentsData=/tmp/agentsData.$$
AgentsRead=/tmp/agentsRead.$$
DiffFile=/tmp/difffile.$$
AllAgents=/export/home/nz9jyp/test/allagents
clear
echo ""
echo "\\t \\t *******************************************"
echo "\\t \\t * Please select an option *"
echo "\\t \\t *******************************************"
echo
echo "\\t \\t a - Show Running Pega Agents"
echo "\\t \\t b - Show None Running Agents"
echo "\\t \\t c - Count Number Of Running Pega Agents"
echo "\\t \\t d - Count Number Of None Running Pega Agents"
echo "\\t \\t e - Start a Pega Agent"
echo "\\t \\t q - Quit"
echo ""
echo "\\t \\t Select an option \\c"
read ans
case $ans in
a) clear
echo "\\t RUNNING A SEARCH ON ALL RUNNING PEGA AGENTS PLEASE WAIT......"
sleep 1
echo ""
ps -ef | grep zasmain |egrep -v grep |grep -v edsuat > $AgentsData
# Now for the results screen
cat $AgentsData | awk '{print $11,$2,$3,$5}' | tr -s ' ' ' ' > $AgentsRead
echo "\\t All PEGA AGENTS" > $AgentsRead
echo "" >> $AgentsRead
echo "AGENT PID PPID TIME STATUS" >>$AgentsRead
echo "____ ___ ____ ____ ______" >>$AgentsRead
cat $AgentsData | awk '{print $11,$2,$3,$5}' | tr -s ' ' ' ' |sort |sed 's/$/ Status Running/' >> $AgentsRead
more $AgentsRead
rm $AgentsData $AgentsRead
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
b) clear
echo "\\t RUNNING A SEARCH ON ALL PEGA AGENTS PLEASE WAIT......"
sleep 1
echo ""
ps -ef | grep zasmain |egrep -v grep |grep -v edsuat > $AgentsData
# Now for the results screen
cat $AgentsData | awk '{print $11}' |sort > $DiffFile
echo "\\t All NONE RUNNING PEGA AGENTS"
echo ""
diff $DiffFile $AllAgents |grep ">" |cut -d " " -f2 |sed 's/$/ Not Running/' >> $AgentsRead
AgentsRead=$(more $AgentsRead)
echo "\\t" $AgentsRead
rm $DiffFile $AgentsData $AgentsRead
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
c) clear
echo "\\t RUNNING A SEARCH ON ALL RUNNING PEGA AGENTS PLEASE WAIT......"
sleep 1
echo ""
ps -ef | grep zasmain |egrep -v grep |grep -v edsuat > $AgentsData
# Now for the results screen
AgentsCount=$(more $AgentsData |wc -l)
echo "\\t There are" $AgentsCount "Pega Agents Running Out Of An Expected 39 Agents"
rm $AgentsData
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
d) clear
echo "\\t RUNNING A SEARCH ON ALL PEGA AGENTS PLEASE WAIT......"
sleep 1
echo ""
ps -ef | grep zasmain |egrep -v grep |grep -v edsuat > $AgentsData
# Now for the results screen
cat $AgentsData | awk '{print $11}' |sort > $DiffFile
diff $DiffFile $AllAgents |grep ">" |cut -d " " -f2 |sed 's/$/ Not Running/' >> $AgentsRead
AgentsRead=$(more $AgentsRead |wc -l)
echo "\\t There is" $AgentsRead "Pega Agent(s) not running out of the expected 39 Agents"
rm $DiffFile $AgentsData $AgentsRead
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
e) clear
echo "\\t \\t *******************************************"
echo "\\t \\t * *"
echo "\\t \\t * Pega Support (Start A Pega Agent) *"
echo "\\t \\t * *"
echo "\\t \\t *******************************************"
echo ""
echo "\\t \\t Enter the Pega Agent Name You Wish To Start \\c"
read imput
echo "Starting The Pega Agent ...."
echo ""
/app/pegatst/zbin/zpddrvr ^yas2^ $imput
sleep 5
ps -ef |grep $imput
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
q) echo ""; echo "\\t \\t Quitting the Pega Agents menu program ...." ; sleep 1; echo "" ; exit;;
*) echo \\t \\t \\t \\t ^ is not a valid option; sleep 1; $0;;
esac
I am new to Unix Shell scripting and have only been doing it for about a week.
I want to tidy up a menu script and looking at functions.
Could anyone give me any pointers.
regards
Ian.
#!/bin/ksh
# Set system variables
AgentsData=/tmp/agentsData.$$
AgentsRead=/tmp/agentsRead.$$
DiffFile=/tmp/difffile.$$
AllAgents=/export/home/nz9jyp/test/allagents
clear
echo ""
echo "\\t \\t *******************************************"
echo "\\t \\t * Please select an option *"
echo "\\t \\t *******************************************"
echo
echo "\\t \\t a - Show Running Pega Agents"
echo "\\t \\t b - Show None Running Agents"
echo "\\t \\t c - Count Number Of Running Pega Agents"
echo "\\t \\t d - Count Number Of None Running Pega Agents"
echo "\\t \\t e - Start a Pega Agent"
echo "\\t \\t q - Quit"
echo ""
echo "\\t \\t Select an option \\c"
read ans
case $ans in
a) clear
echo "\\t RUNNING A SEARCH ON ALL RUNNING PEGA AGENTS PLEASE WAIT......"
sleep 1
echo ""
ps -ef | grep zasmain |egrep -v grep |grep -v edsuat > $AgentsData
# Now for the results screen
cat $AgentsData | awk '{print $11,$2,$3,$5}' | tr -s ' ' ' ' > $AgentsRead
echo "\\t All PEGA AGENTS" > $AgentsRead
echo "" >> $AgentsRead
echo "AGENT PID PPID TIME STATUS" >>$AgentsRead
echo "____ ___ ____ ____ ______" >>$AgentsRead
cat $AgentsData | awk '{print $11,$2,$3,$5}' | tr -s ' ' ' ' |sort |sed 's/$/ Status Running/' >> $AgentsRead
more $AgentsRead
rm $AgentsData $AgentsRead
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
b) clear
echo "\\t RUNNING A SEARCH ON ALL PEGA AGENTS PLEASE WAIT......"
sleep 1
echo ""
ps -ef | grep zasmain |egrep -v grep |grep -v edsuat > $AgentsData
# Now for the results screen
cat $AgentsData | awk '{print $11}' |sort > $DiffFile
echo "\\t All NONE RUNNING PEGA AGENTS"
echo ""
diff $DiffFile $AllAgents |grep ">" |cut -d " " -f2 |sed 's/$/ Not Running/' >> $AgentsRead
AgentsRead=$(more $AgentsRead)
echo "\\t" $AgentsRead
rm $DiffFile $AgentsData $AgentsRead
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
c) clear
echo "\\t RUNNING A SEARCH ON ALL RUNNING PEGA AGENTS PLEASE WAIT......"
sleep 1
echo ""
ps -ef | grep zasmain |egrep -v grep |grep -v edsuat > $AgentsData
# Now for the results screen
AgentsCount=$(more $AgentsData |wc -l)
echo "\\t There are" $AgentsCount "Pega Agents Running Out Of An Expected 39 Agents"
rm $AgentsData
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
d) clear
echo "\\t RUNNING A SEARCH ON ALL PEGA AGENTS PLEASE WAIT......"
sleep 1
echo ""
ps -ef | grep zasmain |egrep -v grep |grep -v edsuat > $AgentsData
# Now for the results screen
cat $AgentsData | awk '{print $11}' |sort > $DiffFile
diff $DiffFile $AllAgents |grep ">" |cut -d " " -f2 |sed 's/$/ Not Running/' >> $AgentsRead
AgentsRead=$(more $AgentsRead |wc -l)
echo "\\t There is" $AgentsRead "Pega Agent(s) not running out of the expected 39 Agents"
rm $DiffFile $AgentsData $AgentsRead
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
e) clear
echo "\\t \\t *******************************************"
echo "\\t \\t * *"
echo "\\t \\t * Pega Support (Start A Pega Agent) *"
echo "\\t \\t * *"
echo "\\t \\t *******************************************"
echo ""
echo "\\t \\t Enter the Pega Agent Name You Wish To Start \\c"
read imput
echo "Starting The Pega Agent ...."
echo ""
/app/pegatst/zbin/zpddrvr ^yas2^ $imput
sleep 5
ps -ef |grep $imput
echo ""
echo "\\t Hit Return to go back to the main menu"
read
$0;;
q) echo ""; echo "\\t \\t Quitting the Pega Agents menu program ...." ; sleep 1; echo "" ; exit;;
*) echo \\t \\t \\t \\t ^ is not a valid option; sleep 1; $0;;
esac