LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Crontab O/P (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-o-p-926904/)

abhinav4 02-01-2012 06:19 AM

Crontab O/P
 
Running the below command in command line gives fine O/P but using it in crontab give wrong O/P

lsof -p 22669 |wc -l

crontab entry

* * * * * lsof -p 22669 |wc -l >/dev/pts/1

acid_kewpie 02-01-2012 06:47 AM

what does "O/P" mean?

abhinav4 02-01-2012 07:39 AM

Quote:

Originally Posted by acid_kewpie (Post 4590389)
what does "O/P" mean?

O/P = output

acid_kewpie 02-01-2012 08:01 AM

I'd suggest writing "output" in future...

so what IS the wrong output? what is the correct output? You should always use full paths to binaries, e.g. /usr/sbin/lsof and /bin/wc

a PID seems like a real odd thing to put in a cronjob to me though.

Every single minute? maybe you would be better off with a watch statement instead of a cron?

abhinav4 02-01-2012 09:04 AM

Quote:

Originally Posted by acid_kewpie (Post 4590455)
I'd suggest writing "output" in future...

so what IS the wrong output? what is the correct output? You should always use full paths to binaries, e.g. /usr/sbin/lsof and /bin/wc

a PID seems like a real odd thing to put in a cronjob to me though.

Every single minute? maybe you would be better off with a watch statement instead of a cron?

ok here is what exactly in crintab but it gives output 0 everytime which is not true

* * * * * /usr/local/bin/lsof -p `/usr/bin/ps -aef |/usr/local/bin/grep java |/usr/local/bin/awk '{print $2}'` |/usr/local/bin/wc -l > /dev/pts/3

abhinav4 02-01-2012 09:05 AM

Quote:

Originally Posted by acid_kewpie (Post 4590455)
I'd suggest writing "output" in future...

so what IS the wrong output? what is the correct output? You should always use full paths to binaries, e.g. /usr/sbin/lsof and /bin/wc

a PID seems like a real odd thing to put in a cronjob to me though.

Every single minute? maybe you would be better off with a watch statement instead of a cron?

ok here is what exactly in crontab but it gives output as 0 (which is not true) and even do not run for second round

I want this output for every 15 minutes, but in crontab I have not mentioned 15 minutes just to verify if it runs

* * * * * /usr/local/bin/lsof -p `/usr/bin/ps -aef |/usr/local/bin/grep java |/usr/local/bin/awk '{print $2}'` |/usr/local/bin/wc -l > /dev/pts/3

acid_kewpie 02-01-2012 09:13 AM

Ouch, that's painful... just run "/usr/bin/pgrep java -n" to get the newest java pid. but then if you want all files opened by the java process, "/usr/local/bin/lsof -c java | wc -l" would give you that I reckon.

what cron are you running this in? If it's on /etc/crontab then you need to add the username to execute it as before the command.

abhinav4 02-01-2012 09:37 AM

Chris thank you for providing the short form of the command
I am running the cron locally under my home directory and it works now.
Thanks, but any idea what was wrong in my command


All times are GMT -5. The time now is 02:59 PM.