4 Replies Latest reply: Dec 13, 2012 6:58 AM by 856777 RSS

    How to create shell script on solaris "TOP" command

    856777
      Hi All,

      i need to write a shell script on unix top command.

      Requirement:
      In top command grep the more than 25% CPU utilization f60webmx process and that f60webmx process time stamp is more than 3HR's and also needs to grep the load average information in top command.

      Please help me some one.
        • 1. Re: How to create shell script on solaris "TOP" command
          i need to write a shell script on unix top command.
          You have our permission to begin to do that.

          These forums are NOT for doing your work for you. They are here to provide assistance for YOUR work.

          I suggest you go get paper and pencil and write down all the steps you think you need to take to accomplish that. Write it down as if you were going to do that manually at the command prompt. Then put it all into a text file and save it with a file name of your script.

          When you have that "script", you can run it and examine whether it succeeds or whether it has errors. Work at it for a while and fix whatever errors might happen.

          When you are really, really stuck at it, you can paste your script into a reply of this thread and maybe someone will respond with suggestions for improvement.
          • 2. Re: How to create shell script on solaris "TOP" command
            Bulls123
            Yes, please proceed step by step.

            Firstly try to find how you can fetch infromation from top.

            Here few sample for CPU and Memory.

            CPU=`sar -u 2 | tail -1 | awk '{sub=100 - $5} {print sub "%"}'`
            mem=`echo $TOTAL_MEM $FREE_MEM | awk '{sub=$1 - $2} {print "Memory Utilization, " (sub/$1)* 100"%"}' `
            • 3. Re: How to create shell script on solaris "TOP" command
              Nik
              Hi.

              For find high load process:
              ps -e -o pid,pcpu,args | egrep "f60webmx|f60webmx" | awk ' { if ($2 + 0 >= 25 ) print $0 } '
              • 4. Re: How to create shell script on solaris "TOP" command
                856777
                my self prepared below script on top command

                expected_cpuusage=25
                max_hour=72
                top -b | grep f60webmx | awk -F " " '{print $9,$10}' > 'top_list'
                exec 6< 'top_list'
                # read until end of file
                while read -u 6 data
                do
                echo "hiii $data";
                let "hour = `echo $data | awk -F ":" '{print $1}'`";
                echo $hour;
                if [ $hour -gt $max_hour ]
                then
                echo "Hours Exceeded";
                fi
                let "cpu = `echo $data | awk -F " " '{print $2}' | awk -F "." '{print $1}'`";
                echo $cpu;
                if [ $cpu -gt $expected_cpuusage ]
                then
                echo "CPU Exceeded";
                fi
                done;
                exec 6<&-
                rm top_list

                but not getting proper results