How to pass the argument while we schedule the script in the cronjob

iamsaicharanburle

New Member
Credits
58
Hi,

I have a shell script to capture the thread dump and the CPU utilization. While executing the script it will prompt PID as an argument and is fine during manual execution. I wanted to schedule it in the cronjob and need to pass the PID as an argument. I've tried using the below way but it is not working. Can you please help me how to achieve this and also is there a way to pass the PID runtime as the PID changes whenever the server restarts.

Below is the script:
--------------------

high_cpu_linux_jstack.sh

#!/bin/sh
#
# Takes the JBoss PID as an argument.
#
# Captures cpu by light weight thread and thread dumps a specified number of
# times and INTERVAL. Thread dumps are retrieved using jstack and are placed in
# high-cpu-tdump.out
#
# Usage: sh ./high_cpu_linux_jstack.sh <JBOSS_PID>
#
# Change Log:
# * 2011-05-02 19:00 <loleary>
# - Added date output to high-cpu.out for log correlation
# - Added -p argument to top to limit high-cpu.out to <JBOSS_PID>
#
#

# Number of times to collect data.
LOOP=6
# Interval in seconds between data points.
INTERVAL=20
NOW=$(date +"%m-%d-%Y")

for ((i=1; i <= $LOOP; i++))
do
_now=$(date)
echo "${_now}" >>high-cpu.out.$NOW
top -b -n 1 -H -p $1 >>high-cpu.out.$NOW
echo "${_now}" >>high-cpu-tdump.out.$NOW
jstack -l $1 >>high-cpu-tdump.out.$NOW
echo "thread dump #" $i
if [ $i -lt $LOOP ]; then
echo "Sleeping..."
sleep $INTERVAL
fi
done


Below is the cron entry which I tried and not working.

35 11 * * * /path/to/script/high_cpu_linux_jstack.sh 19565 >> /path-to-store/
 


wizardfromoz

Super Moderator
Staff member
Gold Supporter
Credits
7,537
G'day and welcome.

Moving this to Command Line, where scripting issues are also addressed.

Chris Turner
wizardfromoz
 


Members online

No members online now.

Latest posts

Top